Merge branch 'packer'

This commit is contained in:
zimbatm 2013-11-27 21:43:16 +00:00
commit f481d5cd52
14 changed files with 407 additions and 22 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@
/Gemfile.lock
/iso
/vendor
/packer_cache

17
Gemfile
View file

@ -1,17 +0,0 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
source :rubygems
gem 'rake', '~> 10.0.2'
group :chef do
gem 'chef', '~> 10.16.2'
gem 'foodcritic', '~> 1.6.1'
gem 'test-kitchen', '~> 0.6.0'
end
group :vagrant do
gem 'vagrant', '~> 1.0.5'
gem 'veewee', '~> 0.3.1'
end

17
Makefile Normal file
View file

@ -0,0 +1,17 @@
ISO_URL_32=http://nixos.org/releases/nixos/13.10/nixos-13.10.35455.45219b9/nixos-minimal-13.10.35455.45219b9-i686-linux.iso
ISO_MD5_32=c10f01734cb187e13068252e2cde565d
GUEST_OS_32=Linux
ISO_URL_64=http://nixos.org/releases/nixos/13.10/nixos-13.10.35455.45219b9/nixos-minimal-13.10.35455.45219b9-x86_64-linux.iso
ISO_MD5_64=fbac8c11661028e6f9c4ec293e1329e1
GUEST_OS_64=Linux_64
all: nixbox32-template.json nixbox64-template.json
nixbox32-template.json: nixbox-template.json.orig
cat $< | sed -e 's|ISO_URL|$(ISO_URL_32)|g' -e 's|ISO_MD5|$(ISO_MD5_32)|g' -e 's|GUEST_OS|$(GUEST_OS_32)|g' -e 's|NIXBOX|nixbox32|g' > $@
nixbox64-template.json: nixbox-template.json.orig
cat $< | sed -e 's|ISO_URL|$(ISO_URL_64)|g' -e 's|ISO_MD5|$(ISO_MD5_64)|g' -e 's|GUEST_OS|$(GUEST_OS_64)|g' -e 's|NIXBOX|nixbox64|g' > $@

34
README.md Normal file
View file

