1
0
Fork 0
mirror of https://cgit.krebsco.de/krops synced 2024-11-26 21:19:47 +01:00

treewide: harmonize ssh calls

This commit is contained in:
tv 2020-06-08 23:11:36 +02:00
parent 1eb67a9b78
commit 44e8dd5cea
2 changed files with 16 additions and 17 deletions

View file

@ -5,7 +5,7 @@ in
{ nix, openssh, populate, writers }: rec { { nix, openssh, populate, writers }: rec {
build = target: build = target:
remoteCommand target (lib.concatStringsSep " " [ runShell target (lib.concatStringsSep " " [
"nix build" "nix build"
"-I ${lib.escapeShellArg target.path}" "-I ${lib.escapeShellArg target.path}"
"--no-link -f '<nixpkgs/nixos>'" "--no-link -f '<nixpkgs/nixos>'"
@ -13,11 +13,11 @@ in
]); ]);
rebuild = args: target: rebuild = args: target:
remoteCommand target "nixos-rebuild -I ${lib.escapeShellArg target.path} ${ runShell target "nixos-rebuild -I ${lib.escapeShellArg target.path} ${
lib.concatMapStringsSep " " lib.escapeShellArg args lib.concatMapStringsSep " " lib.escapeShellArg args
}"; }";
remoteCommand = target: command: runShell = target: command:
if lib.isLocalTarget target if lib.isLocalTarget target
then command then command
else else
@ -25,7 +25,7 @@ in
exec ${openssh}/bin/ssh ${lib.escapeShellArgs (lib.flatten [ exec ${openssh}/bin/ssh ${lib.escapeShellArgs (lib.flatten [
(lib.optionals (target.user != "") ["-l" target.user]) (lib.optionals (target.user != "") ["-l" target.user])
"-p" target.port "-p" target.port
"-t" "-T"
target.extraOptions target.extraOptions
target.host target.host
(if target.sudo then "sudo ${command}" else command)])} (if target.sudo then "sudo ${command}" else command)])}
@ -43,7 +43,7 @@ in
writers.writeDash name '' writers.writeDash name ''
set -efu set -efu
${populate { inherit backup force source; target = target'; }} ${populate { inherit backup force source; target = target'; }}
${remoteCommand target' (command target'.path)} ${runShell target' (command target'.path)}
''; '';
writeDeploy = name: { writeDeploy = name: {

View file

@ -6,7 +6,7 @@ with shell;
let let
check = { force, target }: let check = { force, target }: let
sentinelFile = "${target.path}/.populate"; sentinelFile = "${target.path}/.populate";
in shell' target /* sh */ '' in runShell target /* sh */ ''
${optionalString force /* sh */ '' ${optionalString force /* sh */ ''
mkdir -vp ${quote (dirOf sentinelFile)} >&2 mkdir -vp ${quote (dirOf sentinelFile)} >&2
touch ${quote sentinelFile} touch ${quote sentinelFile}
@ -23,7 +23,7 @@ let
do-backup = { target }: let do-backup = { target }: let
sentinelFile = "${target.path}/.populate"; sentinelFile = "${target.path}/.populate";
in in
shell' target /* sh */ '' runShell target /* sh */ ''
if ! test -d ${quote sentinelFile}; then if ! test -d ${quote sentinelFile}; then
>&2 printf 'error" sentinel file is not a directory: %s\n' ${quote ( >&2 printf 'error" sentinel file is not a directory: %s\n' ${quote (
optionalString (!isLocalTarget target) "${target.host}:" + optionalString (!isLocalTarget target) "${target.host}:" +
@ -40,7 +40,7 @@ let
${target.path}/.populate/backup/ ${target.path}/.populate/backup/
''; '';
pop.derivation = target: source: shell' target /* sh */ '' pop.derivation = target: source: runShell target /* sh */ ''
nix-build -E ${quote source.text} -o ${quote target.path} >&2 nix-build -E ${quote source.text} -o ${quote target.path} >&2
''; '';
@ -50,7 +50,7 @@ let
in in
rsync' target config (quote source.path); rsync' target config (quote source.path);
pop.git = target: source: shell' target /* sh */ '' pop.git = target: source: runShell target /* sh */ ''
set -efu set -efu
if ! test -e ${quote target.path}; then if ! test -e ${quote target.path}; then
git clone --recurse-submodules ${quote source.url} ${quote target.path} git clone --recurse-submodules ${quote source.url} ${quote target.path}
@ -92,7 +92,7 @@ let
if test -e ${quote source.dir}/.git; then if test -e ${quote source.dir}/.git; then
local_pass_info=${quote source.name}\ $(${git}/bin/git -C ${quote source.dir} log -1 --format=%H ${quote source.name}) local_pass_info=${quote source.name}\ $(${git}/bin/git -C ${quote source.dir} log -1 --format=%H ${quote source.name})
remote_pass_info=$(${shell' target /* sh */ '' remote_pass_info=$(${runShell target /* sh */ ''
cat ${quote target.path}/.pass_info || : cat ${quote target.path}/.pass_info || :
''}) ''})
@ -133,12 +133,12 @@ let
pop.pipe = target: source: /* sh */ '' pop.pipe = target: source: /* sh */ ''
${quote source.command} | { ${quote source.command} | {
${shell' target /* sh */ "cat > ${quote target.path}"} ${runShell target /* sh */ "cat > ${quote target.path}"}
} }
''; '';
# TODO rm -fR instead of ln -f? # TODO rm -fR instead of ln -f?
pop.symlink = target: source: shell' target /* sh */ '' pop.symlink = target: source: runShell target /* sh */ ''
ln -fnsT ${quote source.target} ${quote target.path} ln -fnsT ${quote source.target} ${quote target.path}
''; '';
@ -178,20 +178,19 @@ let
>&2 >&2
''; '';
shell' = target: script: runShell = target: command:
if isLocalTarget target if isLocalTarget target
then script then command
else else
if target.sudo then /* sh */ '' if target.sudo then /* sh */ ''
${ssh' target} ${quote target.host} ${quote "sudo bash -c ${quote script}"} ${ssh' target} ${quote target.host} ${quote "sudo bash -c ${quote command}"}
'' else '' '' else ''
${ssh' target} ${quote target.host} ${quote script} ${ssh' target} ${quote target.host} ${quote command}
''; '';
ssh' = target: concatMapStringsSep " " quote (flatten [ ssh' = target: concatMapStringsSep " " quote (flatten [
"${openssh}/bin/ssh" "${openssh}/bin/ssh"
(optionals (target.user != "") ["-l" target.user]) (optionals (target.user != "") ["-l" target.user])
"-o" "ControlPersist=no"
"-p" target.port "-p" target.port
"-T" "-T"
target.extraOptions target.extraOptions