-
Notifications
You must be signed in to change notification settings - Fork 0
/
flakeDeploy.nix
35 lines (30 loc) · 981 Bytes
/
flakeDeploy.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
self,
lib,
...
}: let
inherit (lib) escapeShellArgs filterAttrs mapAttrs' nameValuePair;
validConfigurations = filterAttrs (_: nixosSystem: nixosSystem._module.args ? deploy) self.nixosConfigurations;
mkDeploymentApp = self: name: deploy: pkgs: {
type = "app";
program = pkgs.writeShellApplication {
name = "deploy-${name}";
runtimeInputs = with pkgs; [
nixos-rebuild
];
text = ''
export NIX_SSHOPTS="-t"
goal="''${1:-switch}"
flake="${self}"
name="${name}"
targetHost="${deploy.targetHost}"
extraFlags=(${escapeShellArgs (deploy.extraFlags or [])})
nixos-rebuild "$goal" --flake "$flake#$name" --target-host "$targetHost" "''${extraFlags[@]}"
'';
};
};
in {
perSystem = {pkgs, ...}: {
apps = mapAttrs' (name: nixosSystem: nameValuePair "deploy-${name}" (mkDeploymentApp self name nixosSystem._module.args.deploy pkgs)) validConfigurations;
};
}