Skyler Grey | f08a619 | 2024-06-01 23:55:20 +0000 | [diff] [blame] | 1 | # 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 }: |
| 7 | let |
| 8 | inherit (inputs) deploy-rs; |
| 9 | in |
| 10 | rec { |
| 11 | ## 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 |
| 23 | mkDeploy = |
| 24 | { |
| 25 | self, |
| 26 | overrides ? { }, |
| 27 | }: |
| 28 | let |
| 29 | hosts = self.nixosConfigurations or { }; |
| 30 | names = builtins.attrNames hosts; |
| 31 | nodes = lib.foldl ( |
| 32 | result: name: |
| 33 | let |
| 34 | host = hosts.${name}; |
| 35 | user = host.config.users.infra or null; |
| 36 | inherit (host.pkgs) system; |
| 37 | in |
| 38 | result |
| 39 | // { |
| 40 | ${name} = (overrides.${name} or { }) // { |
| 41 | hostname = overrides.${name}.hostname or "${name}"; |
| 42 | profiles = (overrides.${name}.profiles or { }) // { |
| 43 | system = |
| 44 | (overrides.${name}.profiles.system or { }) |
| 45 | // { |
| 46 | path = deploy-rs.lib.${system}.activate.nixos host; |
| 47 | } |
| 48 | // { |
| 49 | user = "root"; |
| 50 | } |
| 51 | // lib.optionalAttrs host.config.clicks.security.doas.enable { sudo = "doas -u"; }; |
| 52 | }; |
| 53 | }; |
| 54 | } |
| 55 | ) { } names; |
| 56 | in |
| 57 | { |
| 58 | inherit nodes; |
| 59 | }; |
| 60 | } |