From 04d4ea7d68c1d951e45bff7696192f31c4d0eef7 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 23 Jul 2017 21:36:41 +0200 Subject: [PATCH 1/8] shell: split init.proxy off from init.env --- shell.nix | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/shell.nix b/shell.nix index 2973d4c51..ca782d105 100644 --- a/shell.nix +++ b/shell.nix @@ -15,6 +15,7 @@ let \test -n "''${target-}" || target=$system \test -n "''${user-}" || user=$LOGNAME . ${init.env} + . ${init.proxy} exec ${utils.deploy} ''; @@ -29,6 +30,7 @@ let . ${init.args} \test -n "''${user-}" || user=$LOGNAME . ${init.env} + . ${init.proxy} exec ${utils.build} config.system.build.toplevel ''; @@ -114,9 +116,6 @@ let ''; init.env = pkgs.writeText "init.env" /* sh */ '' - source=''${source-$user/1systems/$system/source.nix} - - export source export system export target export user @@ -129,38 +128,31 @@ let export target_port="$(echo $target_object | ${pkgs.jq}/bin/jq -r .port)" export target_path="$(echo $target_object | ${pkgs.jq}/bin/jq -r .path)" export target_local="$(echo $target_object | ${pkgs.jq}/bin/jq -r .local)" + ''; + init.proxy = pkgs.writeText "init.proxy" /* sh */ '' if \test "''${using_proxy-}" != true; then - ${init.env.populate} + + source_file=$user/1systems/$system/source.nix + source=$(get-source "$source_file") + qualified_target=$target_user@$target_host:$target_port$target_path + echo "$source" | populate "$qualified_target" + if \test "$target_local" != true; then - exec ${init.env.proxy} "$command" "$@" + exec ${pkgs.openssh}/bin/ssh \ + "$target_user@$target_host" -p "$target_port" \ + cd "$target_path/stockholm" \; \ + NIX_PATH=$(quote "$target_path") \ + STOCKHOLM_VERSION=$(quote "$STOCKHOLM_VERSION") \ + nix-shell --run "$(quote " + system=$(quote "$system") \ + target=$(quote "$target") \ + using_proxy=true \ + $(quote "$command" "$@") + ")" fi fi - '' // { - populate = pkgs.writeDash "init.env.populate" '' - set -efu - _source=$(get-source "$source") - echo $_source | - ${pkgs.populate}/bin/populate \ - "$target_user@$target_host:$target_port$target_path" \ - >&2 - unset _source - ''; - proxy = pkgs.writeDash "init.env.proxy" '' - set -efu - exec ${pkgs.openssh}/bin/ssh \ - "$target_user@$target_host" -p "$target_port" \ - cd "$target_path/stockholm" \; \ - NIX_PATH=$(quote "$target_path") \ - STOCKHOLM_VERSION=$(quote "$STOCKHOLM_VERSION") \ - nix-shell --run "$(quote " - system=$(quote "$system") \ - target=$(quote "$target") \ - using_proxy=true \ - $(quote "$@") - ")" - ''; - }; + ''; utils.build = pkgs.writeDash "utils.build" '' set -efu @@ -204,6 +196,7 @@ in pkgs.stdenv.mkDerivation { export NIX_PATH=stockholm=$PWD:nixpkgs=${toString } export NIX_REMOTE=daemon export PATH=${lib.makeBinPath [ + pkgs.populate shell.cmdspkg ]} From 55bffc624a36fa9a6a58da68878ed969af763af8 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 23 Jul 2017 22:46:30 +0200 Subject: [PATCH 2/8] shell: add install command --- shell.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/shell.nix b/shell.nix index ca782d105..fce8eaa78 100644 --- a/shell.nix +++ b/shell.nix @@ -20,6 +20,47 @@ let exec ${utils.deploy} ''; + # usage: install [--user=USER] --system=SYSTEM --target=TARGET + cmds.install = pkgs.writeBash "cmds.install" '' + set -efu + + command=install + . ${init.args} + \test -n "''${user-}" || user=$LOGNAME + . ${init.env} + + if \test "''${using_proxy-}" != true; then + ${pkgs.openssh}/bin/ssh \ + -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null \ + "$target_user@$target_host" -p "$target_port" \ + env target_path=$(quote "$target_path") \ + sh -s prepare < ${./krebs/4lib/infest/prepare.sh} + # TODO inline prepare.sh? + fi + + . ${init.proxy} + + # Reset PATH because we need access to nixos-install. + # TODO provide nixos-install instead of relying on prepare.sh + export PATH="$OLD_PATH" + + # these variables get defined by nix-shell (i.e. nix-build) from + # XDG_RUNTIME_DIR and reference the wrong directory (/run/user/0), + # which only exists on / and not at /mnt. + export NIX_BUILD_TOP=/tmp + export TEMPDIR=/tmp + export TEMP=/tmp + export TMPDIR=/tmp + export TMP=/tmp + export XDG_RUNTIME_DIR=/tmp + + export NIXOS_CONFIG="$target_path/nixos-config" + + cd + exec nixos-install + ''; + # usage: test [--user=USER] --system=SYSTEM --target=TARGET cmds.test = pkgs.writeDash "cmds.test" /* sh */ '' set -efu @@ -193,6 +234,7 @@ let in pkgs.stdenv.mkDerivation { name = "stockholm"; shellHook = /* sh */ '' + export OLD_PATH="$PATH" export NIX_PATH=stockholm=$PWD:nixpkgs=${toString } export NIX_REMOTE=daemon export PATH=${lib.makeBinPath [ From 1375e1eb7c3dd90b1228d1ce583a6f2a8875a7e1 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 23 Jul 2017 22:48:58 +0200 Subject: [PATCH 3/8] Makefile: reimplement install using shell --- Makefile | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4258d9178..7b622126e 100644 --- a/Makefile +++ b/Makefile @@ -84,8 +84,9 @@ $(error No goals specified) endif # usage: make deploy system=foo [target=bar] +# usage: make install system=foo target=bar # usage: make test system=foo target=bar -deploy test: +deploy install test: ifdef target nix-shell --run '$@ --system=$(system) --target=$(target)' else @@ -112,15 +113,3 @@ pkgs.%:;@$(call build,$@) # usage: make LOGNAME=krebs system=wolf eval.config.krebs.build.host.name eval eval.:;@$(call evaluate,$${expr-eval}) eval.%:;@$(call evaluate,$@) - -# usage: make install system=foo [target_host=bar] -install: ssh ?= ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -install: - $(ssh) $(target_user)@$(target_host) -p $(target_port) \ - env target_path=$(target_path) \ - sh -s prepare < krebs/4lib/infest/prepare.sh - $(MAKE) populate target_path=/mnt$(target_path) - $(ssh) $(target_user)@$(target_host) -p $(target_port) \ - env NIXOS_CONFIG=$(target_path)/nixos-config \ - STOCKHOLM_VERSION="$$STOCKHOLM_VERSION" \ - nixos-install From e7678382514c6d8bd555be6721c8df91e2dec7cf Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 23 Jul 2017 23:25:37 +0200 Subject: [PATCH 4/8] infest prepare: sed NIX_PATH more lenient everywhere --- krebs/4lib/infest/prepare.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/krebs/4lib/infest/prepare.sh b/krebs/4lib/infest/prepare.sh index d39aca348..92e32a905 100644 --- a/krebs/4lib/infest/prepare.sh +++ b/krebs/4lib/infest/prepare.sh @@ -217,7 +217,7 @@ prepare_common() {( mkdir -p bin rm -f bin/nixos-install cp "$(type -p nixos-install)" bin/nixos-install - sed -i "s@^NIX_PATH=\"[^\"]*\"@NIX_PATH=$target_path@" bin/nixos-install + sed -i "s@NIX_PATH=\"[^\"]*\"@NIX_PATH=$target_path@" bin/nixos-install if ! grep -q '^PATH.*#krebs' .bashrc; then echo '. /root/.nix-profile/etc/profile.d/nix.sh' >> .bashrc From 05eb415beac2c27530d71d9db56b6af199e2fbb0 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 23 Jul 2017 23:36:25 +0200 Subject: [PATCH 5/8] infest prepare nix: 1.10 -> 1.11.13 --- krebs/4lib/infest/prepare.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/krebs/4lib/infest/prepare.sh b/krebs/4lib/infest/prepare.sh index 92e32a905..a16903db4 100644 --- a/krebs/4lib/infest/prepare.sh +++ b/krebs/4lib/infest/prepare.sh @@ -1,8 +1,8 @@ #! /bin/sh set -efu -nix_url=https://nixos.org/releases/nix/nix-1.10/nix-1.10-x86_64-linux.tar.bz2 -nix_sha256=504f7a3a85fceffb8766ae5e1005de9e02e489742f5a63cc3e7552120b138bf4 +nix_url=https://nixos.org/releases/nix/nix-1.11.13/nix-1.11.13-x86_64-linux.tar.bz2 +nix_sha256=c11411d52d8ad1ce3a68410015487282fd4651d3abefbbb13fa1f7803a2f60de prepare() {( if test -e /etc/os-release; then From a1cdec85d6fd4c296d98673473623a1c847a1ec2 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 24 Jul 2017 00:05:31 +0200 Subject: [PATCH 6/8] shell: set NIX_REMOTE only if daemon-socket exists --- shell.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index fce8eaa78..fda48a1a7 100644 --- a/shell.nix +++ b/shell.nix @@ -236,7 +236,9 @@ in pkgs.stdenv.mkDerivation { shellHook = /* sh */ '' export OLD_PATH="$PATH" export NIX_PATH=stockholm=$PWD:nixpkgs=${toString } - export NIX_REMOTE=daemon + if test -e /nix/var/nix/daemon-socket/socket; then + export NIX_REMOTE=daemon + fi export PATH=${lib.makeBinPath [ pkgs.populate shell.cmdspkg From c5fef87af8cba674198cd55ab1153d586db18080 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 25 Jul 2017 12:32:37 +0200 Subject: [PATCH 7/8] writeOut: don't modify stdenv's shell This fixes following (and maybe more) issues: - /nix/store/*-stdenv/setup: line 125: showBuildStats: unbound variable - /nix/store/*-stdenv/setup: line 69: !hookName: unbound variable --- krebs/5pkgs/writers.nix | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/krebs/5pkgs/writers.nix b/krebs/5pkgs/writers.nix index 49ca3557e..f1626078e 100644 --- a/krebs/5pkgs/writers.nix +++ b/krebs/5pkgs/writers.nix @@ -144,9 +144,14 @@ with import ; env = filevars // { passAsFile = attrNames filevars; }; in + # Use a subshell because 's genericBuild + # sources (or evaluates) the buildCommand and we don't want to modify its + # shell. In particular, exitHandler breaks in multiple ways with set -u. pkgs.runCommand name env /* sh */ '' - set -efu - ${concatMapStringsSep "\n" (getAttr "install") files} + ( + set -efu + ${concatMapStringsSep "\n" (getAttr "install") files} + ) ''; writeHaskell = From a15592411e0703180d36dbd8fd50503a6d8d33bb Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 25 Jul 2017 17:48:42 +0200 Subject: [PATCH 8/8] infest prepare: drop support for CentOS 6 --- krebs/4lib/infest/prepare.sh | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/krebs/4lib/infest/prepare.sh b/krebs/4lib/infest/prepare.sh index a16903db4..ccfc4f49b 100644 --- a/krebs/4lib/infest/prepare.sh +++ b/krebs/4lib/infest/prepare.sh @@ -14,10 +14,6 @@ prepare() {( ;; centos) case $VERSION_ID in - 6) - prepare_centos "$@" - exit - ;; 7) prepare_centos "$@" exit @@ -51,13 +47,6 @@ prepare() {( esac ;; esac - elif test -e /etc/centos-release; then - case $(cat /etc/centos-release) in - 'CentOS release 6.5 (Final)') - prepare_centos "$@" - exit - ;; - esac fi echo "$0 prepare: unknown OS" >&2 exit -1