From e15ce7f16b4e79e70a6742369ee72d766d1838b7 Mon Sep 17 00:00:00 2001 From: alexion Date: Wed, 16 Sep 2026 00:16:08 -0400 Subject: [PATCH] style(nix): apply style fixes --- configs/nixos/guests/copyparty.nix | 47 ++++---- configs/nixos/guests/palworld.nix | 93 ++++++++-------- configs/nixos/hosts/neogaia/default.nix | 2 +- configs/nixos/hosts/neogaia/disk.nix | 2 +- configs/nixos/hosts/pikachu/disk.nix | 2 +- configs/nixos/hosts/zeus/default.nix | 5 +- configs/nixos/hosts/zeus/disk.nix | 2 +- .../nixos/modules/desktop/apps/alacritty.nix | 3 +- .../nixos/modules/desktop/apps/obsidian.nix | 3 +- .../nixos/modules/desktop/apps/vencord.nix | 3 +- .../desktop/session/hyprland/default.nix | 31 +++--- .../desktop/session/hyprland/hyprlock.nix | 3 +- .../nixos/modules/desktop/session/login.nix | 3 +- .../modules/desktop/utilities/clipboard.nix | 3 +- .../nixos/modules/desktop/utilities/osd.nix | 3 +- .../modules/desktop/utilities/recording.nix | 3 +- .../modules/desktop/utilities/screenshot.nix | 3 +- configs/nixos/modules/host.nix | 2 +- configs/nixos/modules/network/ssh.nix | 102 +++++++++--------- configs/nixos/modules/network/vlans.nix | 9 +- configs/nixos/modules/network/vpn-client.nix | 16 +-- .../nixos/modules/services/actualbudget.nix | 6 +- configs/nixos/modules/services/copyparty.nix | 20 ++-- .../nixos/modules/services/games/palworld.nix | 25 +++-- configs/nixos/modules/services/homepage.nix | 34 +++--- configs/nixos/modules/services/navidrome.nix | 2 +- .../nixos/modules/services/reverse-proxy.nix | 33 ++++-- configs/nixos/modules/shell/bazel.nix | 3 +- configs/nixos/modules/shell/fish/default.nix | 3 +- configs/nixos/modules/shell/herdr.nix | 3 +- configs/nixos/modules/shell/nvim/default.nix | 3 +- configs/nixos/modules/shell/pi/default.nix | 3 +- configs/nixos/modules/shell/python.nix | 3 +- configs/nixos/modules/shell/rust.nix | 3 +- configs/nixos/registry/route.nix | 6 +- configs/nixos/registry/stable-uid.nix | 6 +- flake.nix | 2 +- src/dotfiles/apps.nix | 30 +++--- src/dotfiles/guests.nix | 47 ++++---- src/dotfiles/hosts.nix | 11 +- src/dotfiles/registry.nix | 84 ++++++++++----- src/dotfiles/util.nix | 11 +- 42 files changed, 389 insertions(+), 289 deletions(-) diff --git a/configs/nixos/guests/copyparty.nix b/configs/nixos/guests/copyparty.nix index df3ceb5..63c57f3 100644 --- a/configs/nixos/guests/copyparty.nix +++ b/configs/nixos/guests/copyparty.nix @@ -109,31 +109,36 @@ in inherit (cfg.reverseProxy) trustedSources; }; volumes = lib.mapAttrs (_urlPath: volume: { - inherit (volume) path access flags readOnly; + inherit (volume) + path + access + flags + readOnly + ; }) cfg.volumes; }; - mounts = - { - ${cfg.stateDir} = { - directory = cfg.statePath; - owner = config.registry."stable-uid".${config.networking.hostName}.copyparty; - group = "storage"; - mode = "0770"; - }; - ${"/run/secrets/${cfg.passwordSecret}"} = { - file = config.sops.secrets.${cfg.passwordSecret}.path; - readOnly = true; - }; + mounts = { + ${cfg.stateDir} = { + directory = cfg.statePath; + owner = config.registry."stable-uid".${config.networking.hostName}.copyparty; + group = "storage"; + mode = "0770"; + }; + ${"/run/secrets/${cfg.passwordSecret}"} = { + file = config.sops.secrets.${cfg.passwordSecret}.path; + readOnly = true; + }; + } + // lib.mapAttrs' ( + _urlPath: volume: + lib.nameValuePair volume.path { + directory = volume.hostPath; + owner = "root"; + group = "storage"; + mode = "2770"; } - // lib.mapAttrs' (_urlPath: volume: - lib.nameValuePair volume.path { - directory = volume.hostPath; - owner = "root"; - group = "storage"; - mode = "2770"; - } - ) cfg.volumes; + ) cfg.volumes; limits = { memory = lib.mkDefault "2G"; cpu = lib.mkDefault "200%"; diff --git a/configs/nixos/guests/palworld.nix b/configs/nixos/guests/palworld.nix index 71bab38..9ae2208 100644 --- a/configs/nixos/guests/palworld.nix +++ b/configs/nixos/guests/palworld.nix @@ -88,43 +88,47 @@ in guests.palworld = { interior.modules.services.games.palworld = { enable = true; - inherit (cfg) serverName port publicIP autoStart; + inherit (cfg) + serverName + port + publicIP + autoStart + ; inherit steamDir installDir stateDir; passwordFile = "/run/secrets/${cfg.passwordSecret}"; adminPasswordFile = "/run/secrets/${cfg.adminPasswordSecret}"; }; - mounts = - { - ${steamDir} = { - directory = cfg.steamPath; - owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd; - group = "storage"; - mode = "0770"; - }; - ${installDir} = { - directory = cfg.installPath; - owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd; - group = "storage"; - mode = "0770"; - }; - ${stateDir} = { - directory = cfg.statePath; - owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd; - group = "storage"; - mode = "0770"; - }; - ${"/run/secrets/${cfg.passwordSecret}"} = { - file = config.sops.secrets.${cfg.passwordSecret}.path; - readOnly = true; - }; - } - // lib.optionalAttrs (cfg.adminPasswordSecret != cfg.passwordSecret) { - ${"/run/secrets/${cfg.adminPasswordSecret}"} = { - file = config.sops.secrets.${cfg.adminPasswordSecret}.path; - readOnly = true; - }; + mounts = { + ${steamDir} = { + directory = cfg.steamPath; + owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd; + group = "storage"; + mode = "0770"; }; + ${installDir} = { + directory = cfg.installPath; + owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd; + group = "storage"; + mode = "0770"; + }; + ${stateDir} = { + directory = cfg.statePath; + owner = config.registry."stable-uid".${config.networking.hostName}.steamcmd; + group = "storage"; + mode = "0770"; + }; + ${"/run/secrets/${cfg.passwordSecret}"} = { + file = config.sops.secrets.${cfg.passwordSecret}.path; + readOnly = true; + }; + } + // lib.optionalAttrs (cfg.adminPasswordSecret != cfg.passwordSecret) { + ${"/run/secrets/${cfg.adminPasswordSecret}"} = { + file = config.sops.secrets.${cfg.adminPasswordSecret}.path; + readOnly = true; + }; + }; limits = { memory = lib.mkDefault "8G"; @@ -133,20 +137,19 @@ in }; }; - sops.secrets = - { - ${cfg.passwordSecret} = { - owner = "root"; - group = "storage"; - mode = "0440"; - }; - } - // lib.optionalAttrs (cfg.adminPasswordSecret != cfg.passwordSecret) { - ${cfg.adminPasswordSecret} = { - owner = "root"; - group = "storage"; - mode = "0440"; - }; + sops.secrets = { + ${cfg.passwordSecret} = { + owner = "root"; + group = "storage"; + mode = "0440"; }; + } + // lib.optionalAttrs (cfg.adminPasswordSecret != cfg.passwordSecret) { + ${cfg.adminPasswordSecret} = { + owner = "root"; + group = "storage"; + mode = "0440"; + }; + }; }; } diff --git a/configs/nixos/hosts/neogaia/default.nix b/configs/nixos/hosts/neogaia/default.nix index 8dba7a4..ffcdcad 100644 --- a/configs/nixos/hosts/neogaia/default.nix +++ b/configs/nixos/hosts/neogaia/default.nix @@ -34,7 +34,7 @@ registry.shell-shortcut.neogaia = { vpn-on = "sudo systemctl start wireguard-wg-home.target"; - vpn-off = ''sudo systemctl stop 'wireguard-wg-home*.service' wireguard-wg-home.target''; + vpn-off = "sudo systemctl stop 'wireguard-wg-home*.service' wireguard-wg-home.target"; }; modules.monorepo.enable = true; diff --git a/configs/nixos/hosts/neogaia/disk.nix b/configs/nixos/hosts/neogaia/disk.nix index db83081..dbc6b72 100644 --- a/configs/nixos/hosts/neogaia/disk.nix +++ b/configs/nixos/hosts/neogaia/disk.nix @@ -1,4 +1,4 @@ -{ ... }: +_: # neogaia's disk layout for disko: one NVMe disk, GPT, with an EFI system # partition and a LUKS container holding btrfs subvolumes. # No swap partition, since swap is zram. diff --git a/configs/nixos/hosts/pikachu/disk.nix b/configs/nixos/hosts/pikachu/disk.nix index 8d6b5f6..a809674 100644 --- a/configs/nixos/hosts/pikachu/disk.nix +++ b/configs/nixos/hosts/pikachu/disk.nix @@ -1,4 +1,4 @@ -{ ... }: +_: # pikachu's install layout for disko: one NVMe boot disk with an EFI system partition and ext4 root. # The existing 8 TB ZFS mirror is imported by name and is never declared here. { diff --git a/configs/nixos/hosts/zeus/default.nix b/configs/nixos/hosts/zeus/default.nix index 4393bd2..8749a70 100644 --- a/configs/nixos/hosts/zeus/default.nix +++ b/configs/nixos/hosts/zeus/default.nix @@ -8,7 +8,10 @@ # Disk layout is in ./disk.nix. # `fileSystems` are derived from it, none declared here. { - imports = [ ./disk.nix ] ++ lib.optional (builtins.pathExists ./hardware-configuration.nix) ./hardware-configuration.nix; + imports = [ + ./disk.nix + ] + ++ lib.optional (builtins.pathExists ./hardware-configuration.nix) ./hardware-configuration.nix; nixpkgs.hostPlatform = "x86_64-linux"; diff --git a/configs/nixos/hosts/zeus/disk.nix b/configs/nixos/hosts/zeus/disk.nix index 975b72d..2d69e1a 100644 --- a/configs/nixos/hosts/zeus/disk.nix +++ b/configs/nixos/hosts/zeus/disk.nix @@ -1,4 +1,4 @@ -{ ... }: +_: # zeus's disk layout for disko: two NVMe disks with one EFI system partition # and two LUKS containers joined into one btrfs filesystem. # No swap partition, since swap is zram. diff --git a/configs/nixos/modules/desktop/apps/alacritty.nix b/configs/nixos/modules/desktop/apps/alacritty.nix index 589d498..785a71e 100644 --- a/configs/nixos/modules/desktop/apps/alacritty.nix +++ b/configs/nixos/modules/desktop/apps/alacritty.nix @@ -10,7 +10,8 @@ let user = config.user.name; in { - options.modules.desktop.apps.alacritty.enable = lib.mkEnableOption "Alacritty as the desktop terminal"; + options.modules.desktop.apps.alacritty.enable = + lib.mkEnableOption "Alacritty as the desktop terminal"; config = lib.mkIf cfg.enable { home-manager.users.${user}.home.packages = [ pkgs.alacritty ]; diff --git a/configs/nixos/modules/desktop/apps/obsidian.nix b/configs/nixos/modules/desktop/apps/obsidian.nix index 46b38da..38b0deb 100644 --- a/configs/nixos/modules/desktop/apps/obsidian.nix +++ b/configs/nixos/modules/desktop/apps/obsidian.nix @@ -10,7 +10,8 @@ let user = config.user.name; in { - options.modules.desktop.apps.obsidian.enable = lib.mkEnableOption "Obsidian as the desktop note-taking vault"; + options.modules.desktop.apps.obsidian.enable = + lib.mkEnableOption "Obsidian as the desktop note-taking vault"; config = lib.mkIf cfg.enable { home-manager.users.${user}.home.packages = [ pkgs.obsidian ]; diff --git a/configs/nixos/modules/desktop/apps/vencord.nix b/configs/nixos/modules/desktop/apps/vencord.nix index 1245967..53b6ecf 100644 --- a/configs/nixos/modules/desktop/apps/vencord.nix +++ b/configs/nixos/modules/desktop/apps/vencord.nix @@ -10,7 +10,8 @@ let user = config.user.name; in { - options.modules.desktop.apps.vencord.enable = lib.mkEnableOption "Vesktop, a Discord client with Vencord built in"; + options.modules.desktop.apps.vencord.enable = + lib.mkEnableOption "Vesktop, a Discord client with Vencord built in"; config = lib.mkIf cfg.enable { home-manager.users.${user}.home.packages = [ pkgs.vesktop ]; diff --git a/configs/nixos/modules/desktop/session/hyprland/default.nix b/configs/nixos/modules/desktop/session/hyprland/default.nix index 0105939..445f293 100644 --- a/configs/nixos/modules/desktop/session/hyprland/default.nix +++ b/configs/nixos/modules/desktop/session/hyprland/default.nix @@ -67,22 +67,21 @@ in # UWSM launches the session without the shell profile that would carry # them, so a variable the compositor or its children must see is set # here rather than through home-manager's sessionVariables. - env = - [ - # Chromium and Electron apps read this to select native Wayland; - # nixpkgs wrappers (Obsidian's included) gate their Wayland flags on - # it, so without it they run under XWayland and blur at this DPI. - "NIXOS_OZONE_WL,1" - ] - # Bibata ships XCursor only. - # The hyprcursor variables name the same theme, which Hyprland - # resolves through its XCursor fallback. - ++ lib.optionals (cursor != null) [ - "XCURSOR_THEME,${cursor.name}" - "XCURSOR_SIZE,${toString cursor.size}" - "HYPRCURSOR_THEME,${cursor.name}" - "HYPRCURSOR_SIZE,${toString cursor.size}" - ]; + env = [ + # Chromium and Electron apps read this to select native Wayland; + # nixpkgs wrappers (Obsidian's included) gate their Wayland flags on + # it, so without it they run under XWayland and blur at this DPI. + "NIXOS_OZONE_WL,1" + ] + # Bibata ships XCursor only. + # The hyprcursor variables name the same theme, which Hyprland + # resolves through its XCursor fallback. + ++ lib.optionals (cursor != null) [ + "XCURSOR_THEME,${cursor.name}" + "XCURSOR_SIZE,${toString cursor.size}" + "HYPRCURSOR_THEME,${cursor.name}" + "HYPRCURSOR_SIZE,${toString cursor.size}" + ]; input = { kb_layout = "us"; diff --git a/configs/nixos/modules/desktop/session/hyprland/hyprlock.nix b/configs/nixos/modules/desktop/session/hyprland/hyprlock.nix index c7e58ed..50a9782 100644 --- a/configs/nixos/modules/desktop/session/hyprland/hyprlock.nix +++ b/configs/nixos/modules/desktop/session/hyprland/hyprlock.nix @@ -45,7 +45,8 @@ let ''; in { - options.modules.desktop.session.hyprland.hyprlock.enable = lib.mkEnableOption "the hyprlock lock screen"; + options.modules.desktop.session.hyprland.hyprlock.enable = + lib.mkEnableOption "the hyprlock lock screen"; config = lib.mkIf cfg.enable { home-manager.users.${user} = { diff --git a/configs/nixos/modules/desktop/session/login.nix b/configs/nixos/modules/desktop/session/login.nix index ec9e4c5..d3f6cfd 100644 --- a/configs/nixos/modules/desktop/session/login.nix +++ b/configs/nixos/modules/desktop/session/login.nix @@ -10,7 +10,8 @@ let cfg = config.modules.desktop.session.login; in { - options.modules.desktop.session.login.enable = lib.mkEnableOption "greetd with the tuigreet text greeter"; + options.modules.desktop.session.login.enable = + lib.mkEnableOption "greetd with the tuigreet text greeter"; config = lib.mkIf cfg.enable { services.greetd = { diff --git a/configs/nixos/modules/desktop/utilities/clipboard.nix b/configs/nixos/modules/desktop/utilities/clipboard.nix index 4eae7af..612255f 100644 --- a/configs/nixos/modules/desktop/utilities/clipboard.nix +++ b/configs/nixos/modules/desktop/utilities/clipboard.nix @@ -25,7 +25,8 @@ let ''; in { - options.modules.desktop.utilities.clipboard.enable = lib.mkEnableOption "cliphist clipboard history"; + options.modules.desktop.utilities.clipboard.enable = + lib.mkEnableOption "cliphist clipboard history"; config = lib.mkIf cfg.enable { home-manager.users.${user} = { diff --git a/configs/nixos/modules/desktop/utilities/osd.nix b/configs/nixos/modules/desktop/utilities/osd.nix index 6e231eb..d6227c5 100644 --- a/configs/nixos/modules/desktop/utilities/osd.nix +++ b/configs/nixos/modules/desktop/utilities/osd.nix @@ -10,7 +10,8 @@ let user = config.user.name; in { - options.modules.desktop.utilities.osd.enable = lib.mkEnableOption "the SwayOSD volume and brightness popup"; + options.modules.desktop.utilities.osd.enable = + lib.mkEnableOption "the SwayOSD volume and brightness popup"; config = lib.mkIf cfg.enable { environment.systemPackages = [ pkgs.swayosd ]; diff --git a/configs/nixos/modules/desktop/utilities/recording.nix b/configs/nixos/modules/desktop/utilities/recording.nix index f35b2d3..7fa9ccc 100644 --- a/configs/nixos/modules/desktop/utilities/recording.nix +++ b/configs/nixos/modules/desktop/utilities/recording.nix @@ -41,7 +41,8 @@ let ''; in { - options.modules.desktop.utilities.recording.enable = lib.mkEnableOption "wf-recorder screen recording"; + options.modules.desktop.utilities.recording.enable = + lib.mkEnableOption "wf-recorder screen recording"; config = lib.mkIf cfg.enable { home-manager.users.${user} = { diff --git a/configs/nixos/modules/desktop/utilities/screenshot.nix b/configs/nixos/modules/desktop/utilities/screenshot.nix index 44134d7..ba18c98 100644 --- a/configs/nixos/modules/desktop/utilities/screenshot.nix +++ b/configs/nixos/modules/desktop/utilities/screenshot.nix @@ -32,7 +32,8 @@ let ''; in { - options.modules.desktop.utilities.screenshot.enable = lib.mkEnableOption "screenshots via grimblast and satty"; + options.modules.desktop.utilities.screenshot.enable = + lib.mkEnableOption "screenshots via grimblast and satty"; config = lib.mkIf cfg.enable { home-manager.users.${user} = { diff --git a/configs/nixos/modules/host.nix b/configs/nixos/modules/host.nix index db47d4d..ca4ce4d 100644 --- a/configs/nixos/modules/host.nix +++ b/configs/nixos/modules/host.nix @@ -5,7 +5,7 @@ }: let cfg = config.modules.host; - user = config.user; + inherit (config) user; hostSecrets = ../secrets + "/${config.networking.hostName}.yaml"; passwordSecret = "${user.name}-password"; in diff --git a/configs/nixos/modules/network/ssh.nix b/configs/nixos/modules/network/ssh.nix index 55d422e..45e8e75 100644 --- a/configs/nixos/modules/network/ssh.nix +++ b/configs/nixos/modules/network/ssh.nix @@ -104,8 +104,7 @@ let isWorkstation = elem currentHost cfg.hosts.workstations; defaultAuthorizedKeys = lib.flatten ( - clientKeysFor workstationNames - ++ optional isServer (clientKeysFor serverNames) + clientKeysFor workstationNames ++ optional isServer (clientKeysFor serverNames) ); outboundTargetNames = @@ -120,7 +119,8 @@ let in filter (name: name != currentHost) (targetNamesIn groupTargets); - sshSettingsFor = name: + sshSettingsFor = + name: let target = cfg.targets.${name}; in @@ -131,7 +131,8 @@ let } // optionalAttrs (target.port != 22) { Port = target.port; }; - knownHostNamesFor = target: + knownHostNamesFor = + target: let names = unique (target.aliases ++ [ target.hostName ]); withPort = name: if target.port == 22 then name else "[${name}]:${toString target.port}"; @@ -142,7 +143,8 @@ let concatLists ( mapAttrsToList ( targetName: target: - imap0 (i: key: + imap0 ( + i: key: nameValuePair "${targetName}-${toString i}" { hostNames = knownHostNamesFor target; publicKey = keyWithoutComment key; @@ -290,58 +292,56 @@ in }; }; - config = mkIf cfg.enable ( - mkMerge [ - { - services.openssh.enable = true; + config = mkIf cfg.enable (mkMerge [ + { + services.openssh.enable = true; - users.users.${user}.openssh.authorizedKeys.keys = - if cfg.authorizedKeys != null then - cfg.authorizedKeys - else - defaultAuthorizedKeys ++ cfg.extraAuthorizedKeys; + users.users.${user}.openssh.authorizedKeys.keys = + if cfg.authorizedKeys != null then + cfg.authorizedKeys + else + defaultAuthorizedKeys ++ cfg.extraAuthorizedKeys; - programs.ssh.knownHosts = knownHosts; + programs.ssh.knownHosts = knownHosts; - home-manager.users.${user}.programs.ssh = { - enable = true; - enableDefaultConfig = false; - settings = - mapAttrs (name: _: sshSettingsFor name) (genAttrs outboundTargetNames (name: name)) - // cfg.extraSettings; - }; - } + home-manager.users.${user}.programs.ssh = { + enable = true; + enableDefaultConfig = false; + settings = + mapAttrs (name: _: sshSettingsFor name) (genAttrs outboundTargetNames (name: name)) + // cfg.extraSettings; + }; + } - (mkIf cfg.hostKeys.restore { - assertions = [ - { - assertion = cfg.hostKeys.sopsFile != null; - message = "modules.network.ssh.hostKeys.restore requires modules.network.ssh.hostKeys.sopsFile to name the encrypted host keys."; - } - ]; + (mkIf cfg.hostKeys.restore { + assertions = [ + { + assertion = cfg.hostKeys.sopsFile != null; + message = "modules.network.ssh.hostKeys.restore requires modules.network.ssh.hostKeys.sopsFile to name the encrypted host keys."; + } + ]; - sops.secrets = genAttrs (map hostKeySecret cfg.hostKeys.types) (_: { - inherit (cfg.hostKeys) sopsFile; - mode = "0400"; - restartUnits = [ "sshd.service" ]; - }); + sops.secrets = genAttrs (map hostKeySecret cfg.hostKeys.types) (_: { + inherit (cfg.hostKeys) sopsFile; + mode = "0400"; + restartUnits = [ "sshd.service" ]; + }); - services.openssh.hostKeys = [ ]; - services.openssh.extraConfig = concatStringsSep "" ( - map (type: "HostKey ${config.sops.secrets.${hostKeySecret type}.path}\n") cfg.hostKeys.types - ); - }) + services.openssh.hostKeys = [ ]; + services.openssh.extraConfig = concatStringsSep "" ( + map (type: "HostKey ${config.sops.secrets.${hostKeySecret type}.path}\n") cfg.hostKeys.types + ); + }) - (mkIf (cfg.userKey.sopsFile != null) { - sops.secrets.${userKeySecret} = { - inherit (cfg.userKey) sopsFile; - mode = "0400"; - owner = user; - }; + (mkIf (cfg.userKey.sopsFile != null) { + sops.secrets.${userKeySecret} = { + inherit (cfg.userKey) sopsFile; + mode = "0400"; + owner = user; + }; - home-manager.users.${user}.programs.ssh.settings."*".IdentityFile = - config.sops.secrets.${userKeySecret}.path; - }) - ] - ); + home-manager.users.${user}.programs.ssh.settings."*".IdentityFile = + config.sops.secrets.${userKeySecret}.path; + }) + ]); } diff --git a/configs/nixos/modules/network/vlans.nix b/configs/nixos/modules/network/vlans.nix index dc79b05..c945821 100644 --- a/configs/nixos/modules/network/vlans.nix +++ b/configs/nixos/modules/network/vlans.nix @@ -75,10 +75,11 @@ in ]; # networkd owns these interfaces so NetworkManager does not contend for them. - networking.networkmanager.unmanaged = - [ "interface-name:${cfg.trunk}" ] - ++ map (id: "interface-name:${bridgeName id}") cfg.ids - ++ map (id: "interface-name:${vlanName id}") cfg.ids; + networking.networkmanager.unmanaged = [ + "interface-name:${cfg.trunk}" + ] + ++ map (id: "interface-name:${bridgeName id}") cfg.ids + ++ map (id: "interface-name:${vlanName id}") cfg.ids; systemd.network = { enable = true; diff --git a/configs/nixos/modules/network/vpn-client.nix b/configs/nixos/modules/network/vpn-client.nix index 0c7e562..495b95a 100644 --- a/configs/nixos/modules/network/vpn-client.nix +++ b/configs/nixos/modules/network/vpn-client.nix @@ -88,16 +88,18 @@ in networking.wireguard.interfaces.${cfg.interface} = { ips = [ cfg.address ]; - mtu = cfg.mtu; + inherit (cfg) mtu; privateKeyFile = config.sops.secrets.${cfg.privateKeySecret}.path; peers = [ - ({ - inherit (cfg.peer) publicKey endpoint allowedIPs; - } - // lib.optionalAttrs (cfg.peer.persistentKeepalive != null) { - inherit (cfg.peer) persistentKeepalive; - }) + ( + { + inherit (cfg.peer) publicKey endpoint allowedIPs; + } + // lib.optionalAttrs (cfg.peer.persistentKeepalive != null) { + inherit (cfg.peer) persistentKeepalive; + } + ) ]; }; }; diff --git a/configs/nixos/modules/services/actualbudget.nix b/configs/nixos/modules/services/actualbudget.nix index d8eae8e..73e7bdd 100644 --- a/configs/nixos/modules/services/actualbudget.nix +++ b/configs/nixos/modules/services/actualbudget.nix @@ -45,14 +45,14 @@ in users.users.${cfg.user} = { isSystemUser = true; uid = config.registry."stable-uid".${config.networking.hostName}.actualbudget; - group = cfg.group; + inherit (cfg) group; }; services.actual = { enable = true; openFirewall = true; - user = cfg.user; - group = cfg.group; + inherit (cfg) user; + inherit (cfg) group; settings = { inherit (cfg) port dataDir; }; diff --git a/configs/nixos/modules/services/copyparty.nix b/configs/nixos/modules/services/copyparty.nix index 38854c7..e1d0ce3 100644 --- a/configs/nixos/modules/services/copyparty.nix +++ b/configs/nixos/modules/services/copyparty.nix @@ -40,13 +40,16 @@ let renderAccess = permission: accounts: " ${permission}: ${lib.concatStringsSep ", " accounts}"; - hasFlag = name: flags: lib.any (flag: lib.hasPrefix "${name}:" flag || lib.hasPrefix "${name}=" flag) flags; + hasFlag = + name: flags: lib.any (flag: lib.hasPrefix "${name}:" flag || lib.hasPrefix "${name}=" flag) flags; - defaultPermissionFlags = flags: + defaultPermissionFlags = + flags: lib.optionals (!(hasFlag "chmod_d" flags)) [ "chmod_d: 2770" ] ++ lib.optionals (!(hasFlag "chmod_f" flags)) [ "chmod_f: 660" ]; - renderFlags = flags: lib.concatMapStringsSep "\n" (flag: " ${flag}") (flags ++ defaultPermissionFlags flags); + renderFlags = + flags: lib.concatMapStringsSep "\n" (flag: " ${flag}") (flags ++ defaultPermissionFlags flags); renderVolume = urlPath: volume: '' [${urlPath}] @@ -54,8 +57,8 @@ let accs: ${lib.concatStringsSep "\n" (lib.mapAttrsToList renderAccess volume.access)} ${lib.optionalString (volume.flags != [ ]) '' - flags: - ${renderFlags volume.flags} + flags: + ${renderFlags volume.flags} ''} ''; @@ -173,7 +176,7 @@ in users.users.${cfg.user} = { isSystemUser = true; uid = config.registry."stable-uid".${config.networking.hostName}.copyparty; - group = cfg.group; + inherit (cfg) group; home = cfg.stateDir; }; @@ -202,7 +205,10 @@ in PrivateTmp = true; ProtectSystem = "strict"; ProtectHome = true; - ReadWritePaths = [ cfg.stateDir ] ++ map (volume: volume.path) (lib.filter (volume: !volume.readOnly) (lib.attrValues cfg.volumes)); + ReadWritePaths = [ + cfg.stateDir + ] + ++ map (volume: volume.path) (lib.filter (volume: !volume.readOnly) (lib.attrValues cfg.volumes)); }; }; diff --git a/configs/nixos/modules/services/games/palworld.nix b/configs/nixos/modules/services/games/palworld.nix index 4e2fa66..3c04327 100644 --- a/configs/nixos/modules/services/games/palworld.nix +++ b/configs/nixos/modules/services/games/palworld.nix @@ -134,19 +134,18 @@ appId = 2394010; inherit (service) autoStart; executable = "${startScript}"; - arguments = - [ - "-useperfthreads" - "-NoAsyncLoadingThread" - "-UseMultithreadForDS" - "-port=${toString service.port}" - "-publicport=${toString service.port}" - "-servername=${service.serverName}" - "-players=${toString service.maxPlayers}" - ] - ++ lib.optional service.publicLobby "-publiclobby" - ++ lib.optionals (service.publicIP != null) [ "-publicip=${service.publicIP}" ] - ++ lib.optional service.rcon.enable "-rcon"; + arguments = [ + "-useperfthreads" + "-NoAsyncLoadingThread" + "-UseMultithreadForDS" + "-port=${toString service.port}" + "-publicport=${toString service.port}" + "-servername=${service.serverName}" + "-players=${toString service.maxPlayers}" + ] + ++ lib.optional service.publicLobby "-publiclobby" + ++ lib.optionals (service.publicIP != null) [ "-publicip=${service.publicIP}" ] + ++ lib.optional service.rcon.enable "-rcon"; udpPorts = [ service.port ]; tcpPorts = [ service.port ]; }; diff --git a/configs/nixos/modules/services/homepage.nix b/configs/nixos/modules/services/homepage.nix index 6386ebc..4017f88 100644 --- a/configs/nixos/modules/services/homepage.nix +++ b/configs/nixos/modules/services/homepage.nix @@ -7,7 +7,9 @@ let cfg = config.modules.services.homepage; - mkRegistryPath = registryName: host: entry: "registry.${registryName}.${host}.${entry}"; + mkRegistryPath = + registryName: host: entry: + "registry.${registryName}.${host}.${entry}"; homepageEntries = lib.concatLists ( lib.mapAttrsToList ( @@ -19,7 +21,8 @@ let ) registry.homepage ); - mkHref = item: + mkHref = + item: if item.homepage.href != null then item.homepage.href else if (item.composite.route or null) != null then @@ -32,7 +35,8 @@ let else throw "${mkRegistryPath "homepage" item.host item.entry} needs href or a matching route entry"; - mkServiceAttrs = item: + mkServiceAttrs = + item: lib.filterAttrs (_: value: value != null) { href = mkHref item; inherit (item.homepage) description icon; @@ -40,15 +44,15 @@ let sortedEntries = lib.sort (left: right: left.homepage.name < right.homepage.name) homepageEntries; - insertEntry = acc: item: + insertEntry = + acc: item: acc // { - ${item.homepage.tab} = (acc.${item.homepage.tab} or { }) - // { - ${item.homepage.section} = (acc.${item.homepage.tab}.${item.homepage.section} or [ ]) ++ [ - { ${item.homepage.name} = mkServiceAttrs item; } - ]; - }; + ${item.homepage.tab} = (acc.${item.homepage.tab} or { }) // { + ${item.homepage.section} = (acc.${item.homepage.tab}.${item.homepage.section} or [ ]) ++ [ + { ${item.homepage.name} = mkServiceAttrs item; } + ]; + }; }; entriesByTab = lib.foldl' insertEntry { } sortedEntries; @@ -80,13 +84,15 @@ let ]; }; - orderedSections = tab: sections: + orderedSections = + tab: sections: let sectionOrder = sectionOrderByTab.${tab} or [ ]; in sectionOrder ++ lib.filter (section: !lib.elem section sectionOrder) (lib.attrNames sections); - mkTab = tab: + mkTab = + tab: let sections = entriesByTab.${tab}; in @@ -148,7 +154,9 @@ in openFirewall = true; inherit (cfg) listenPort; environmentFiles = [ cfg.environmentFile ]; - allowedHosts = lib.concatStringsSep "," (if cfg.allowedHosts == null then derivedAllowedHosts else cfg.allowedHosts); + allowedHosts = lib.concatStringsSep "," ( + if cfg.allowedHosts == null then derivedAllowedHosts else cfg.allowedHosts + ); services = homepageServices; widgets = [ { diff --git a/configs/nixos/modules/services/navidrome.nix b/configs/nixos/modules/services/navidrome.nix index e5bba6c..9bcacaa 100644 --- a/configs/nixos/modules/services/navidrome.nix +++ b/configs/nixos/modules/services/navidrome.nix @@ -50,7 +50,7 @@ in user = "navidrome"; group = "storage"; openFirewall = true; - environmentFile = cfg.environmentFile; + inherit (cfg) environmentFile; settings = { Address = "0.0.0.0"; Port = 4533; diff --git a/configs/nixos/modules/services/reverse-proxy.nix b/configs/nixos/modules/services/reverse-proxy.nix index 3ca985a..8ce9fb4 100644 --- a/configs/nixos/modules/services/reverse-proxy.nix +++ b/configs/nixos/modules/services/reverse-proxy.nix @@ -7,15 +7,20 @@ let cfg = config.modules.services.reverse-proxy; - mkRegistryPath = registryName: host: entry: "registry.${registryName}.${host}.${entry}"; + mkRegistryPath = + registryName: host: entry: + "registry.${registryName}.${host}.${entry}"; mkBackend = address: port: "http://${address}:${toString port}"; - mkVirtualHost = host: entry: mode: + mkVirtualHost = + host: entry: mode: let compositeEntry = registry.join host entry; - route = compositeEntry.route; - address = compositeEntry.address or (throw "no matching entry in registry.address for ${mkRegistryPath "route" host entry}"); + inherit (compositeEntry) route; + address = + compositeEntry.address + or (throw "no matching entry in registry.address for ${mkRegistryPath "route" host entry}"); isHttp = mode == "http"; port = if isHttp then route.http.port else route.port; in @@ -63,7 +68,11 @@ let domain: virtualHosts: if lib.length virtualHosts > 1 then [ - "duplicate route domain ${domain} in ${lib.concatMapStringsSep " and " (virtualHost: mkRegistryPath virtualHost.registryName virtualHost.host virtualHost.entry) virtualHosts}" + "duplicate route domain ${domain} in ${ + lib.concatMapStringsSep " and " ( + virtualHost: mkRegistryPath virtualHost.registryName virtualHost.host virtualHost.entry + ) virtualHosts + }" ] else [ ] @@ -76,13 +85,21 @@ let else lib.listToAttrs generatedVirtualHostList; - mkUdpStream = host: entry: port: + mkUdpStream = + host: entry: port: let compositeEntry = registry.join host entry; - address = compositeEntry.address or (throw "no matching entry in registry.address for ${mkRegistryPath "route" host entry}"); + address = + compositeEntry.address + or (throw "no matching entry in registry.address for ${mkRegistryPath "route" host entry}"); in { - inherit host entry port address; + inherit + host + entry + port + address + ; }; generatedUdpStreams = lib.concatLists ( diff --git a/configs/nixos/modules/shell/bazel.nix b/configs/nixos/modules/shell/bazel.nix index b2db218..e984bec 100644 --- a/configs/nixos/modules/shell/bazel.nix +++ b/configs/nixos/modules/shell/bazel.nix @@ -10,7 +10,8 @@ let user = config.user.name; in { - options.modules.shell.bazel.enable = lib.mkEnableOption "Bazel for the primary user's shell environment"; + options.modules.shell.bazel.enable = + lib.mkEnableOption "Bazel for the primary user's shell environment"; config = lib.mkIf cfg.enable { home-manager.users.${user}.home.packages = [ pkgs.bazel ]; diff --git a/configs/nixos/modules/shell/fish/default.nix b/configs/nixos/modules/shell/fish/default.nix index 7808133..4f8ef12 100644 --- a/configs/nixos/modules/shell/fish/default.nix +++ b/configs/nixos/modules/shell/fish/default.nix @@ -107,8 +107,7 @@ in # Rendered by home-manager into ~/.config/fish/config.fish. interactiveShellInit = lib.concatStringsSep "\n" ( - (lib.mapAttrsToList exportEnvVar envVars) - ++ [ (builtins.readFile ./config.fish) ] + (lib.mapAttrsToList exportEnvVar envVars) ++ [ (builtins.readFile ./config.fish) ] ); }; }; diff --git a/configs/nixos/modules/shell/herdr.nix b/configs/nixos/modules/shell/herdr.nix index f8f12a1..b91e03c 100644 --- a/configs/nixos/modules/shell/herdr.nix +++ b/configs/nixos/modules/shell/herdr.nix @@ -10,7 +10,8 @@ let user = config.user.name; in { - options.modules.shell.herdr.enable = lib.mkEnableOption "Herdr, a terminal multiplexer for coding agents"; + options.modules.shell.herdr.enable = + lib.mkEnableOption "Herdr, a terminal multiplexer for coding agents"; config = lib.mkIf cfg.enable { registry.shell-shortcut.${config.networking.hostName}.hs = "herdr --session"; diff --git a/configs/nixos/modules/shell/nvim/default.nix b/configs/nixos/modules/shell/nvim/default.nix index ac1a1eb..8527d34 100644 --- a/configs/nixos/modules/shell/nvim/default.nix +++ b/configs/nixos/modules/shell/nvim/default.nix @@ -11,7 +11,8 @@ let user = config.user.name; in { - options.modules.shell.nvim.enable = lib.mkEnableOption "Neovim, configured declaratively via nixvim"; + options.modules.shell.nvim.enable = + lib.mkEnableOption "Neovim, configured declaratively via nixvim"; config = lib.mkIf cfg.enable { registry.shell-shortcut.${config.networking.hostName} = { diff --git a/configs/nixos/modules/shell/pi/default.nix b/configs/nixos/modules/shell/pi/default.nix index 2b1c74b..db1c3ca 100644 --- a/configs/nixos/modules/shell/pi/default.nix +++ b/configs/nixos/modules/shell/pi/default.nix @@ -18,8 +18,7 @@ let in { options.modules.shell.pi = { - enable = lib.mkEnableOption '' - Pi, a terminal coding agent, configured through home-manager''; + enable = lib.mkEnableOption "Pi, a terminal coding agent, configured through home-manager"; }; config = lib.mkIf cfg.enable { diff --git a/configs/nixos/modules/shell/python.nix b/configs/nixos/modules/shell/python.nix index a77471a..c1c5f43 100644 --- a/configs/nixos/modules/shell/python.nix +++ b/configs/nixos/modules/shell/python.nix @@ -10,7 +10,8 @@ let user = config.user.name; in { - options.modules.shell.python.enable = lib.mkEnableOption "Python tools for the primary user's shell environment"; + options.modules.shell.python.enable = + lib.mkEnableOption "Python tools for the primary user's shell environment"; config = lib.mkIf cfg.enable { registry.env-var.${config.networking.hostName}.PYTHON_TOOLCHAIN_ROOT = "${pkgs.python3}"; diff --git a/configs/nixos/modules/shell/rust.nix b/configs/nixos/modules/shell/rust.nix index 36c9c8d..0d12702 100644 --- a/configs/nixos/modules/shell/rust.nix +++ b/configs/nixos/modules/shell/rust.nix @@ -20,7 +20,8 @@ let }; in { - options.modules.shell.rust.enable = lib.mkEnableOption "Rust tools for the primary user's shell environment"; + options.modules.shell.rust.enable = + lib.mkEnableOption "Rust tools for the primary user's shell environment"; config = lib.mkIf cfg.enable { registry.env-var.${config.networking.hostName}.RUST_TOOLCHAIN_ROOT = "${toolchain}"; diff --git a/configs/nixos/registry/route.nix b/configs/nixos/registry/route.nix index 50d728c..65e7857 100644 --- a/configs/nixos/registry/route.nix +++ b/configs/nixos/registry/route.nix @@ -6,14 +6,16 @@ message = "Route domains must be unique."; } { - assertion = entries: + assertion = + entries: lib.registry.predicates.uniqueValue (entry: entry.value) ( lib.concatMap (entry: map (port: entry // { value = port; }) entry.value.udp.ports) entries ); message = "Route UDP ports must be unique."; } { - assertion = entries: lib.all (entry: entry.value.port == null || entry.value.http.port == null) entries; + assertion = + entries: lib.all (entry: entry.value.port == null || entry.value.http.port == null) entries; message = "Route entries must not set both port and http.port."; } ]; diff --git a/configs/nixos/registry/stable-uid.nix b/configs/nixos/registry/stable-uid.nix index 7d2b18b..7b155f3 100644 --- a/configs/nixos/registry/stable-uid.nix +++ b/configs/nixos/registry/stable-uid.nix @@ -7,12 +7,14 @@ let unique ; - serviceNamesByUid = entries: + serviceNamesByUid = + entries: mapAttrs (_uid: uidEntries: unique (map (entry: entry.entry) uidEntries)) ( groupBy (entry: toString entry.value) entries ); - duplicateUids = entries: + duplicateUids = + entries: filterAttrs (_uid: serviceNames: builtins.length serviceNames > 1) (serviceNamesByUid entries); in diff --git a/flake.nix b/flake.nix index 40bab76..fc2981b 100644 --- a/flake.nix +++ b/flake.nix @@ -78,7 +78,7 @@ { self, nixpkgs, ... }@inputs: import ./src/dotfiles { inherit inputs self; - lib = nixpkgs.lib; + inherit (nixpkgs) lib; root = ./configs/nixos; system = "x86_64-linux"; }; diff --git a/src/dotfiles/apps.nix b/src/dotfiles/apps.nix index 26a79c3..0d62fba 100644 --- a/src/dotfiles/apps.nix +++ b/src/dotfiles/apps.nix @@ -10,19 +10,21 @@ in { fix = { type = "app"; - program = lib.getExe (pkgs.writeShellApplication { - name = "fix"; - runtimeInputs = [ - formatter.config.build.wrapper - pkgs.statix - pkgs.deadnix - ]; - text = '' - treefmt - statix fix . - deadnix --edit --exclude configs/nixos/hosts/*/hardware-configuration.nix -- . - treefmt - ''; - }); + program = lib.getExe ( + pkgs.writeShellApplication { + name = "fix"; + runtimeInputs = [ + formatter.config.build.wrapper + pkgs.statix + pkgs.deadnix + ]; + text = '' + treefmt + statix fix . + deadnix --edit --exclude configs/nixos/hosts/*/hardware-configuration.nix -- . + treefmt + ''; + } + ); }; } diff --git a/src/dotfiles/guests.nix b/src/dotfiles/guests.nix index 5f8c50f..4085661 100644 --- a/src/dotfiles/guests.nix +++ b/src/dotfiles/guests.nix @@ -17,16 +17,13 @@ let directoryMounts = lib.filterAttrs (_: mount: mount.directory != null) cfg.mounts; directoryScript = lib.concatStringsSep "\n" ( - lib.mapAttrsToList ( - _: mount: - '' - ${config.system.path}/bin/install -d \ - ${lib.optionalString (mount.owner != null) "-o ${lib.escapeShellArg (toString mount.owner)}"} \ - ${lib.optionalString (mount.group != null) "-g ${lib.escapeShellArg mount.group}"} \ - ${lib.optionalString (mount.mode != null) "-m ${lib.escapeShellArg mount.mode}"} \ - ${lib.escapeShellArg mount.directory} - '' - ) directoryMounts + lib.mapAttrsToList (_: mount: '' + ${config.system.path}/bin/install -d \ + ${lib.optionalString (mount.owner != null) "-o ${lib.escapeShellArg (toString mount.owner)}"} \ + ${lib.optionalString (mount.group != null) "-g ${lib.escapeShellArg mount.group}"} \ + ${lib.optionalString (mount.mode != null) "-m ${lib.escapeShellArg mount.mode}"} \ + ${lib.escapeShellArg mount.directory} + '') directoryMounts ); in { @@ -171,14 +168,20 @@ let assertions = let hasDirectorySettings = mount: mount.owner != null || mount.group != null || mount.mode != null; - hasCompleteDirectorySettings = mount: mount.owner != null && mount.group != null && mount.mode != null; + hasCompleteDirectorySettings = + mount: mount.owner != null && mount.group != null && mount.mode != null; hasOneSource = mount: (mount.directory != null) != (mount.file != null); - mountsWithInvalidSource = lib.attrNames (lib.filterAttrs (_: mount: !hasOneSource mount) cfg.mounts); + mountsWithInvalidSource = lib.attrNames ( + lib.filterAttrs (_: mount: !hasOneSource mount) cfg.mounts + ); fileMountsWithHostSettings = lib.attrNames ( lib.filterAttrs (_: mount: mount.file != null && hasDirectorySettings mount) cfg.mounts ); directoryMountsWithPartialHostSettings = lib.attrNames ( - lib.filterAttrs (_: mount: mount.directory != null && hasDirectorySettings mount && !hasCompleteDirectorySettings mount) cfg.mounts + lib.filterAttrs ( + _: mount: + mount.directory != null && hasDirectorySettings mount && !hasCompleteDirectorySettings mount + ) cfg.mounts ); in [ @@ -203,20 +206,23 @@ let { assertion = lib.elem cfg.vlan config.modules.network.vlans.ids; message = '' - guests.${name}.vlan = ${toString cfg.vlan} is not among its host's modules.network.vlans.ids (${lib.concatMapStringsSep ", " toString config.modules.network.vlans.ids}). Declare the VLAN on the host or correct the guest's placement. + guests.${name}.vlan = ${toString cfg.vlan} is not among its host's modules.network.vlans.ids (${ + lib.concatMapStringsSep ", " toString config.modules.network.vlans.ids + }). Declare the VLAN on the host or correct the guest's placement. ''; } ]; - registry.address.${config.networking.hostName}.${name} = - lib.mkIf (cfg.address != null) cfg.address; + registry.address.${config.networking.hostName}.${name} = lib.mkIf (cfg.address != null) cfg.address; registry.route.${config.networking.hostName}.${name} = lib.mkIf cfg.reverseProxy.enable cfg.reverseProxy.route; systemd.services."container@${name}" = let - bridgeDevice = "sys-subsystem-net-devices-${lib.replaceStrings [ "-" ] [ "\\x2d" ] (util.bridgeName cfg.vlan)}.device"; + bridgeDevice = "sys-subsystem-net-devices-${ + lib.replaceStrings [ "-" ] [ "\\x2d" ] (util.bridgeName cfg.vlan) + }.device"; in { after = [ bridgeDevice ]; @@ -268,10 +274,11 @@ let }; }; }; -in -let + files = util.collectNixFiles root; - guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) (builtins.readDir root); + guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) ( + builtins.readDir root + ); names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles); in { diff --git a/src/dotfiles/hosts.nix b/src/dotfiles/hosts.nix index a25372d..09ff2dd 100644 --- a/src/dotfiles/hosts.nix +++ b/src/dotfiles/hosts.nix @@ -26,7 +26,8 @@ let guestModules # TODO: refactor - registryModule (root + "/${name}") + registryModule + (root + "/${name}") { networking.hostName = name; @@ -34,12 +35,8 @@ let } ]; }; -in -let + directories = lib.filterAttrs (_name: type: type == "directory") (builtins.readDir root); names = lib.attrNames directories; in -lib.genAttrs names ( - name: - mkHost { inherit root name; } -) +lib.genAttrs names (name: mkHost { inherit root name; }) diff --git a/src/dotfiles/registry.nix b/src/dotfiles/registry.nix index 67c7c05..4a9314b 100644 --- a/src/dotfiles/registry.nix +++ b/src/dotfiles/registry.nix @@ -1,4 +1,8 @@ -{ hosts, lib, root }: +{ + hosts, + lib, + root, +}: let checkType = lib.types.submodule { options = { @@ -19,7 +23,8 @@ let }; predicates = { - uniqueValue = value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries; + uniqueValue = + value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries; }; registryLib = lib // { @@ -57,15 +62,18 @@ let registryName = fileName: lib.removeSuffix ".nix" fileName; - registryOption = registry: lib.mkOption { - type = lib.types.attrsOf (lib.types.attrsOf registry.type); - default = { }; - description = '' - Lazily collected fleet-visible registry entries, nested by host and entry name. - ''; - }; + registryOption = + registry: + lib.mkOption { + type = lib.types.attrsOf (lib.types.attrsOf registry.type); + default = { }; + description = '' + Lazily collected fleet-visible registry entries, nested by host and entry name. + ''; + }; - mkRegistry = path: + mkRegistry = + path: let evaluated = lib.evalModules { specialArgs.lib = registryLib; @@ -79,15 +87,21 @@ let inherit (evaluated.config) type replicate checks; }; - definitions = lib.mapAttrs' ( - name: type: - let - path = root + "/${name}"; - in - lib.nameValuePair (registryName name) (mkRegistry path) - ) (lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root)); + definitions = + lib.mapAttrs' + ( + name: _type: + let + path = root + "/${name}"; + in + lib.nameValuePair (registryName name) (mkRegistry path) + ) + ( + lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root) + ); - flattenRegistryEntries = registryName: data: + flattenRegistryEntries = + registryName: data: lib.concatLists ( lib.mapAttrsToList ( host: entries: @@ -98,10 +112,12 @@ let ) data ); - rawDeclarations = registryName: hosts: + rawDeclarations = + registryName: hosts: lib.mapAttrs (_hostName: host: host.config.registry.${registryName} or { }) hosts; - replicatedEntries = registryName: raw: + replicatedEntries = + registryName: raw: let entries = lib.concatLists ( lib.concatLists ( @@ -126,18 +142,21 @@ let else throw "conflicting replicated registry entry ${entry.path} does not match ${acc.${entry.entryName}.path}" else - acc // { + acc + // { ${entry.entryName} = entry; } ) { } entries; - replicatedData = registryName: hosts: raw: + replicatedData = + registryName: hosts: raw: let entries = lib.mapAttrs (_entryName: entry: entry.value) (replicatedEntries registryName raw); in lib.mapAttrs (_hostName: _host: entries) hosts; - validationAssertions = data: + validationAssertions = + data: lib.concatLists ( lib.mapAttrsToList ( registryName: registry: @@ -151,7 +170,8 @@ let ) definitions ); - assertValid = data: + assertValid = + data: let assertions = validationAssertions data; failures = lib.filter (assertion: !assertion.assertion) assertions; @@ -161,9 +181,12 @@ let ); data; - join = registry: host: entry: + join = + registry: host: entry: lib.filterAttrs (_name: value: value != null) ( - lib.mapAttrs (registryName: _registry: (registry.${registryName}.${host} or { }).${entry} or null) definitions + lib.mapAttrs ( + registryName: _registry: (registry.${registryName}.${host} or { }).${entry} or null + ) definitions ); collectData = @@ -180,7 +203,8 @@ let in assertValid data; - withOperations = registry: + withOperations = + registry: registry // { join = host: entry: join registry host entry; @@ -190,8 +214,10 @@ in types = lib.mapAttrs (_name: definition: definition.type) definitions; module = { - options.registry = lib.mapAttrs (_name: registry: registryOption registry) definitions; + options.registry = lib.mapAttrs (_name: registryOption) definitions; }; - collected = withOperations (collectData { inherit hosts; }); + collected = withOperations (collectData { + inherit hosts; + }); } diff --git a/src/dotfiles/util.nix b/src/dotfiles/util.nix index 66c1018..99e1ac2 100644 --- a/src/dotfiles/util.nix +++ b/src/dotfiles/util.nix @@ -28,5 +28,14 @@ in hash = builtins.hashString "sha256" name; octet = i: builtins.substring (i * 2) 2 hash; in - lib.concatStringsSep ":" ([ "02" ] ++ map octet [ 0 1 2 3 4 ]); + lib.concatStringsSep ":" ( + [ "02" ] + ++ map octet [ + 0 + 1 + 2 + 3 + 4 + ] + ); } -- 2.47.3