-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkrops.nix
81 lines (61 loc) · 2.29 KB
/
krops.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Full example:
# https://tech.ingolf-wagner.de/nixos/krops/
let
# Basic krops setup
krops = builtins.fetchGit { url = "https://cgit.krebsco.de/krops/"; };
lib = import "${krops}/lib";
pkgs = import "${krops}/pkgs" { };
source = name:
lib.evalSource [{
# Copy over the whole repo. By default nixos-rebuild will use the
# currents system hostname to lookup the right nixos configuration in
# `nixosConfigurations` from flake.nix
machine-config.file = toString ./.;
secrets.pass = {
dir = toString /home/emma/.local/share/password-store;
name = "${name}";
};
}];
command = targetPath: ''
nix-shell -p git --run '
nixos-rebuild switch -v --show-trace --flake ${targetPath}/machine-config || \
nixos-rebuild switch -v --show-trace --flake ${targetPath}/machine-config
'
'';
# Convenience function to define machines with connection parameters and
# configuration source
createHost = name: target:
pkgs.krops.writeCommand "deploy-${name}" {
inherit command;
source = source name;
target = target;
};
in rec {
# Define deployments
# Run with (e.g.):
# nix-build ./krops.nix -A all && ./result
# nix-build ./krops.nix -A desktop && ./result
# nix-build ./krops.nix -A servers && ./result
#
# nix-build ./krops.nix -A arm && ./result
# nix-build ./krops.nix -A majaArm && ./result
# nix-build ./krops.nix -A pi4b && ./result
# nix-build ./krops.nix -A laptop && ./result
# Individual machines
laptop = createHost "laptop" "root@laptop";
desktop = createHost "desktop" "root@desktop";
nix86 = createHost "nix86" "[email protected]";
arm = createHost "arm" "[email protected]";
majaArm = createHost "majaArm" "[email protected]";
rapaArm = createHost "rapaArm" "[email protected]";
olafArm = createHost "olafArm" "[email protected]";
pi4b = createHost "pi4b" "[email protected]";
pi4b2 = createHost "pi4b2" "[email protected]";
# Groups
all = pkgs.writeScript "deploy-all"
(lib.concatStringsSep "\n" [ laptop arm pi4b pi4b2 majaArm rapaArm ]);
desktops = pkgs.writeScript "deploy-desktops"
(lib.concatStringsSep "\n" [ laptop pi4b2 ]);
servers = pkgs.writeScript "deploy-servers"
(lib.concatStringsSep "\n" [ arm majaArm nix86 ]);
}