summaryrefslogtreecommitdiffstats
path: root/shell.nix
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2017-07-28 13:31:15 +0200
committermakefu <github@syntax-fehler.de>2017-07-28 13:31:15 +0200
commit44e521a5745807f4c19e7c56b9f4d0266f89b3e4 (patch)
tree11396e2c39d251ceb1018f34f2cc5a38bd722459 /shell.nix
parent421c27332a69708afd81a5fb07a28fdc93449338 (diff)
parente8148b62fdb39ed76361da5b7a6de88a8f800073 (diff)
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'shell.nix')
-rw-r--r--shell.nix114
1 files changed, 80 insertions, 34 deletions
diff --git a/shell.nix b/shell.nix
index 2973d4c51..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
@@ -15,11 +16,55 @@ let
\test -n "''${target-}" || target=$system
\test -n "''${user-}" || user=$LOGNAME
. ${init.env}
+ . ${init.proxy}
exec ${utils.deploy}
'';
- # usage: test [--user=USER] --system=SYSTEM --target=TARGET
+ # usage: install [--force-populate] [--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 [--force-populate] [--user=USER]
+ # --system=SYSTEM --target=TARGET
cmds.test = pkgs.writeDash "cmds.test" /* sh */ ''
set -efu
@@ -29,6 +74,7 @@ let
. ${init.args}
\test -n "''${user-}" || user=$LOGNAME
. ${init.env}
+ . ${init.proxy}
exec ${utils.build} config.system.build.toplevel
'';
@@ -99,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;;
@@ -114,9 +162,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 +174,35 @@ 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
+ 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 ${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
@@ -201,9 +243,13 @@ let
in pkgs.stdenv.mkDerivation {
name = "stockholm";
shellHook = /* sh */ ''
+ export OLD_PATH="$PATH"
export NIX_PATH=stockholm=$PWD:nixpkgs=${toString <nixpkgs>}
- 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
]}