Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nixos19.09 #42

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6098f3b
[nixos]: minimal from scratch version
augu5te Jul 10, 2019
5c4077d
[nixos] Add nixos-19.09 recipe
augu5te Dec 16, 2019
6fa89b9
[nixos-19.09] cleaning configuration.nix
augu5te Dec 19, 2019
802ba77
[nixos] do not change global script prepare_disk just for nix.
npf Feb 6, 2020
a66e457
[nixos] rework the recipes inheritance
npf Feb 6, 2020
19cc085
[nixos] do not change the export section by default
npf Feb 6, 2020
a2d51f5
Update the qemy-sendkeys script, so that it handles more characters
npf Mar 25, 2020
1a256a6
[nixos] Move nix data files to the nixos directory
npf Mar 13, 2020
bf1e772
[nixos] rework the from_scratch/nixos-base recipe
npf Mar 25, 2020
058a846
[nixos] fixup move nixos data files
npf Mar 25, 2020
849c288
[base] add option for the first VM boot timeout
npf Mar 25, 2020
03017c6
Generate the insecure ssh key a bit earlier, before the 1st VM boot
npf Mar 25, 2020
83f1b99
[nixos] revert to use the base bootstrap.
npf Mar 25, 2020
7626771
[nixos] fix the grub installation device
npf Mar 25, 2020
bdc13e0
[nixos] make autoinstall.sh install the bootloader
npf Mar 25, 2020
4e0a6c6
[nixos] fix installer, use new url, add nixos 20.03
npf May 3, 2020
5919d29
Remove g5k workaround for qemu user network
npf May 3, 2020
e9eadf5
Add option to prepare_appliance to not run the steps using virt-custo…
npf May 3, 2020
95f8130
[from_scratch/base] reorganize the bootstrap steps
npf May 3, 2020
58ace03
[nixos] use kameleon default root password
npf May 3, 2020
6fefec6
[nixos] fix the root ssh key and password setup (virt-customize does …
npf May 3, 2020
f55b520
[nixos] fix the in_context: bash is /run/current-system/sw/bin/bash
npf May 3, 2020
c288003
[nixos] do not setup the serial console for grub and linux at this st…
npf May 3, 2020
5ff664a
[nixos] fix the boot on the root device: qemu needs the virtio driver…
npf May 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions from_scratch/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ global:
qemu_append_cmdline: $${installer_cmdline}
qemu_iso_path: $${kameleon_cwd}/qemu.iso

first_vm_boot_timeout: 5

# rootfs options
disk_device: /dev/vda
rootfs: /rootfs
Expand Down Expand Up @@ -105,15 +107,15 @@ bootstrap:
- enable_checkpoint
- download_installer
- prepare_disk
- prepare_autoinstall
- prepare_ssh_to_out_context
- start_http_server
- prepare_autoinstall
- start_qemu:
- force_vm_shutdown: false
- shutdown_vm_immediately: true
- vm_cleanup_section: bootstrap
- vm_expected_service:
- boot_timeout: 5
- prepare_ssh_to_out_context
- boot_timeout: $${first_vm_boot_timeout}
- prepare_appliance
- start_qemu:
- force_vm_shutdown: true
Expand Down
21 changes: 21 additions & 0 deletions from_scratch/nixos-19.03.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#==============================================================================
# vim: softtabstop=2 shiftwidth=2 expandtab fenc=utf-8 cc=81 tw=80
#==============================================================================
#
# DESCRIPTION: NIXOS
#
#==============================================================================
---
extend: nixos-base.yaml

global:
release: 19.03

bootstrap:
- "@base"

setup:
- "@base"

export:
- "@base"
21 changes: 21 additions & 0 deletions from_scratch/nixos-19.09.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#==============================================================================
# vim: softtabstop=2 shiftwidth=2 expandtab fenc=utf-8 cc=81 tw=80
#==============================================================================
#
# DESCRIPTION: NIXOS
#
#==============================================================================
---
extend: nixos-base.yaml

global:
release: 19.09

bootstrap:
- "@base"

setup:
- "@base"

export:
- "@base"
21 changes: 21 additions & 0 deletions from_scratch/nixos-20.03.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#==============================================================================
# vim: softtabstop=2 shiftwidth=2 expandtab fenc=utf-8 cc=81 tw=80
#==============================================================================
#
# DESCRIPTION: NIXOS
#
#==============================================================================
---
extend: nixos-base.yaml

global:
release: 20.03

bootstrap:
- "@base"

setup:
- "@base"

export:
- "@base"
52 changes: 52 additions & 0 deletions from_scratch/nixos-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#==============================================================================
# vim: softtabstop=2 shiftwidth=2 expandtab fenc=utf-8 cc=81 tw=80
#==============================================================================
#
# DESCRIPTION: NIXOS
#
#==============================================================================
---
extend: base.yaml

global:
distrib: nixos
release: 19.09

installer_iso_url: https://channels.nixos.org/$${distrib}-$${release}/latest-nixos-minimal-$${arch}-linux.iso
# To use a special build, comment the previous line and uncomment the build
# and installer_iso_url lines below. Builds can be found at http://releases.nixos.org/?prefix=nixos/19.09-small/
#build: 2484.322fd893724
#installer_iso_url: http://releases.nixos.org/$${distrib}/$${release}-small/$${distrib}-$${release}.$${build}/$${distrib}-minimal-$${release}.$${build}-$${arch}-linux.iso

qemu_iso_path: $${kameleon_cwd}/$${distrib}.iso

qemu_sendkeys_commands: $${kameleon_data_dir}/qemu-sendkeys/netinst-iso-$${distrib}
qemu_memory_size: 2048

first_vm_boot_timeout: 40
use_virt_customize: false

autoinstall_script_path: $${kameleon_data_dir}/$${distrib}/autoinstall.sh

nix_hardware_configuration: $${kameleon_data_dir}/$${distrib}/hardware-configuration.nix
nix_configuration: $${kameleon_data_dir}/$${distrib}/configuration.nix

out_context:
cmd: ssh -F $${ssh_config_file} $${kameleon_recipe_name} -t /run/current-system/sw/bin/bash
workdir: /root/kameleon_workdir
proxy_cache: $${local_ip}

in_context:
cmd: ssh -F $${ssh_config_file} $${kameleon_recipe_name} -t /run/current-system/sw/bin/bash
workdir: /root/kameleon_workdir
proxy_cache: $${local_ip}

bootstrap:
- "@base"
- breakpoint
setup:
- "@base"
- breakpoint

export:
- "@base"
23 changes: 13 additions & 10 deletions steps/bootstrap/nixos/prepare_autoinstall.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
- insecure_ssh_key: $${kameleon_cwd}/insecure_ssh_key

- copy_autoinstall_script_to_http_directory:
- exec_local: mkdir -p $${http_directory}
- exec_local: cp $${autoinstall_script_path} $${http_directory}/autoinstall.sh
- exec_local: cp $${nix_configuration} $${http_directory}/configuration.nix
- exec_local: cp $${nix_hardware_configuration} $${http_directory}/hardware-configuration.nix

- configure_proxy:
- exec_local: |
if [ ! "$${proxy_out}" = "" ]; then
sed -i s'|export http_proxy=\(.*\)|export http_proxy=http://$${proxy_out}|'g $${http_directory}/autoinstall.sh
if [ -n "$${proxy_out}" ]; then
sed -i -e "s|%HTTP_PROXY%|http://$${proxy_out}|g" $${http_directory}/autoinstall.sh
else
sed -i -e "s|%HTTP_PROXY%||g" $${http_directory}/autoinstall.sh
fi

- set_root_password:
- exec_local: |
sed -i s'|export PASSWD=\(.*\)|export PASSWD=$${root_password}|'g $${http_directory}/autoinstall.sh

- write_boot_command:
- write_local:
- $${kameleon_cwd}/boot_command
- >
curl -sSL http://$${local_ip}:$${http_port}/configuration.nix <gt> /tmp/configuration.nix<kp_enter>
curl -sSL http://$${local_ip}:$${http_port}/autoinstall.sh | bash<kp_enter>
INSECURE_SSH_KEY_PUB=$(< $${insecure_ssh_key}.pub)
sed -i -e "s|%PASSWORD%|$${root_password}|g" $${http_directory}/autoinstall.sh
sed -i -e "s|%LOCAL_IP%|$${local_ip}|g" $${http_directory}/autoinstall.sh
sed -i -e "s|%HTTP_PORT%|$HTTP_PORT|g" $${http_directory}/autoinstall.sh
sed -i -e "s|%PASSWORD%|$${root_password}|g" $${http_directory}/configuration.nix
sed -i -e "s|%SSH_PUBLIC_KEY%|$INSECURE_SSH_KEY_PUB|g" $${http_directory}/configuration.nix
64 changes: 22 additions & 42 deletions steps/bootstrap/prepare_appliance.yaml
Original file line number Diff line number Diff line change
@@ -1,53 +1,33 @@
- insecure_ssh_key: $${kameleon_cwd}/insecure_ssh_key
- enable_workaround_login_delay: false
- use_virt_customize: true

- generate_ssh_keys:
- check_cmd_local: ssh-keygen
- exec_local: echo -e 'y\n' | ssh-keygen -q -t rsa -b 4096 -f $${insecure_ssh_key} -N ''
- show_ssh_keys:
- exec_local: cat $${insecure_ssh_key}
- exec_local: cat $${insecure_ssh_key}.pub

- inject_ssh_private_key:
- check_cmd_local: virt-customize
- exec_local: |
virt-customize \
-a $${image_disk}.$${image_format} \
--run-command 'mkdir -p /root/.ssh' \
--upload $${insecure_ssh_key}.pub:/root/.ssh/.kameleon_authorized_keys \
--run-command 'touch /root/.ssh/authorized_keys' \
--run-command 'cp /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bak' \
--run-command 'cat /root/.ssh/.kameleon_authorized_keys >> /root/.ssh/authorized_keys' \
--run-command 'chmod 700 /root/.ssh' \
--run-command 'chmod -R go-rw /root/.ssh' \
--run-command 'chown -R root:root /root/.ssh'
- on_export_init:
- exec_local: |
virt-customize \
-a $${image_disk}.$${image_format} \
--run-command 'mv /root/.ssh/authorized_keys.bak /root/.ssh/authorized_keys' \
--delete /root/.ssh/.kameleon_authorized_keys

- add_insecure_key_to_ssh_config:
- on_checkpoint: redo
- exec_local: |
cat <<EOF >> $${ssh_config_file}
IdentityFile $${insecure_ssh_key}
EOF

- workaround_login_delay_due_to_ldap_and_dns:
- test:
- exec_local: test "$${enable_workaround_login_delay}" = "true"
- exec_local: test "$${use_virt_customize}" = "true"
- exec_local: |
virt-customize \
-a $${image_disk}.$${image_format} \
--run-command 'mv /etc/nslcd.conf /etc/nslcd.conf.orig-g5k' \
--run-command 'sed -i.orig-g5k "s/ ldap//" /etc/nsswitch.conf' \
--run-command 'echo > /etc/resolv.conf'
- exec_local: echo "Workaround is not enabled"
- on_setup_clean:
- test:
- exec_local: test "$${enable_workaround_login_delay}" = "true"
- exec_local: |
virt-customize \
-a $${image_disk}.$${image_format} \
--run-command 'mv /etc/nslcd.conf.orig-g5k /etc/nslcd.conf' \
--run-command 'mv /etc/nsswitch.conf.orig-g5k /etc/nsswitch.conf'
--run-command 'mkdir -p /root/.ssh' \
--upload $${insecure_ssh_key}.pub:/root/.ssh/.kameleon_authorized_keys \
--run-command 'touch /root/.ssh/authorized_keys' \
--run-command 'cp /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bak' \
--run-command 'cat /root/.ssh/.kameleon_authorized_keys >> /root/.ssh/authorized_keys' \
--run-command 'chmod 700 /root/.ssh' \
--run-command 'chmod -R go-rw /root/.ssh' \
--run-command 'chown -R root:root /root/.ssh'
- exec_local: echo "Do nothing (do not use virt-customize)"
- on_export_init:
- test:
- exec_local: test "$${use_virt_customize}" = "true"
- exec_local: |
virt-customize \
-a $${image_disk}.$${image_format} \
--run-command 'mv /root/.ssh/authorized_keys.bak /root/.ssh/authorized_keys' \
--delete /root/.ssh/.kameleon_authorized_keys
- exec_local: echo "Do nothing (do not use virt-customize)"
10 changes: 10 additions & 0 deletions steps/bootstrap/prepare_ssh_to_out_context.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
- insecure_ssh_key: $${kameleon_cwd}/insecure_ssh_key

- select_empty_port:
- on_checkpoint: redo
- exec_local: |
# Find empty SSH forwarding port
SSH_FWD_PORT=$(__find_free_port 50000 60000)
echo "SSH forwarding port: $SSH_FWD_PORT"

- generate_ssh_keys:
- check_cmd_local: ssh-keygen
- exec_local: echo -e 'y\n' | ssh-keygen -q -t rsa -b 4096 -f $${insecure_ssh_key} -N ''
- exec_local: cat $${insecure_ssh_key}

- prepare_ssh_config:
- on_checkpoint: redo
- write_local:
Expand All @@ -21,3 +29,5 @@
ForwardAgent yes
Compression yes
Protocol 2
IdentityFile $${insecure_ssh_key}

1 change: 1 addition & 0 deletions steps/bootstrap/start_http_server.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- http_script: $${kameleon_data_dir}/helpers/simple_http_server.py

- run_http_server:
- exec_local: mkdir -p $${http_directory}
- exec_local: |
HTTP_PORT=$(__find_free_port 8000 8100)
echo "HTTP port: $HTTP_PORT"
Expand Down
3 changes: 2 additions & 1 deletion steps/bootstrap/start_qemu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- no_reboot: true
- socat_monitor: socat - UNIX-CONNECT:$${qemu_monitor_socket}
- qemu_sendkeys_script: $${kameleon_data_dir}/qemu-sendkeys.rb
- qemu_sendkeys_opts:
- qemu_sendkeys_commands:
- vm_expected_service: ssh
- vm_cleanup_section: setup
Expand Down Expand Up @@ -207,7 +208,7 @@
- exec_local: |
echo "Sending keyboard commands to the VM: $${qemu_sendkeys_commands}"
echo "(Local httpd server url: http://$${local_ip}:$HTTP_PORT)"
ruby $${qemu_sendkeys_script} -d 0.05 "$(sed -e s/%LOCAL_IP%/$${local_ip}/g -e s/%HTTP_PORT%/$HTTP_PORT/g $${qemu_sendkeys_commands})" | $${socat_monitor} > /dev/null
ruby $${qemu_sendkeys_script} $${qemu_sendkeys_opts} "$(sed -e s/%LOCAL_IP%/$${local_ip}/g -e s/%HTTP_PORT%/$HTTP_PORT/g $${qemu_sendkeys_commands})" | $${socat_monitor} > /dev/null
- exec_local: echo "No keyboard commands to send"

- shutdown_vm:
Expand Down
20 changes: 0 additions & 20 deletions steps/data/configuration.nix

This file was deleted.

33 changes: 0 additions & 33 deletions steps/data/nixos-autoinstall.sh

This file was deleted.

Loading