From 2339979240aa47cbf646b9794e5c2613a253b109 Mon Sep 17 00:00:00 2001 From: Chris Farmiloe Date: Mon, 3 Feb 2014 02:32:28 +0000 Subject: [PATCH] setup for use with vagrant-nixos --- README.md | 30 ++++++++++++------------------ nixos/configuration.nix | 16 ++++------------ nixos/guest-virtualbox.nix | 8 ++++++++ nixos/users-vagrant.nix | 37 +++++++++++++++++++++++++++++++++++++ nixos/vagrant.nix | 36 ++---------------------------------- scripts/postinstall.sh | 3 ++- template.json | 7 ++++--- 7 files changed, 69 insertions(+), 68 deletions(-) create mode 100644 nixos/users-vagrant.nix diff --git a/README.md b/README.md index 6d4d0eb..dd44f76 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,10 @@ -OS Image build scripts -====================== +NixOS Image build scripts +========================= -Cycle's OS is based on [NixOS](http://nixos.org), a linux distribution with a purely functional +[NixOS](http://nixos.org) is a linux distribution with a purely functional package manager. -These scripts build .box images that can be used by [vagrant](http://vagrantup.com) for development, and other images suitable for production. - -See [CycleSDK](https://bitbucket.org/oxdi/cycle-sdk) for the complete development environment (which makes use of the images generated here). +These scripts build .box images that can be used by [vagrant](http://vagrantup.com) with the [vagrant-nixos](http://github.com/oxdi/vagrant-nixos) plugin for development, and other images suitable for production. Building the images @@ -22,21 +20,17 @@ packer build template.json The .box image is now ready to go. Install it into Vagrant via: -Updating the public box image ------------------------------ - -`s3put` is handy tool for copying files to Amazon S3, it's part of the [boto](https://github.com/boto/boto) library. - -Install boto: - ```bash -pip install boto +vagrant box add nixos-14.02-x86_64 nixos-14.02-x86_64-virtualbox.box ``` -Push the .box image to S3 via s3put +Using the images +---------------- + +Vagrant does not have a nixos guest plugin by default, so you'll need to install [vagrant-nixos](http://github.com/oxdi/vagrant-nixos). ```bash -s3put -a $AWS_ID -s $AWS_KEY -b oxdi -g public-read --prefix `pwd` cycle-xx.xx-x86_64-virtualbox.box +vagrant plugin install vagrant-nixos +vagrant init nixos-14.02-x86_64 +vagrant up ``` - -The box will then be available at http://amazonaws.com/oxdi/cycle64-virtualbox.box diff --git a/nixos/configuration.nix b/nixos/configuration.nix index a0e893f..9ef691e 100644 --- a/nixos/configuration.nix +++ b/nixos/configuration.nix @@ -1,26 +1,18 @@ { config, pkgs, ... }: -# -# This file should only be a list of imports managed by whichever provisioner -# is building the environment. -# -# You should not be editing this by hand. -# - { imports = [ ./hardware-configuration.nix ./guest.nix + ./users.nix ./vagrant.nix ]; - # we want our nixpkgs repo to take priority - environment.shellInit = '' - export NIX_PATH='nixpkgs=/etc/nixos/nixpkgs:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels/nixos' - ''; - + # we always want git and vim environment.systemPackages = with pkgs; [ git + vim ]; + } diff --git a/nixos/guest-virtualbox.nix b/nixos/guest-virtualbox.nix index c08c1cd..65dba00 100644 --- a/nixos/guest-virtualbox.nix +++ b/nixos/guest-virtualbox.nix @@ -11,9 +11,17 @@ boot.loader.grub.version = 2; boot.loader.grub.device = "/dev/sda"; + # load missing module (should be fixed by 14.02 propper) + boot.kernelModules = [ "vboxsf" ]; + # Enable the OpenSSH daemon. services.openssh.enable = true; services.openssh.permitRootLogin = "yes"; users.extraUsers.root.openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" ]; + # Vagrant cannot yet handle udev's new predictable interface names. + # Use the old ethX naming system for the moment. + # http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/ + networking.usePredictableInterfaceNames = false; + } diff --git a/nixos/users-vagrant.nix b/nixos/users-vagrant.nix new file mode 100644 index 0000000..c6ceaf3 --- /dev/null +++ b/nixos/users-vagrant.nix @@ -0,0 +1,37 @@ +{ config, pkgs, ... }: + +# +# This file is used by the vagrant-nixos plugin +# + +{ + # Creates a "vagrant" users with password-less sudo access + users = { + extraGroups = [ { name = "vagrant"; } { name = "vboxsf"; } ]; + extraUsers = [ { + description = "Vagrant User"; + name = "vagrant"; + group = "vagrant"; + extraGroups = [ "users" "vboxsf" "wheel" ]; + password = "vagrant"; + home = "/home/vagrant"; + createHome = true; + useDefaultShell = true; + openssh.authorizedKeys.keys = [ + "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" + ]; + } ]; + }; + + security.sudo.wheelNeedsPassword = false; + security.sudo.configFile = '' + Defaults:root,%wheel env_keep+=LOCALE_ARCHIVE + Defaults:root,%wheel env_keep+=NIX_PATH + Defaults:root,%wheel env_keep+=TERMINFO_DIRS + Defaults env_keep+=SSH_AUTH_SOCK + Defaults lecture = never + root ALL=(ALL) SETENV: ALL + %wheel ALL=(ALL) NOPASSWD: ALL, SETENV: ALL + ''; + +} diff --git a/nixos/vagrant.nix b/nixos/vagrant.nix index 9911101..c16fd15 100644 --- a/nixos/vagrant.nix +++ b/nixos/vagrant.nix @@ -1,39 +1,7 @@ { config, pkgs, ... }: # -# This file configures the OS for use with vagrant by setting up the -# vagrant user, keys etc. +# This file is used by the vagrant-nixos plugin # -{ - - # Creates a "vagrant" users with password-less sudo access - users = { - extraGroups = [ { name = "vagrant"; } { name = "vboxsf"; } ]; - extraUsers = [ { - description = "Vagrant User"; - name = "vagrant"; - group = "vagrant"; - extraGroups = [ "users" "vboxsf" "wheel" ]; - password = "vagrant"; - home = "/home/vagrant"; - createHome = true; - useDefaultShell = true; - openssh.authorizedKeys.keys = [ - "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" - ]; - } ]; - }; - - security.sudo.wheelNeedsPassword = false; - security.sudo.configFile = '' - Defaults:root,%wheel env_keep+=LOCALE_ARCHIVE - Defaults:root,%wheel env_keep+=NIX_PATH - Defaults:root,%wheel env_keep+=TERMINFO_DIRS - Defaults env_keep+=SSH_AUTH_SOCK - Defaults lecture = never - root ALL=(ALL) SETENV: ALL - %wheel ALL=(ALL) NOPASSWD: ALL, SETENV: ALL - ''; - -} +{} diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh index ddca1c8..7bc4bfa 100755 --- a/scripts/postinstall.sh +++ b/scripts/postinstall.sh @@ -2,7 +2,8 @@ set -e -# rebuild (which should now use our nixpkgs) +# Switch to non ssl channel as there are issues with certs +# TODO: fix this propperly by including the root certs. nix-channel --remove nixos nix-channel --add http://nixos.org/channels/nixos-unstable nixos nixos-rebuild switch --upgrade diff --git a/template.json b/template.json index c5337bb..13eabec 100644 --- a/template.json +++ b/template.json @@ -18,8 +18,9 @@ "nixos-generate-config --root /mnt", "curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/configuration.nix > /mnt/etc/nixos/configuration.nix", "curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/guest-virtualbox.nix > /mnt/etc/nixos/guest.nix", + "curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/users-vagrant.nix > /mnt/etc/nixos/users.nix", "curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/vagrant.nix > /mnt/etc/nixos/vagrant.nix", - "nix-env -i git && (cd /mnt/etc/nixos && git clone git://github.com/oxdi/nixpkgs.git) && nixos-install && reboot" + "nixos-install && reboot" ], "guest_additions_mode": "disable", "guest_os_type": "Linux_64", @@ -33,7 +34,7 @@ "ssh_wait_timeout": "20m", "virtualbox_version_file": ".vbox_version", "vboxmanage": [ - ["modifyvm", "{{.Name}}", "--memory", "2048"], + ["modifyvm", "{{.Name}}", "--memory", "1024"], ["modifyvm", "{{.Name}}", "--cpus", "2"] ] } @@ -48,7 +49,7 @@ "post-processors": [ { "type": "vagrant", - "output": "cycle-14.02-x86_64-{{.Provider}}.box" + "output": "nixos-14.02-x86_64-{{.Provider}}.box" } ] }