blob: 8e512ac28c02daa5af4f5dcdffc76aeab937ad87 [file] [log] [blame]
Skyler Greyf08a6192024-06-01 23:55:20 +00001# SPDX-FileCopyrightText: 2024 Auxolotl Infrastructure Contributors
2# SPDX-FileCopyrightText: 2024 Clicks Codes
3#
4# SPDX-License-Identifier: GPL-3.0-only
5
6{ lib, inputs }:
7let
8 inherit (inputs) deploy-rs;
9in
Skyler Greyd083cf42024-06-08 23:10:24 +000010{
Skyler Greyf08a6192024-06-01 23:55:20 +000011 ## Create deployment configuration for use with deploy-rs.
12 ##
13 ## ```nix
14 ## mkDeploy {
15 ## inherit self;
16 ## overrides = {
17 ## my-host.system.sudo = "doas -u";
18 ## };
19 ## }
20 ## ```
21 ##
22 #@ { self: Flake, overrides: Attrs ? {} } -> Attrs
Skyler Greyd083cf42024-06-08 23:10:24 +000023 deploy = {
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.users.infra 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 }
49 // {
50 user = "root";
51 }
52 // lib.optionalAttrs host.config.clicks.security.doas.enable { sudo = "doas -u"; };
53 };
Skyler Greyf08a6192024-06-01 23:55:20 +000054 };
Skyler Greyd083cf42024-06-08 23:10:24 +000055 }
56 ) { } names;
57 in
58 {
59 inherit nodes;
60 };
61 };
Skyler Greyf08a6192024-06-01 23:55:20 +000062}