@ -0,0 +1,34 @@
NixOS boxes for Vagrant
=======================
[NixOS](http://nixos.org) is a linux distribution based on a purely functional
package manager. This project builds .box images that can be used by
[vagrant](http://vagrantup.com), the VM manager.
Status
------
stable
Building the images
-------------------
First install [packer](http://packer.io) and
[virtualbox](https://www.virtualbox.org/)
Then:
```
packer build nixbox32-template.json
# or
packer build nixbox64-template.json
```
The .box image is now ready to go and you can use it in vagrant:
```
vagrant box add nixbox32 nixbox32-virtualbox.box
# or
vagrant box add nixbox64-nixbox64-virtualbox.box
```

3
Vagrantfile vendored
View file

@ -1,6 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
Vagrant.configure("2") do |config|
config.vm.box = 'nixos32'
config.vm.box_url = 'http://zimbatm.s3.amazonaws.com/nixbox/nixos32.box'
end

View file

@ -1,6 +1,6 @@
iso = {
:file => 'nixos-minimal-0.2pre4454_979117b-789154b-i686-linux.iso',
:md5 => '0f3a1a5a531b01819ec17a0feeea11e6',
:url => 'http://nixos.org/releases/nixos/nixos-0.2pre4476_a5e4432-b076ab9/nixos-minimal-0.2pre4476_a5e4432-b076ab9-i686-linux.iso',
:md5 => 'f035bb375f0fbcbbc4e33a12131e91d4',
}
session = {
@ -27,9 +27,9 @@ session = {
:disk_size => '20400',
:hostiocache => 'off',
:iso_download_timeout => '1000',
:iso_file => iso[:file],
:iso_file => File.basename(iso[:url]),
:iso_md5 => iso[:md5],
:iso_src => "http://nixos.org/releases/nixos/#{iso[:file].gsub(/-[^-]+-linux.iso$/,'')}/#{iso[:file]}",
:iso_src => iso[:url],
:kickstart_file => 'configuration.nix',
:kickstart_port => '7122',
:kickstart_timeout => '10000',

View file

@ -0,0 +1,39 @@
{ config, pkgs, ... }:
{
require = [ ./hardware-configuration.nix ];
boot = {
loader.grub.device = "/dev/sda";
};
environment.systemPackages = with pkgs; [ git ruby rubygems gnumake gcc ];
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"
];
} ];
};
}

View file

@ -0,0 +1,50 @@
iso = {
:url => 'http://nixos.org/releases/nixos/nixos-0.2pre4476_a5e4432-b076ab9/nixos-minimal-0.2pre4476_a5e4432-b076ab9-x86_64-linux.iso',
:md5 => '3e0a95f0b7634022e1b0d88c6fc5ab17',
}
session = {
:boot_cmd_sequence =>
[
'<Enter>', '<Wait>'*15,
'root', '<Enter>',
'stop sshd', '<Enter>', # Make sure we don't accept connections until reboot
'fdisk /dev/sda', '<Enter>',
'n', '<Enter>'*5,
'a', '<Enter>',
'1', '<Enter>',
'w', '<Enter>',
'mkfs.ext4 -j -L nixos /dev/sda1', '<Enter>',
'mount LABEL=nixos /mnt', '<Enter>',
'nixos-option --install', '<Enter>',
'curl http://%IP%:%PORT%/configuration.nix > /mnt/etc/nixos/configuration.nix &&', '<Enter>',
'nixos-install &&', '<Enter>',
'reboot', '<Enter>',
],
:boot_wait => '5',
:cpu_count => '1',
:disk_format => 'VDI',
:disk_size => '20400',
:hostiocache => 'off',
:iso_download_timeout => '1000',
:iso_file => File.basename(iso[:url]),
:iso_md5 => iso[:md5],
:iso_src => iso[:url],
:kickstart_file => 'configuration.nix',
:kickstart_port => '7122',
:kickstart_timeout => '10000',
:memory_size => '256',
:os_type_id => 'Linux26_64',
:postinstall_files => [ 'postinstall.sh' ],
:postinstall_timeout => '10000',
:shutdown_cmd => 'shutdown -h now',
:ssh_guest_port => '22',
:ssh_host_port => '7222',
:ssh_key => '',
:ssh_login_timeout => '10000',
:ssh_password => 'vagrant',
:ssh_user => 'vagrant',
:sudo_cmd => "sudo '%f'"
}
Veewee::Definition.declare session

View file

@ -0,0 +1,28 @@
#!/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

63
http/configuration.nix Normal file
View file

@ -0,0 +1,63 @@
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
# Use the GRUB 2 boot loader.
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
boot.loader.grub.device = "/dev/sda";
networking.hostName = "nixbox";
# Services to enable:
# Enable the OpenSSH daemon.
services.openssh.enable = true;
# Enable DBus
services.dbus.enable = true;
# Default packages
environment.systemPackages = with pkgs; [
gcc
git
gnumake
python
ruby
rubygems
];
# 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.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
'';
}

50
nixbox-template.json.orig Normal file
View file

@ -0,0 +1,50 @@
{
"builders": [
{
"type": "virtualbox",
"boot_wait": "1m",
"boot_command": [
"root<enter>",
"stop sshd<enter>",
"fdisk /dev/sda<enter>",
"n",
"<enter><enter><enter><enter><enter>",
"a<enter>",
"1<enter>",
"w<enter>",
"<wait>",
"mkfs.ext4 -j -L nixos /dev/sda1<enter><wait5>",
"mount LABEL=nixos /mnt<enter><wait>",
"nixos-generate-config --root /mnt<enter><wait>",
"curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/configuration.nix | sed -e 's|nixbox|NIXBOX|g' > /mnt/etc/nixos/configuration.nix<enter><wait>",
"nixos-install && reboot<enter>"
],
"guest_additions_mode": "disable",
"guest_os_type": "GUEST_OS",
"http_directory": "http",
"iso_checksum": "ISO_MD5",
"iso_checksum_type": "md5",
"iso_url": "ISO_URL",
"shutdown_command": "sudo shutdown -h now",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
"ssh_wait_timeout": "5m",
"virtualbox_version_file": ".vbox_version"
}
],
"provisioners": [
{
"type": "shell",
"execute_command": "sudo sh '{{.Path}}'",
"script": "scripts/postinstall.sh"
}
],
"post-processors": [
{
"type": "vagrant",
"output": "NIXBOX-{{.Provider}}.box"
}
]
}

50
nixbox32-template.json Normal file
View file

@ -0,0 +1,50 @@
{
"builders": [
{
"type": "virtualbox",
"boot_wait": "1m",
"boot_command": [
"root<enter>",
"stop sshd<enter>",
"fdisk /dev/sda<enter>",
"n",
"<enter><enter><enter><enter><enter>",
"a<enter>",
"1<enter>",
"w<enter>",
"<wait>",
"mkfs.ext4 -j -L nixos /dev/sda1<enter><wait5>",
"mount LABEL=nixos /mnt<enter><wait>",
"nixos-generate-config --root /mnt<enter><wait>",
"curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/configuration.nix | sed -e 's|nixbox|nixbox32|g' > /mnt/etc/nixos/configuration.nix<enter><wait>",
"nixos-install && reboot<enter>"
],
"guest_additions_mode": "disable",
"guest_os_type": "Linux",
"http_directory": "http",
"iso_checksum": "c10f01734cb187e13068252e2cde565d",
"iso_checksum_type": "md5",
"iso_url": "http://nixos.org/releases/nixos/13.10/nixos-13.10.35455.45219b9/nixos-minimal-13.10.35455.45219b9-i686-linux.iso",
"shutdown_command": "sudo shutdown -h now",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
"ssh_wait_timeout": "5m",
"virtualbox_version_file": ".vbox_version"
}
],
"provisioners": [
{
"type": "shell",
"execute_command": "sudo sh '{{.Path}}'",
"script": "scripts/postinstall.sh"
}
],
"post-processors": [
{
"type": "vagrant",
"output": "nixbox32-{{.Provider}}.box"
}
]
}

50
nixbox64-template.json Normal file
View file

@ -0,0 +1,50 @@
{
"builders": [
{
"type": "virtualbox",
"boot_wait": "1m",
"boot_command": [
"root<enter>",
"stop sshd<enter>",
"fdisk /dev/sda<enter>",
"n",
"<enter><enter><enter><enter><enter>",
"a<enter>",
"1<enter>",
"w<enter>",
"<wait>",
"mkfs.ext4 -j -L nixos /dev/sda1<enter><wait5>",
"mount LABEL=nixos /mnt<enter><wait>",
"nixos-generate-config --root /mnt<enter><wait>",
"curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/configuration.nix | sed -e 's|nixbox|nixbox64|g' > /mnt/etc/nixos/configuration.nix<enter><wait>",
"nixos-install && reboot<enter>"
],
"guest_additions_mode": "disable",
"guest_os_type": "Linux_64",
"http_directory": "http",
"iso_checksum": "fbac8c11661028e6f9c4ec293e1329e1",
"iso_checksum_type": "md5",
"iso_url": "http://nixos.org/releases/nixos/13.10/nixos-13.10.35455.45219b9/nixos-minimal-13.10.35455.45219b9-x86_64-linux.iso",
"shutdown_command": "sudo shutdown -h now",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_username": "vagrant",
"ssh_wait_timeout": "5m",
"virtualbox_version_file": ".vbox_version"
}
],
"provisioners": [
{
"type": "shell",
"execute_command": "sudo sh '{{.Path}}'",
"script": "scripts/postinstall.sh"
}
],
"post-processors": [
{
"type": "vagrant",
"output": "nixbox64-{{.Provider}}.box"
}
]
}

19
scripts/postinstall.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/sh
# Make sure we are totally up to date
nix-channel --add http://nixos.org/channels/nixos-13.10 nixos
nixos-rebuild switch --upgrade
# 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