From d6d8bc7c1cb8da67ddd8eaa6d3e32aa12fd21d18 Mon Sep 17 00:00:00 2001 From: Chris Farmiloe Date: Thu, 30 Jan 2014 22:00:41 +0000 Subject: [PATCH] simplify the os build --- README.md | 19 ++++++++-- definitions/nixos32/configuration.nix | 39 -------------------- definitions/nixos32/definition.rb | 50 -------------------------- definitions/nixos32/postinstall.sh | 28 --------------- definitions/nixos64/configuration.nix | 39 -------------------- definitions/nixos64/definition.rb | 50 -------------------------- definitions/nixos64/postinstall.sh | 28 --------------- nixos/basic.nix | 23 ++++++++++++ {http => nixos}/configuration.nix | 24 ++++++++----- nixos/init.psql | 2 ++ scripts/postinstall.sh | 12 ++++--- cycle64-template.json => template.json | 10 ++++-- 12 files changed, 72 insertions(+), 252 deletions(-) delete mode 100644 definitions/nixos32/configuration.nix delete mode 100644 definitions/nixos32/definition.rb delete mode 100755 definitions/nixos32/postinstall.sh delete mode 100644 definitions/nixos64/configuration.nix delete mode 100644 definitions/nixos64/definition.rb delete mode 100755 definitions/nixos64/postinstall.sh create mode 100644 nixos/basic.nix rename {http => nixos}/configuration.nix (82%) create mode 100644 nixos/init.psql rename cycle64-template.json => template.json (79%) diff --git a/README.md b/README.md index 39ca24b..fc22bc3 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ Cycle OS build scripts Cycle's OS is based on [NixOS](http://nixos.org), a linux distribution with a purely functional package manager. -These scripts build .box images that can be used by [vagrant](http://vagrantup.com), the VM manager, and ISO images that can be installed on bare metal. +These scripts build .box images that can be used by [vagrant](http://vagrantup.com), and ISO images that can be installed on bare metal. -See [cycle-sdk](https://bitbucket.org/oxdi/cycle-sdk) if you want the complete development environment (which makes use of the images generated here). +See [CycleSDK](https://bitbucket.org/oxdi/cycle-sdk) for the complete development environment (which makes use of the images generated here). Building the images @@ -26,6 +26,21 @@ The .box image is now ready to go. Install it into Vagrant via: vagrant box add cycle64 cycle64-virtualbox.box ``` +Updating the public box image +----------------------------- +`s3put` is handy command line wrapper for copying files to Amazon S3, it's part of the [boto](https://github.com/boto/boto) library. +Install boto: +``` +pip install boto +``` + +Push the .box image to S3 via s3put + +``` +s3put -a $AWS_ID -s $AWS_KEY -b oxdi -g public-read --prefix `pwd` cycle64-virtualbox.box +``` + +The box will then be available at http://amazonaws.com/oxdi/cycle64-virtualbox.box diff --git a/definitions/nixos32/configuration.nix b/definitions/nixos32/configuration.nix deleted file mode 100644 index 31b1807..0000000 --- a/definitions/nixos32/configuration.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ 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" - ]; - } ]; - }; -} diff --git a/definitions/nixos32/definition.rb b/definitions/nixos32/definition.rb deleted file mode 100644 index 2021aec..0000000 --- a/definitions/nixos32/definition.rb +++ /dev/null @@ -1,50 +0,0 @@ -iso = { - :url => 'http://nixos.org/releases/nixos/nixos-0.2pre4476_a5e4432-b076ab9/nixos-minimal-0.2pre4476_a5e4432-b076ab9-i686-linux.iso', - :md5 => 'f035bb375f0fbcbbc4e33a12131e91d4', -} - -session = { - :boot_cmd_sequence => - [ - '', ''*15, - 'root', '', - 'stop sshd', '', # Make sure we don't accept connections until reboot - 'fdisk /dev/sda', '', - 'n', ''*5, - 'a', '', - '1', '', - 'w', '', - 'mkfs.ext4 -j -L nixos /dev/sda1', '', - 'mount LABEL=nixos /mnt', '', - 'nixos-option --install', '', - 'curl http://%IP%:%PORT%/configuration.nix > /mnt/etc/nixos/configuration.nix &&', '', - 'nixos-install &&', '', - 'reboot', '', - ], - :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', - :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 diff --git a/definitions/nixos32/postinstall.sh b/definitions/nixos32/postinstall.sh deleted file mode 100755 index 6e3e215..0000000 --- a/definitions/nixos32/postinstall.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/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 diff --git a/definitions/nixos64/configuration.nix b/definitions/nixos64/configuration.nix deleted file mode 100644 index 31b1807..0000000 --- a/definitions/nixos64/configuration.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ 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" - ]; - } ]; - }; -} diff --git a/definitions/nixos64/definition.rb b/definitions/nixos64/definition.rb deleted file mode 100644 index 233ced2..0000000 --- a/definitions/nixos64/definition.rb +++ /dev/null @@ -1,50 +0,0 @@ -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 => - [ - '', ''*15, - 'root', '', - 'stop sshd', '', # Make sure we don't accept connections until reboot - 'fdisk /dev/sda', '', - 'n', ''*5, - 'a', '', - '1', '', - 'w', '', - 'mkfs.ext4 -j -L nixos /dev/sda1', '', - 'mount LABEL=nixos /mnt', '', - 'nixos-option --install', '', - 'curl http://%IP%:%PORT%/configuration.nix > /mnt/etc/nixos/configuration.nix &&', '', - 'nixos-install &&', '', - 'reboot', '', - ], - :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 diff --git a/definitions/nixos64/postinstall.sh b/definitions/nixos64/postinstall.sh deleted file mode 100755 index 6e3e215..0000000 --- a/definitions/nixos64/postinstall.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/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 diff --git a/nixos/basic.nix b/nixos/basic.nix new file mode 100644 index 0000000..3778557 --- /dev/null +++ b/nixos/basic.nix @@ -0,0 +1,23 @@ +{ 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"; + + # hostname + networking.hostName = "CycleSDK"; + + # Enable the OpenSSH daemon. + services.openssh.enable = true; + + # Enable DBus + services.dbus.enable = true; + +} diff --git a/http/configuration.nix b/nixos/configuration.nix similarity index 82% rename from http/configuration.nix rename to nixos/configuration.nix index cd0ffb3..1bf16df 100644 --- a/http/configuration.nix +++ b/nixos/configuration.nix @@ -11,9 +11,8 @@ boot.loader.grub.version = 2; boot.loader.grub.device = "/dev/sda"; - networking.hostName = "nixbox"; - - # Services to enable: + # hostname + networking.hostName = "CycleSDK"; # Enable the OpenSSH daemon. services.openssh.enable = true; @@ -21,14 +20,23 @@ # Enable DBus services.dbus.enable = true; + # Enable postgres + services.postgresql = { + enable = true; + package = pkgs.postgresql93; + enableTCPIP = true; + authentication = pkgs.lib.mkForce '' + local all all trust + host all all 127.0.0.1/32 trust + ''; + initialScript = "/etc/nixos/init.psql"; + }; + # Default packages environment.systemPackages = with pkgs; [ - gcc git - gnumake - python - ruby - rubygems + subversion + vim ]; # Creates a "vagrant" users with password-less sudo access diff --git a/nixos/init.psql b/nixos/init.psql new file mode 100644 index 0000000..cafefa9 --- /dev/null +++ b/nixos/init.psql @@ -0,0 +1,2 @@ + +CREATE ROLE vagrant WITH CREATEDB LOGIN; \ No newline at end of file diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh index 7942f9a..ac17ac9 100755 --- a/scripts/postinstall.sh +++ b/scripts/postinstall.sh @@ -1,19 +1,21 @@ #!/bin/sh -# Make sure we are totally up to date +# Checkout our nixpkg tree +NIXREPO=/etc/nixos/oxdi +mkdir -p $NIXREPO +cd $NIXREPO +git clone https://github.com/oxdi/nixpkgs.git -nix-channel --add http://nixos.org/channels/nixos-13.10 nixos -nixos-rebuild switch --upgrade +# Update and initialize our new configuration +nixos-rebuild -I nixos=$NIXREPO/nixos -I nixpkgs=$NIXREPO/nixpkgs 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 diff --git a/cycle64-template.json b/template.json similarity index 79% rename from cycle64-template.json rename to template.json index 45d9569..ddcbe7a 100644 --- a/cycle64-template.json +++ b/template.json @@ -2,7 +2,7 @@ "builders": [ { "type": "virtualbox-iso", - "boot_wait": "1m", + "boot_wait": "2m", "boot_command": [ "root", "stop sshd", @@ -16,7 +16,6 @@ "mkfs.ext4 -j -L nixos /dev/sda1", "mount LABEL=nixos /mnt", "nixos-generate-config --root /mnt", - "curl http://{{ .HTTPIP }}:{{ .HTTPPort }}/configuration.nix | sed -e 's|nixbox|nixbox64|g' > /mnt/etc/nixos/configuration.nix", "nixos-install && reboot" ], "guest_additions_mode": "disable", @@ -24,7 +23,7 @@ "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", + "iso_url": "http://releases.nixos.org/nixos/unstable/nixos-14.02pre38596.1dd0e05/nixos-minimal-14.02pre38596.1dd0e05-x86_64-linux.iso", "shutdown_command": "sudo shutdown -h now", "ssh_password": "vagrant", "ssh_port": 22, @@ -34,6 +33,11 @@ } ], "provisioners": [ + { + "type": "file", + "source": "nixos/", + "destination": "/etc/nixos" + }, { "type": "shell", "execute_command": "sudo sh '{{.Path}}'",