krops/pkgs/krops/default.nix

89 lines
2.1 KiB
Nix
Raw Normal View History

let
2018-07-12 14:14:27 +02:00
lib = import ../../lib;
in
{ exec, nix, openssh, populate, writeDash }: rec {
2018-09-16 01:53:53 +02:00
build = target:
remoteCommand target (lib.concatStringsSep " " [
"nix build"
"-I ${lib.escapeShellArg target.path}"
"--no-link -f '<nixpkgs/nixos>'"
"config.system.build.toplevel"
]);
rebuild = args: target:
remoteCommand target "nixos-rebuild -I ${lib.escapeShellArg target.path} ${
lib.concatMapStringsSep " " lib.escapeShellArg args
}";
remoteCommand = target: command:
exec "build.${target.host}" rec {
2018-09-16 01:53:53 +02:00
filename = "${openssh}/bin/ssh";
argv = lib.flatten [
2018-09-16 01:53:53 +02:00
filename
(lib.optionals (target.user != "") ["-l" target.user])
2018-09-16 01:53:53 +02:00
"-p" target.port
"-t"
2018-09-16 01:53:53 +02:00
target.host
2019-12-02 11:31:02 +01:00
(if target.sudo then "sudo ${command}" else command)
2018-09-16 01:53:53 +02:00
];
};
2019-10-23 16:01:38 +02:00
writeCommand = name: {
command ? (targetPath: "echo ${targetPath}"),
backup ? false,
force ? false,
source,
target
}: let
target' = lib.mkTarget target;
in
writeDash name ''
set -efu
${populate { inherit backup force source; target = target'; }}
${remoteCommand target' (command target'.path)}
'';
2019-10-20 17:48:32 +02:00
writeDeploy = name: {
backup ? false,
fast ? false,
force ? false,
source,
target
}: let
target' = lib.mkTarget target;
in
writeDash name ''
set -efu
${populate { inherit backup force source; target = target'; }}
2019-10-20 17:48:32 +02:00
${lib.optionalString (! fast) ''
${rebuild ["dry-build"] target'}
${build target'}
''}
${rebuild ["switch"] target'}
'';
2019-10-20 17:48:32 +02:00
writeTest = name: {
backup ? false,
force ? false,
source,
target
}: let
target' = lib.mkTarget target;
in
assert lib.isLocalTarget target';
writeDash name ''
set -efu
${populate { inherit backup force source; target = target'; }} >&2
NIX_PATH=${lib.escapeShellArg target'.path} \
${nix}/bin/nix-build \
2018-09-13 20:14:33 +02:00
-A system \
2018-10-07 16:45:21 +02:00
--keep-going \
--no-out-link \
--show-trace \
2018-09-13 20:14:33 +02:00
'<nixpkgs/nixos>'
'';
}