shell: support --user

This commit is contained in:
tv 2017-07-13 23:39:48 +02:00
parent bc6c6a3164
commit c213968c44
2 changed files with 11 additions and 7 deletions

View File

@ -9,7 +9,7 @@ in
nixos-config.symlink = "stockholm/shared/1systems/${name}/config.nix"; nixos-config.symlink = "stockholm/shared/1systems/${name}/config.nix";
secrets.file = getAttr builder { secrets.file = getAttr builder {
buildbot = toString <stockholm/shared/6tests/data/secrets>; buildbot = toString <stockholm/shared/6tests/data/secrets>;
lass = "${getEnv "HOME"}/secrets/krebs/${host.name}"; shared = "${getEnv "HOME"}/secrets/krebs/${host.name}";
}; };
stockholm.file = toString <stockholm>; stockholm.file = toString <stockholm>;
nixpkgs.git = { nixpkgs.git = {

View File

@ -2,24 +2,26 @@ let
lib = import ./lib; lib = import ./lib;
pkgs = import <nixpkgs> { overlays = [(import ./krebs/5pkgs)]; }; pkgs = import <nixpkgs> { overlays = [(import ./krebs/5pkgs)]; };
# usage: deploy --system=SYSTEM [--target=TARGET] # usage: deploy [--user=USER] --system=SYSTEM [--target=TARGET]
cmds.deploy = pkgs.writeDash "cmds.deploy" '' cmds.deploy = pkgs.writeDash "cmds.deploy" ''
set -efu set -efu
command=deploy command=deploy
. ${init.args} . ${init.args}
\test -n "''${target-}" || target=$system \test -n "''${target-}" || target=$system
\test -n "''${user-}" || user=$LOGNAME
. ${init.env} . ${init.env}
exec ${utils.deploy} exec ${utils.deploy}
''; '';
# usage: test --system=SYSTEM --target=TARGET # usage: test [--user=USER] --system=SYSTEM --target=TARGET
cmds.test = pkgs.writeDash "cmds.test" /* sh */ '' cmds.test = pkgs.writeDash "cmds.test" /* sh */ ''
set -efu set -efu
command=test command=test
. ${init.args} . ${init.args}
\test -n "''${user-}" || user=$LOGNAME
. ${init.env} . ${init.env}
export dummy_secrets=true export dummy_secrets=true
@ -28,14 +30,15 @@ let
init.args = pkgs.writeText "init.args" /* sh */ '' init.args = pkgs.writeText "init.args" /* sh */ ''
args=$(${pkgs.utillinux}/bin/getopt -n "$command" -s sh \ args=$(${pkgs.utillinux}/bin/getopt -n "$command" -s sh \
-o s:t: \ -o s:t:u: \
-l system:,target: \ -l system:,target:,user: \
-- "$@") -- "$@")
if \test $? != 0; then exit 1; fi if \test $? != 0; then exit 1; fi
eval set -- "$args" eval set -- "$args"
while :; do case $1 in while :; do case $1 in
-s|--system) system=$2; shift 2;; -s|--system) system=$2; shift 2;;
-t|--target) target=$2; shift 2;; -t|--target) target=$2; shift 2;;
-u|--user) user=$2; shift 2;;
--) shift; break;; --) shift; break;;
esac; done esac; done
for arg; do echo "$command: bad argument: $arg" >&2; done for arg; do echo "$command: bad argument: $arg" >&2; done
@ -43,13 +46,14 @@ let
''; '';
init.env = pkgs.writeText "init.env" /* sh */ '' init.env = pkgs.writeText "init.env" /* sh */ ''
config=''${config-$LOGNAME/1systems/$system/config.nix} config=''${config-$user/1systems/$system/config.nix}
source=''${source-$LOGNAME/1systems/$system/source.nix} source=''${source-$user/1systems/$system/source.nix}
export config export config
export source export source
export system export system
export target export target
export user
export target_object="$(${init.env.parsetarget} $target)" export target_object="$(${init.env.parsetarget} $target)"
export target_user="$(echo $target_object | ${pkgs.jq}/bin/jq -r .user)" export target_user="$(echo $target_object | ${pkgs.jq}/bin/jq -r .user)"