1# From https://github.com/khaneliman/khanelinix
2
3{
4 lib,
5 inputs,
6 namespace,
7}:
8let
9 inherit (inputs) deploy-rs;
10in
11{
12 ## Create deployment configuration for use with deploy-rs.
13 ##
14 ## ```nix
15 ## mkDeploy {
16 ## inherit self;
17 ## overrides = {
18 ## my-host.system.sudo = "doas -u";
19 ## };
20 ## }
21 ## ```
22 ##
23 #@ { self: Flake, overrides: Attrs ? {} } -> Attrs
24 mkDeploy =
25 {
26 self,
27 overrides ? { },
28 }:
29 let
30 hosts = self.nixosConfigurations or { };
31 names = builtins.attrNames hosts;
32 nodes = lib.foldl (
33 result: name:
34 let
35 host = hosts.${name};
36 user = host.config.${namespace}.user.name or null;
37 inherit (host.pkgs) system;
38 in
39 result
40 // {
41 ${name} = (overrides.${name} or { }) // {
42 hostname = overrides.${name}.hostname or "${name}";
43 profiles = (overrides.${name}.profiles or { }) // {
44 system =
45 (overrides.${name}.profiles.system or { })
46 // {
47 path = deploy-rs.lib.${system}.activate.nixos host;
48 sudo = "doas -u";
49 }
50 // lib.optionalAttrs (user != null) {
51 user = "root";
52 sshUser = user;
53 };
54 };
55 };
56 }
57 ) { } names;
58 in
59 {
60 inherit nodes;
61 };
62}