simplify the os build
This commit is contained in:
parent
fb9fba3d07
commit
d6d8bc7c1c
19
README.md
19
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
|
Cycle's OS is based on [NixOS](http://nixos.org), a linux distribution with a purely functional
|
||||||
package manager.
|
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
|
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
|
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
|
||||||
|
|
|
@ -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"
|
|
||||||
];
|
|
||||||
} ];
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -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 =>
|
|
||||||
[
|
|
||||||
'<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',
|
|
||||||
: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
|
|
|
@ -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
|
|
|
@ -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"
|
|
||||||
];
|
|
||||||
} ];
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -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 =>
|
|
||||||
[
|
|
||||||
'<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
|
|
|
@ -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
|
|
23
nixos/basic.nix
Normal file
23
nixos/basic.nix
Normal file
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -11,9 +11,8 @@
|
||||||
boot.loader.grub.version = 2;
|
boot.loader.grub.version = 2;
|
||||||
boot.loader.grub.device = "/dev/sda";
|
boot.loader.grub.device = "/dev/sda";
|
||||||
|
|
||||||
networking.hostName = "nixbox";
|
# hostname
|
||||||
|
networking.hostName = "CycleSDK";
|
||||||
# Services to enable:
|
|
||||||
|
|
||||||
# Enable the OpenSSH daemon.
|
# Enable the OpenSSH daemon.
|
||||||
services.openssh.enable = true;
|
services.openssh.enable = true;
|
||||||
|
@ -21,14 +20,23 @@
|
||||||
# Enable DBus
|
# Enable DBus
|
||||||
services.dbus.enable = true;
|
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
|
# Default packages
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
gcc
|
|
||||||
git
|
git
|
||||||
gnumake
|
subversion
|
||||||
python
|
vim
|
||||||
ruby
|
|
||||||
rubygems
|
|
||||||
];
|
];
|
||||||
|
|
||||||
# Creates a "vagrant" users with password-less sudo access
|
# Creates a "vagrant" users with password-less sudo access
|
2
nixos/init.psql
Normal file
2
nixos/init.psql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
CREATE ROLE vagrant WITH CREATEDB LOGIN;
|
|
@ -1,19 +1,21 @@
|
||||||
#!/bin/sh
|
#!/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
|
# Update and initialize our new configuration
|
||||||
nixos-rebuild switch --upgrade
|
nixos-rebuild -I nixos=$NIXREPO/nixos -I nixpkgs=$NIXREPO/nixpkgs switch
|
||||||
|
|
||||||
# Cleanup any previous generations and delete old packages that can be
|
# Cleanup any previous generations and delete old packages that can be
|
||||||
# pruned.
|
# pruned.
|
||||||
|
|
||||||
for x in `seq 0 2` ; do
|
for x in `seq 0 2` ; do
|
||||||
nix-env --delete-generations old
|
nix-env --delete-generations old
|
||||||
nix-collect-garbage -d
|
nix-collect-garbage -d
|
||||||
done
|
done
|
||||||
|
|
||||||
# Zero out the disk (for better compression)
|
# Zero out the disk (for better compression)
|
||||||
|
|
||||||
dd if=/dev/zero of=/EMPTY bs=1M
|
dd if=/dev/zero of=/EMPTY bs=1M
|
||||||
rm -rf /EMPTY
|
rm -rf /EMPTY
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"builders": [
|
"builders": [
|
||||||
{
|
{
|
||||||
"type": "virtualbox-iso",
|
"type": "virtualbox-iso",
|
||||||
"boot_wait": "1m",
|
"boot_wait": "2m",
|
||||||
"boot_command": [
|
"boot_command": [
|
||||||
"root<enter>",
|
"root<enter>",
|
||||||
"stop sshd<enter>",
|
"stop sshd<enter>",
|
||||||
|
@ -16,7 +16,6 @@
|
||||||
"mkfs.ext4 -j -L nixos /dev/sda1<enter><wait5>",
|
"mkfs.ext4 -j -L nixos /dev/sda1<enter><wait5>",
|
||||||
"mount LABEL=nixos /mnt<enter><wait>",
|
"mount LABEL=nixos /mnt<enter><wait>",
|
||||||
"nixos-generate-config --root /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>"
|
"nixos-install && reboot<enter>"
|
||||||
],
|
],
|
||||||
"guest_additions_mode": "disable",
|
"guest_additions_mode": "disable",
|
||||||
|
@ -24,7 +23,7 @@
|
||||||
"http_directory": "http",
|
"http_directory": "http",
|
||||||
"iso_checksum": "fbac8c11661028e6f9c4ec293e1329e1",
|
"iso_checksum": "fbac8c11661028e6f9c4ec293e1329e1",
|
||||||
"iso_checksum_type": "md5",
|
"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",
|
"shutdown_command": "sudo shutdown -h now",
|
||||||
"ssh_password": "vagrant",
|
"ssh_password": "vagrant",
|
||||||
"ssh_port": 22,
|
"ssh_port": 22,
|
||||||
|
@ -34,6 +33,11 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"provisioners": [
|
"provisioners": [
|
||||||
|
{
|
||||||
|
"type": "file",
|
||||||
|
"source": "nixos/",
|
||||||
|
"destination": "/etc/nixos"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"execute_command": "sudo sh '{{.Path}}'",
|
"execute_command": "sudo sh '{{.Path}}'",
|
Loading…
Reference in a new issue