From c4017fe605d4e0bcb2d6147d980f4c4914205fae Mon Sep 17 00:00:00 2001 From: Jonas Pfenniger Date: Mon, 22 Jul 2013 12:07:17 +0100 Subject: [PATCH] Porting to packer Still not working yet, it's blocking on the SSHd server after install. --- .gitignore | 1 + README.md | 12 ++-- http/configuration.nix | 39 ++++++++++++ nixos32-template.json | 131 +++++++++++++++++++++++++++++++++++++++++ scripts/postinstall.sh | 27 +++++++++ 5 files changed, 204 insertions(+), 6 deletions(-) create mode 100644 http/configuration.nix create mode 100644 nixos32-template.json create mode 100755 scripts/postinstall.sh diff --git a/.gitignore b/.gitignore index d3930f2..e976b47 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /Gemfile.lock /iso /vendor +/packer_cache diff --git a/README.md b/README.md index 156121b..41ca018 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ NixOS boxes for Vagrant ======================= -``` -bundle -bundle exec veewee vbox build nixos32 -bundle exec veewee vbox export nixos32 -``` +First install packer: http://packer.io (or `brew install packer`) -There's also a nixos64 version but it's still failing to build. +Then: + +``` +packer build --only=virtualbox nixos32-template.json +``` diff --git a/http/configuration.nix b/http/configuration.nix new file mode 100644 index 0000000..99df003 --- /dev/null +++ b/http/configuration.nix @@ -0,0 +1,39 @@ +{ config, pkgs, ... }: +{ + require = [ ./hardware-configuration.nix ]; + boot = { + loader.grub.device = "/dev/sda"; + }; + environment.systemPackages = with pkgs; [ git gnumake gcc ruby rubygems python ]; + fileSystems = [ { mountPoint = "/"; label = "nixos"; } ]; + 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 + ''; + services = { + dbus.enable = true; + openssh.enable = true; + }; + 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" + ]; + } ]; + }; +} diff --git a/nixos32-template.json b/nixos32-template.json new file mode 100644 index 0000000..5aa7c87 --- /dev/null +++ b/nixos32-template.json @@ -0,0 +1,131 @@ +{ + "provisioners": [ + { + "type": "shell", + "scripts": [ + "scripts/postinstall.sh" + ], + "override": { + "virtualbox": { + "execute_command": "sudo '{{.Path}}'" + }, + "vmware": { + "execute_command": "sudo '{{.Path}}'" + } + } + } + ], + "builders": [ + { + "type": "virtualbox", + "boot_command": [ + "", + "", + "root", + "", + "stop sshd", + "", + "fdisk /dev/sda", + "", + "n", + "", + "a", + "", + "1", + "", + "w", + "", + "mkfs.ext4 -j -L nixos /dev/sda1", + "", + "mount LABEL=nixos /mnt", + "", + "nixos-option --install", + "", + "curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/configuration.nix > /mnt/etc/nixos/configuration.nix &&", + "", + "nixos-install &&", + "", + "reboot", + "" + ], + "boot_wait": "5s", + "disk_size": 20400, + "guest_os_type": "Linux26", + "http_directory": "http", + "iso_checksum": "b1a78fc1b72ea1a19957cb1422817ab6", + "iso_checksum_type": "md5", + "iso_url": "http://nixos.org/releases/nixos/nixos-13.07pre4871_18de9f6-3c35dae/nixos-minimal-13.07pre4871_18de9f6-3c35dae-i686-linux.iso", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "sudo shutdown -h now", + "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", + "virtualbox_version_file": ".vbox_version", + "vboxmanage": [ + [ + "modifyvm", + "{{.Name}}", + "--memory", + "256" + ], + [ + "modifyvm", + "{{.Name}}", + "--cpus", + "1" + ] + ] + }, + { + "type": "vmware", + "boot_command": [ + "", + "", + "root", + "", + "stop sshd", + "", + "fdisk /dev/sda", + "", + "n", + "", + "a", + "", + "1", + "", + "w", + "", + "mkfs.ext4 -j -L nixos /dev/sda1", + "", + "mount LABEL=nixos /mnt", + "", + "nixos-option --install", + "", + "curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/configuration.nix > /mnt/etc/nixos/configuration.nix &&", + "", + "nixos-install &&", + "", + "reboot", + "" + ], + "boot_wait": "5s", + "disk_size": 20400, + "guest_os_type": "other26xlinux", + "http_directory": "http", + "iso_checksum": "b1a78fc1b72ea1a19957cb1422817ab6", + "iso_checksum_type": "md5", + "iso_url": "http://nixos.org/releases/nixos/nixos-13.07pre4871_18de9f6-3c35dae/nixos-minimal-13.07pre4871_18de9f6-3c35dae-i686-linux.iso", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "sudo shutdown -h now", + "vmx_data": { + "memsize": "256", + "numvcpus": "1", + "cpuid.coresPerSocket": "1" + } + } + ] +} diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh new file mode 100755 index 0000000..57ad04b --- /dev/null +++ b/scripts/postinstall.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# Remove VirtualBox Guest Additions ISO that the Veewee put in our +# home dir + +rm -f ~/*.iso + +# Install chef & puppet + +#su - vagrant -c 'gem install chef puppet --user-install --bindir=$HOME/bin --no-rdoc --no-ri' + +# Make sure we are totally up to date + +nixos-rebuild --upgrade switch + +# Cleanup any previous generations and delete old packages that can be +# pruned. + +for x in `seq 0 2` ; do + nix-env --delete-generations old + nix-collect-garbage -d +done + +# Zero out the disk (for better compression) + +dd if=/dev/zero of=/EMPTY bs=1M +rm -rf /EMPTY