From 04d4ea7d68c1d951e45bff7696192f31c4d0eef7 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 23 Jul 2017 21:36:41 +0200 Subject: shell: split init.proxy off from init.env --- shell.nix | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) (limited to 'shell.nix') 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 ]} -- cgit v1.2.3 From 55bffc624a36fa9a6a58da68878ed969af763af8 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 23 Jul 2017 22:46:30 +0200 Subject: shell: add install command --- shell.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'shell.nix') 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 [ -- cgit v1.2.3 From a1cdec85d6fd4c296d98673473623a1c847a1ec2 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 24 Jul 2017 00:05:31 +0200 Subject: shell: set NIX_REMOTE only if daemon-socket exists --- shell.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shell.nix') 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 -- cgit v1.2.3 From 252d45d212ad0b67336636914a721eb08b5df1c3 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 27 Jul 2017 20:43:17 +0200 Subject: shell: add --force-populate flag --- shell.nix | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'shell.nix') diff --git a/shell.nix b/shell.nix index fda48a1a7..57690d398 100644 --- a/shell.nix +++ b/shell.nix @@ -6,7 +6,8 @@ let # high level commands # - # usage: deploy [--user=USER] --system=SYSTEM [--target=TARGET] + # usage: deploy [--force-populate] [--user=USER] + # --system=SYSTEM [--target=TARGET] cmds.deploy = pkgs.writeDash "cmds.deploy" '' set -efu @@ -20,7 +21,8 @@ let exec ${utils.deploy} ''; - # usage: install [--user=USER] --system=SYSTEM --target=TARGET + # usage: install [--force-populate] [--user=USER] + # --system=SYSTEM --target=TARGET cmds.install = pkgs.writeBash "cmds.install" '' set -efu @@ -61,7 +63,8 @@ let exec nixos-install ''; - # usage: test [--user=USER] --system=SYSTEM --target=TARGET + # usage: test [--force-populate] [--user=USER] + # --system=SYSTEM --target=TARGET cmds.test = pkgs.writeDash "cmds.test" /* sh */ '' set -efu @@ -142,11 +145,13 @@ let init.args = pkgs.writeText "init.args" /* sh */ '' args=$(${pkgs.utillinux}/bin/getopt -n "$command" -s sh \ -o s:t:u: \ - -l system:,target:,user: \ + -l force-populate,system:,target:,user: \ -- "$@") if \test $? != 0; then exit 1; fi eval set -- "$args" + force_populate=false; while :; do case $1 in + --force-populate) force_populate=true; shift;; -s|--system) system=$2; shift 2;; -t|--target) target=$2; shift 2;; -u|--user) user=$2; shift 2;; @@ -177,7 +182,11 @@ let 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 "$force_populate" = true; then + echo "$source" | populate --force "$qualified_target" + else + echo "$source" | populate "$qualified_target" + fi if \test "$target_local" != true; then exec ${pkgs.openssh}/bin/ssh \ -- cgit v1.2.3