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
|
|
|
|
;
|
|
|
|
|
2019-03-26 13:39:52 +00:00
|
|
|
source = { test }: lib.evalSource ([
|
2018-11-28 20:30:46 +00:00
|
|
|
(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";
|
2023-06-19 00:16:17 +00:00
|
|
|
nixpkgs = lib.mkForce (if test then {
|
|
|
|
derivation = let
|
|
|
|
rev = (lib.importJSON ../krebs/nixpkgs-unstable.json).rev;
|
|
|
|
sha256 = (lib.importJSON ../krebs/nixpkgs-unstable.json).sha256;
|
|
|
|
in ''
|
|
|
|
with import (builtins.fetchTarball {
|
|
|
|
url = "https://github.com/nixos/nixpkgs/archive/${rev}.tar.gz";
|
|
|
|
sha256 = "${sha256}";
|
|
|
|
}) {};
|
|
|
|
pkgs.fetchFromGitHub {
|
|
|
|
owner = "nixos";
|
|
|
|
repo = "nixpkgs";
|
|
|
|
rev = "${rev}";
|
|
|
|
sha256 = "${sha256}";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
} else {
|
|
|
|
git = {
|
2023-07-15 15:04:58 +00:00
|
|
|
ref = (lib.importJSON ../krebs/nixpkgs-unstable.json).rev;
|
2023-06-19 00:16:17 +00:00
|
|
|
url = https://github.com/NixOS/nixpkgs;
|
|
|
|
shallow = true;
|
|
|
|
};
|
|
|
|
});
|
2018-04-05 17:31:39 +00:00
|
|
|
secrets = if test then {
|
2018-09-07 14:55:37 +00:00
|
|
|
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
|
|
|
|
2023-09-03 10:35:59 +00:00
|
|
|
deploy = { target ? "root@${name}/var/src", offline ? false, command ? "switch" }: 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
|
|
|
|
2021-12-15 08:14:44 +00:00
|
|
|
nix-env -p /nix/var/nix/profiles/system --set "$outDir/out"
|
|
|
|
|
2023-09-03 10:35:59 +00:00
|
|
|
"$outDir/out/bin/switch-to-configuration" ${command}
|
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;
|
2023-09-03 10:35:59 +00:00
|
|
|
backup = false;
|
|
|
|
inherit target;
|
|
|
|
};
|
|
|
|
|
|
|
|
deployWithFlake = { target ? "root@${name}/var/src", offline ? false }: pkgs.krops.writeCommand "deploy" {
|
|
|
|
source = {
|
|
|
|
inherit (source { test = false; }) stockholm secrets;
|
|
|
|
};
|
|
|
|
command = targetPath: ''
|
|
|
|
'';
|
|
|
|
allocateTTY = true;
|
2018-10-23 13:45:38 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2018-09-09 08:23:20 +00:00
|
|
|
# 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;
|
2018-09-09 08:23:20 +00:00
|
|
|
inherit target;
|
2018-04-05 17:31:39 +00:00
|
|
|
source = source { test = true; };
|
2018-09-07 15:40:10 +00:00
|
|
|
};
|
2023-09-03 10:35:59 +00:00
|
|
|
|
|
|
|
deploy-with-diff = { target ? "root@${name}/var/src" }: pkgs.krops.writeCommand "${name}-deploy" {
|
|
|
|
command = targetPath: ''
|
|
|
|
set -xu
|
|
|
|
deployScript=$(mktemp)
|
|
|
|
cat << EOF > "$deployScript"
|
|
|
|
#! /usr/bin/env nix-shell
|
|
|
|
#! nix-shell -p nix-diff proot rsync -i bash
|
|
|
|
set -xfu
|
|
|
|
|
|
|
|
oldPath=\$(echo "${targetPath}" | sed 's/-new$//')
|
|
|
|
oldSystemDrv=\$(nix show-derivation /run/current-system | jq -r 'keys[0]')
|
|
|
|
newSystemDrv=\$(proot -b /var/src-new:/var/src nix-instantiate -I /var/src '<nixpkgs/nixos>' -A config.system.build.toplevel)
|
|
|
|
|
|
|
|
(
|
|
|
|
diff -rq -x '.git' "\$oldPath" "${targetPath}"
|
|
|
|
nix-diff --color always --line-oriented "\$oldSystemDrv" "\$newSystemDrv"
|
|
|
|
) | less -R
|
|
|
|
echo 'continue? [(Y)es]/(n)o'
|
|
|
|
read yn
|
|
|
|
case \$yn in
|
|
|
|
[Nn]* ) exit;;
|
|
|
|
esac
|
|
|
|
rsync -ra --delete /var/src-new/ /var/src/
|
|
|
|
nixos-rebuild -I /var/src switch
|
|
|
|
EOF
|
|
|
|
|
|
|
|
chmod +x "$deployScript"
|
|
|
|
echo "$deployScript"
|
|
|
|
cat "$deployScript"
|
|
|
|
exec "$deployScript"
|
|
|
|
rm "$deployScript"
|
|
|
|
'';
|
|
|
|
target = "${target}-new";
|
|
|
|
source = source { test = false; };
|
|
|
|
force = true;
|
|
|
|
allocateTTY = true;
|
|
|
|
};
|
2018-04-05 17:31:39 +00:00
|
|
|
}
|