Skip to content

Instantly share code, notes, and snippets.

@andir
Created September 12, 2018 11:41
Show Gist options
  • Save andir/d208f54de7562ab8ceaacdd3a28363d4 to your computer and use it in GitHub Desktop.
Save andir/d208f54de7562ab8ceaacdd3a28363d4 to your computer and use it in GitHub Desktop.
nixos build virtualbox image for dummies
# This file describes how to build custom virtualbox instances. This examples ignores things like cross compiling etc..
# this defines the function signature of our expression, pkgs is defaulted to the systems packages,
# you could also overrides that if you need a specific release / channel.
{ pkgs ? import <nixpkgs> {}}:
# "let" expressions are just there to introduce scoped variables and functions,
# in this case it is declaring just a helper function
let
# this creates a helper function that abstracts a bit of the boilerplate away
# `mkVM` takes one argument, a list of `modules` to include in the image.
mkVM = mods: (import <nixpkgs/nixos/lib/eval-config.nix> {
modules = [
# include the standard virtualbox demo install that probably includes things like KDE or whatever
<nixpkgs/nixos/modules/installer/virtualbox-demo.nix>
] ++ mods;
}).config.system.build.virtualBoxOVA;
in
# here starts the actual declaration of "target" included in this file.
{
# delcares the target of an example image with vim and tmux
# build with: nix-build . -A withTmuxAndVIM
withTmuxAndVIM = mkVM [
# add some custom pkgs like vim and tmux, could be our internal packages
({pkgs, ...}: {
environment.systemPackages = with pkgs; [ vim tmux ];
})
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment