stockholm/lass/krops.nix

80 lines
2.1 KiB
Nix
Raw Normal View History

2018-09-07 15:55:22 +00:00
{ name }: let
2018-06-07 06:24:56 +00:00
inherit (import ../krebs/krops.nix { inherit name; })
2018-04-05 17:31:39 +00:00
krebs-source
lib
pkgs
;
source = { test }: lib.evalSource ([
(krebs-source { test = test; })
2018-04-05 17:31:39 +00:00
{
2018-05-12 13:53:04 +00:00
nixos-config.symlink = "stockholm/lass/1systems/${name}/physical.nix";
2020-01-11 20:03:08 +00:00
nixpkgs-unstable.git = {
2020-10-18 17:07:09 +00:00
url = "https://github.com/nixos/nixpkgs";
2020-01-11 20:03:08 +00:00
ref = (lib.importJSON ../krebs/nixpkgs-unstable.json).rev;
2020-10-18 17:07:09 +00:00
shallow = true;
2020-01-11 20:03:08 +00:00
};
2018-04-05 17:31:39 +00:00
secrets = if test then {
file = toString ./2configs/tests/dummy-secrets;
2018-04-05 17:31:39 +00:00
} else {
pass = {
2020-01-11 20:03:42 +00:00
dir = "${lib.getEnv "HOME"}/sync/pwstore";
2018-04-05 17:31:39 +00:00
name = "hosts/${name}";
};
};
2021-12-25 08:51:16 +00:00
stockholm.file = lib.mkForce {
path = toString ../.;
useChecksum = true;
};
2018-04-05 17:31:39 +00:00
}
2021-10-23 17:03:02 +00:00
(if lib.pathExists (./. + "/1systems/${name}/source.nix") then
2019-10-14 14:00:07 +00:00
import (./. + "/1systems/${name}/source.nix") { inherit lib pkgs test; }
else
{}
)
]);
2018-04-05 17:31:39 +00:00
in {
2018-11-20 00:16:22 +00:00
2022-06-21 21:39:33 +00:00
deploy = { target ? "root@${name}/var/src", offline ? false }: pkgs.krops.writeCommand "deploy" {
2021-10-26 19:00:22 +00:00
command = targetPath: ''
2022-06-21 21:39:33 +00:00
set -xfu
2021-10-26 19:00:22 +00:00
outDir=$(mktemp -d)
trap "rm -rf $outDir;" INT TERM EXIT
2022-06-21 21:39:33 +00:00
build=$(command -v nom-build || echo "nix-build")
$build \
2021-10-26 19:00:22 +00:00
-I "${targetPath}" \
2022-06-21 21:39:33 +00:00
'<nixpkgs/nixos>' -A config.system.build.toplevel \
-o "$outDir/out" \
${lib.optionalString offline "--option substitute false"} \
# -vvvvv --show-trace
2021-10-26 19:00:22 +00:00
nix-env -p /nix/var/nix/profiles/system --set "$outDir/out"
"$outDir/out/bin/switch-to-configuration" switch
2021-10-26 19:00:22 +00:00
'';
2018-04-05 17:31:39 +00:00
source = source { test = false; };
2021-10-26 19:00:22 +00:00
allocateTTY = true;
inherit target;
2018-04-05 17:31:39 +00:00
};
2018-11-20 00:16:22 +00:00
# usage: $(nix-build --no-out-link --argstr name HOSTNAME --argstr target PATH -A populate)
populate = { target, force ? false }: pkgs.populate {
inherit force;
source = source { test = false; };
target = lib.mkTarget target;
};
# usage: $(nix-build --no-out-link --argstr name HOSTNAME --argstr target PATH -A test)
test = { target }: pkgs.krops.writeTest "${name}-test" {
2018-10-09 11:48:52 +00:00
force = true;
inherit target;
2018-04-05 17:31:39 +00:00
source = source { test = true; };
2018-09-07 15:40:10 +00:00
};
2018-04-05 17:31:39 +00:00
}