From 2efaf0f219850cd02cc77cb41d6c1c1bdd9de6ba Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Oct 2015 20:06:17 +0200 Subject: populate dir: improve error message --- krebs/default.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index c23cf152..5e6595ce 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -221,11 +221,15 @@ let out = { ${config.path}/ \ root@${target}:${config.target-path} ''; - url = "file://${config.host.name}${config.path}"; + current-url = "${current-user-name}@${current-host.name}"; + source-url = "file://${config.host.name}${config.path}"; + target-url = "root@${target}:${config.target-path}"; in #if can-link then link-method else if can-push then push-method else - throw "cannot source ${url}"; + throw + # /!\ revise this message when using more than just push-method + "No way to push ${source-url} from ${current-url} to ${target-url}"; methods.git = config: rootssh target '' -- cgit v1.2.3 From acb53c23dcb11de02e642e7f99e83401531e48c1 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Oct 2015 20:19:40 +0200 Subject: populate dir: drop link-method fragments --- krebs/default.nix | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 5e6595ce..40b3550c 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -203,11 +203,8 @@ let out = { current-host = config.krebs.hosts.${current-host-name}; current-user = config.krebs.users.${current-user-name}; - target-host = config.krebs.hosts.${system}; - methods.dir = config: let - can-link = config.host.name == target-host.name; can-push = config.host.name == current-host.name; push-method = '' rsync \ @@ -219,13 +216,12 @@ let out = { --delete-excluded \ -vrLptgoD \ ${config.path}/ \ - root@${target}:${config.target-path} + ${target-url} ''; current-url = "${current-user-name}@${current-host.name}"; source-url = "file://${config.host.name}${config.path}"; target-url = "root@${target}:${config.target-path}"; in - #if can-link then link-method else if can-push then push-method else throw # /!\ revise this message when using more than just push-method -- cgit v1.2.3 From 9cb1fdc946aecc96bd9bbadca77b6d7e3c87abd3 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Oct 2015 20:24:25 +0200 Subject: populate dir: reduce noise in error message --- krebs/default.nix | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 40b3550c..3e86c046 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -216,16 +216,13 @@ let out = { --delete-excluded \ -vrLptgoD \ ${config.path}/ \ - ${target-url} + root@${target}:${config.target-path} ''; - current-url = "${current-user-name}@${current-host.name}"; - source-url = "file://${config.host.name}${config.path}"; - target-url = "root@${target}:${config.target-path}"; in if can-push then push-method else - throw - # /!\ revise this message when using more than just push-method - "No way to push ${source-url} from ${current-url} to ${target-url}"; + let dir = "file://${config.host.name}${config.path}"; in + # /!\ revise this message when using more than just push-method + throw "No way to push ${dir} from ${current-host.name} to ${target}"; methods.git = config: rootssh target '' -- cgit v1.2.3 From 914c4c4a2fb6be95f7f4dbc9134fd272ec210c26 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Oct 2015 20:28:26 +0200 Subject: krebs default: drop redundant "lib." --- krebs/default.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 3e86c046..9258c236 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -48,14 +48,14 @@ let out = { # eval "$RSYNC_RSH \"\$@\"" #} - ${lib.rootssh target '' + ${rootssh target '' ${builtins.readFile ./4lib/infest/prepare.sh} ${builtins.readFile ./4lib/infest/install-nix.sh} ''} - (${lib.populate args}) + (${populate args}) - ${lib.rootssh target '' + ${rootssh target '' export PATH; PATH=/root/.nix-profile/bin:$PATH src=$(type -p nixos-install) @@ -79,7 +79,7 @@ let out = { { cat_src | sed -n "1,$i{p}" - cat ${lib.doc (install args)} + cat ${doc (install args)} cat_src | sed -n "$i,\''${$i!p}" } > nixos-install chmod +x nixos-install -- cgit v1.2.3 From 9bbdfb85cf333fde4050bbef738c54ca988db228 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Oct 2015 22:13:42 +0200 Subject: export krebs.populate --- krebs/default.nix | 1 + 1 file changed, 1 insertion(+) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 9258c236..4d09075c 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -8,6 +8,7 @@ let out = { inherit deploy; inherit infest; inherit init; + inherit populate; inherit lib; }; -- cgit v1.2.3 From fc45cc29265e9b3e51033fddd5d8ea1042c1aa41 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 20 Oct 2015 23:17:32 +0200 Subject: export krebs.nixos-install Collaterally, unexport krebs.populate again. --- krebs/default.nix | 101 ++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 53 deletions(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 4d09075c..de805a89 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -8,8 +8,8 @@ let out = { inherit deploy; inherit infest; inherit init; - inherit populate; inherit lib; + inherit nixos-install; }; deploy = @@ -24,7 +24,7 @@ let out = { set -efu (${populate args}) ${rootssh target '' - ${install args} + ${nix-install args} ${config.krebs.build.profile}/bin/switch-to-configuration switch ''} echo OK @@ -40,63 +40,14 @@ let out = { # krebs.infest set -efu - # XXX type -p is non-standard - #export RSYNC_RSH; RSYNC_RSH="$(type -p ssh) \ - # -o 'HostName $ {target.host.infest.addr}' \ - # -o 'Port $ {toString target.host.infest.port}' \ - #" - #ssh() { - # eval "$RSYNC_RSH \"\$@\"" - #} - ${rootssh target '' ${builtins.readFile ./4lib/infest/prepare.sh} ${builtins.readFile ./4lib/infest/install-nix.sh} ''} - (${populate args}) + (${nixos-install args}) ${rootssh target '' - export PATH; PATH=/root/.nix-profile/bin:$PATH - - src=$(type -p nixos-install) - cat_src() { - sed < "$src" "$( - { sed < "$src" -n ' - /^if ! test -e "\$mountPoint\/\$NIXOS_CONFIG/,/^fi$/= - /^nixpkgs=/= - /^NIX_PATH=/,/^$/{/./=} - - # Disable: Copy the NixOS/Nixpkgs sources to the target as - # the initial contents of the NixOS channel. - /^srcs=/,/^ln -sfn /= - ' - } | sed 's:$:s/^/#krebs#/:' - )" - } - - # Location to insert install - i=$(sed -n '/^echo "building the system configuration/=' "$src") - - { - cat_src | sed -n "1,$i{p}" - cat ${doc (install args)} - cat_src | sed -n "$i,\''${$i!p}" - } > nixos-install - chmod +x nixos-install - - ## Wrap inserted install into chroot. - #nix_env=$(cat_src | sed -n ' - # s:.*\(/nix/store/[a-z0-9]*-nix-[0-9.]\+/bin/nix-env\).*:\1:p;T;q - #') - #echo nix-env is $nix_env - #sed -i ' - # s:^nix-env:chroot $mountPoint '"$nix_env"': - #' nixos-install - - unset SSL_CERT_FILE - ./nixos-install - ${builtins.readFile ./4lib/infest/finalize.sh} ''} ''; @@ -136,6 +87,50 @@ let out = { EOF ''; + nixos-install = + { system ? current-host-name + , target ? system + }@args: let + in '' + #! /bin/sh + # ${current-date} ${current-user-name}@${current-host-name} + # krebs.nixos-install + (${populate args}) + + ${rootssh target '' + export PATH; PATH=/root/.nix-profile/bin:$PATH + + src=$(type -p nixos-install) + cat_src() { + sed < "$src" "$( + { sed < "$src" -n ' + /^if ! test -e "\$mountPoint\/\$NIXOS_CONFIG/,/^fi$/= + /^nixpkgs=/= + /^NIX_PATH=/,/^$/{/./=} + + # Disable: Copy the NixOS/Nixpkgs sources to the target as + # the initial contents of the NixOS channel. + /^srcs=/,/^ln -sfn /= + ' + } | sed 's:$:s/^/#krebs#/:' + )" + } + + # Location to insert `nix-install` + i=$(sed -n '/^echo "building the system configuration/=' "$src") + + { + cat_src | sed -n "1,$i{p}" + cat ${doc (nix-install args)} + cat_src | sed -n "$i,\''${$i!p}" + } > nixos-install + chmod +x nixos-install + + unset SSL_CERT_FILE + ./nixos-install + ''} + ''; + lib = import ./4lib { lib = import ; } // rec { stockholm-path = ../.; nspath = ns: p: stockholm-path + "/${ns}/${p}"; @@ -153,7 +148,7 @@ let out = { stockholm.users.${current-user-name}.${system}.config or (abort "unknown system: ${system}, user: ${current-user-name}"); - install = + nix-install = { system ? current-host-name , target ? system }: -- cgit v1.2.3 From 226ea391caec5b3f2f112de263dd2db3a0e012f4 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 21 Oct 2015 00:08:18 +0200 Subject: stockholm: provide krebs lib --- krebs/default.nix | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index de805a89..5518a449 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -1,6 +1,7 @@ { current-date , current-host-name , current-user-name +, lib , stockholm }: @@ -8,7 +9,6 @@ let out = { inherit deploy; inherit infest; inherit init; - inherit lib; inherit nixos-install; }; @@ -131,11 +131,6 @@ let out = { ''} ''; - lib = import ./4lib { lib = import ; } // rec { - stockholm-path = ../.; - nspath = ns: p: stockholm-path + "/${ns}/${p}"; - }; - doc = s: let b = "EOF${builtins.hashString "sha256" s}"; in '' -- cgit v1.2.3 From 9c9a7d611ed9201e84ed49067027e85389313b7c Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 21 Oct 2015 02:21:56 +0200 Subject: krebs.nixos-install: bring back chroot wrapper Because we _do_ need it. :D --- krebs/default.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 5518a449..5f1cfb95 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -126,6 +126,16 @@ let out = { } > nixos-install chmod +x nixos-install + # Wrap inserted nix-install into chroot. + nix_env=$(cat_src | sed -n ' + s:.*\(/nix/store/[a-z0-9]*-nix-[0-9.]\+/bin/nix-env\).*:\1:p;T;q + ') + echo nix-env is $nix_env + sed -i ' + s:^NIX_PATH=:chroot $mountPoint /usr/bin/env &: + s:^nix-env:'"$nix_env"': + ' nixos-install + unset SSL_CERT_FILE ./nixos-install ''} -- cgit v1.2.3 From 48abef60c172bdd5d15e574138824a89b23fa86d Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 21 Oct 2015 12:45:50 +0200 Subject: krebs.nixos-install: discover coreutils in /mnt --- krebs/default.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 5f1cfb95..24d9e843 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -130,9 +130,12 @@ let out = { nix_env=$(cat_src | sed -n ' s:.*\(/nix/store/[a-z0-9]*-nix-[0-9.]\+/bin/nix-env\).*:\1:p;T;q ') + coreutils=$(find /mnt/nix/store \ + -mindepth 1 -maxdepth 1 -type d -name '*-coreutils-*' \ + | head -n 1 | sed s:^/mnt::) echo nix-env is $nix_env sed -i ' - s:^NIX_PATH=:chroot $mountPoint /usr/bin/env &: + s:^NIX_PATH=:chroot $mountPoint '"$coreutils"'/bin/env &: s:^nix-env:'"$nix_env"': ' nixos-install -- cgit v1.2.3 From df04a82426ad36726da7becae5ec4b6c33d8d14b Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 21 Oct 2015 13:13:49 +0200 Subject: krebs.nixos-infest: set SSL_CERT_FILE properly --- krebs/default.nix | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 24d9e843..0b055cd2 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -130,16 +130,24 @@ let out = { nix_env=$(cat_src | sed -n ' s:.*\(/nix/store/[a-z0-9]*-nix-[0-9.]\+/bin/nix-env\).*:\1:p;T;q ') - coreutils=$(find /mnt/nix/store \ - -mindepth 1 -maxdepth 1 -type d -name '*-coreutils-*' \ - | head -n 1 | sed s:^/mnt::) - echo nix-env is $nix_env + echo "nix-env is $nix_env" >&2 + getchrootpath() {( + name=$1 + path=$(find /mnt/nix/store \ + -mindepth 1 -maxdepth 1 -type d -name '*-'"$name"'-*' \ + | head -n 1 | sed s:^/mnt::) + echo "$name is $path" >&2 + echo "$path" + )} + cacert=$(getchrootpath cacert) + coreutils=$(getchrootpath coreutils) + env="$coreutils/bin/env \ + SSL_CERT_FILE=$cacert/etc/ssl/certs/ca-bundle.crt" sed -i ' - s:^NIX_PATH=:chroot $mountPoint '"$coreutils"'/bin/env &: + s:^NIX_PATH=:chroot $mountPoint '"$env"' &: s:^nix-env:'"$nix_env"': ' nixos-install - unset SSL_CERT_FILE ./nixos-install ''} ''; -- cgit v1.2.3 From fc64fd18cb8677f08d038a086de879fd69f89b8c Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 22 Oct 2015 00:20:16 +0200 Subject: krebs.*: make StrictHostKeyChecking configurable --- krebs/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 0b055cd2..08de7229 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -3,6 +3,7 @@ , current-user-name , lib , stockholm +, StrictHostKeyChecking ? "yes" }: let out = { @@ -260,7 +261,10 @@ let out = { in out; rootssh = target: script: - "ssh root@${target} -T ${doc '' + let + flags = "-o StrictHostKeyChecking=${StrictHostKeyChecking}"; + in + "ssh ${flags} root@${target} -T ${doc '' set -efu ${script} ''}"; -- cgit v1.2.3 From 4b8ffc1bfd494de1fafde2527a337ad5eb31a27c Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 22 Oct 2015 00:23:02 +0200 Subject: krebs.nixos-install: fail if pkg cannot be found Collaterally, search in /nix instead of /mnt/nix --- krebs/default.nix | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 08de7229..40d245f9 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -132,16 +132,20 @@ let out = { s:.*\(/nix/store/[a-z0-9]*-nix-[0-9.]\+/bin/nix-env\).*:\1:p;T;q ') echo "nix-env is $nix_env" >&2 - getchrootpath() {( + findpkg() {( name=$1 - path=$(find /mnt/nix/store \ + path=$(find /nix/store \ -mindepth 1 -maxdepth 1 -type d -name '*-'"$name"'-*' \ | head -n 1 | sed s:^/mnt::) - echo "$name is $path" >&2 - echo "$path" + if echo "$path" | grep .; then + echo "$name is $path" >&2 + else + echo "Error: package not found: $name" >&2 + exit 1 + fi )} - cacert=$(getchrootpath cacert) - coreutils=$(getchrootpath coreutils) + cacert=$(findpkg cacert) + coreutils=$(findpkg coreutils) env="$coreutils/bin/env \ SSL_CERT_FILE=$cacert/etc/ssl/certs/ca-bundle.crt" sed -i ' -- cgit v1.2.3 From df6f0392cbdf7923537eb5d328bd345cde11eb53 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 22 Oct 2015 00:49:51 +0200 Subject: krebs.nixos-install: cacert -> /root/SSL_CERT_FILE --- krebs/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'krebs/default.nix') diff --git a/krebs/default.nix b/krebs/default.nix index 40d245f9..31a7f7d0 100644 --- a/krebs/default.nix +++ b/krebs/default.nix @@ -146,8 +146,8 @@ let out = { )} cacert=$(findpkg cacert) coreutils=$(findpkg coreutils) - env="$coreutils/bin/env \ - SSL_CERT_FILE=$cacert/etc/ssl/certs/ca-bundle.crt" + cp "$cacert"/etc/ssl/certs/ca-bundle.crt /mnt/root/SSL_CERT_FILE + env="$coreutils/bin/env SSL_CERT_FILE=/root/SSL_CERT_FILE" sed -i ' s:^NIX_PATH=:chroot $mountPoint '"$env"' &: s:^nix-env:'"$nix_env"': -- cgit v1.2.3