From e5b76515f15152619ecda3d28c8f5b0e793e5e97 Mon Sep 17 00:00:00 2001 From: alexion Date: Sat, 26 Sep 2026 23:43:45 -0400 Subject: [PATCH] refactor(nix): order let bindings --- .../nixos/modules/desktop/apps/firefox.nix | 2 +- .../desktop/session/hyprland/default.nix | 3 +- .../desktop/session/hyprland/hypridle.nix | 7 +- .../nixos/modules/desktop/session/waybar.nix | 3 +- .../modules/desktop/utilities/theming.nix | 2 +- configs/nixos/modules/network/ssh.nix | 136 ++++++++-------- configs/nixos/modules/services/copyparty.nix | 50 +++--- configs/nixos/modules/services/homepage.nix | 96 +++++------ .../nixos/modules/services/reverse-proxy.nix | 150 +++++++++--------- configs/nixos/modules/services/steamcmd.nix | 4 +- configs/nixos/modules/shell/fish/default.nix | 6 +- configs/nixos/modules/shell/pi/default.nix | 4 +- configs/nixos/modules/shell/rust.nix | 2 +- configs/nixos/registry/stable-uid.nix | 13 +- src/dotfiles/guests.nix | 12 +- src/dotfiles/hosts.nix | 4 +- 16 files changed, 245 insertions(+), 249 deletions(-) diff --git a/configs/nixos/modules/desktop/apps/firefox.nix b/configs/nixos/modules/desktop/apps/firefox.nix index 4693a03..e29035a 100644 --- a/configs/nixos/modules/desktop/apps/firefox.nix +++ b/configs/nixos/modules/desktop/apps/firefox.nix @@ -8,8 +8,8 @@ # Firefox as the desktop browser: stock mainline, hardened and de-monetized by policy. let cfg = config.modules.desktop.apps.firefox; # NOLINT(let_order) - user = config.user.name; firefoxAddons = inputs.firefox-addons.packages.${pkgs.stdenv.hostPlatform.system}; + user = config.user.name; in { options.modules.desktop.apps.firefox = { diff --git a/configs/nixos/modules/desktop/session/hyprland/default.nix b/configs/nixos/modules/desktop/session/hyprland/default.nix index cdb462a..7cc25db 100644 --- a/configs/nixos/modules/desktop/session/hyprland/default.nix +++ b/configs/nixos/modules/desktop/session/hyprland/default.nix @@ -7,7 +7,6 @@ # The Hyprland compositor. let cfg = config.modules.desktop.session.hyprland; # NOLINT(let_order) - user = config.user.name; cursor = config.stylix.cursor; # Numbered-workspace switch and move for 1..9, the operator's i3 muscle memory. @@ -16,6 +15,8 @@ let "$mod SHIFT, ${toString n}, movetoworkspace, ${toString n}" ]) (lib.range 1 9); + user = config.user.name; + # Flip the tiling strategy between the two built-in layouts, since neither a # dispatcher nor a keyword toggles it on its own. toggleLayout = pkgs.writeShellScript "hypr-toggle-layout" '' diff --git a/configs/nixos/modules/desktop/session/hyprland/hypridle.nix b/configs/nixos/modules/desktop/session/hyprland/hypridle.nix index e87b078..a77e501 100644 --- a/configs/nixos/modules/desktop/session/hyprland/hypridle.nix +++ b/configs/nixos/modules/desktop/session/hyprland/hypridle.nix @@ -7,14 +7,15 @@ # hypridle: idle-triggered locking and display power management. let cfg = config.modules.desktop.session.hyprland.hypridle; # NOLINT(let_order) + + # The guard drops the call when a locker is already up, so no idle trigger + # stacks a second hyprlock over the first. + lockCmd = "${pkgs.procps}/bin/pidof hyprlock || ${hyprlock}"; user = config.user.name; hyprctl = "${config.programs.hyprland.package}/bin/hyprctl"; hyprlock = "${config.home-manager.users.${user}.programs.hyprlock.package}/bin/hyprlock"; - # The guard drops the call when a locker is already up, so no idle trigger - # stacks a second hyprlock over the first. - lockCmd = "${pkgs.procps}/bin/pidof hyprlock || ${hyprlock}"; in { options.modules.desktop.session.hyprland.hypridle = { diff --git a/configs/nixos/modules/desktop/session/waybar.nix b/configs/nixos/modules/desktop/session/waybar.nix index d13ba8d..3015552 100644 --- a/configs/nixos/modules/desktop/session/waybar.nix +++ b/configs/nixos/modules/desktop/session/waybar.nix @@ -8,11 +8,12 @@ let cfg = config.modules.desktop.session.waybar; # NOLINT(let_order) vpnClient = config.modules.network.vpn-client; - user = config.user.name; # A Nerd Font Private-Use-Area codepoint as a literal character, decoded # through JSON so the glyph survives as bytes rather than an editor paste. g = code: builtins.fromJSON ''"\u${code}"''; + user = config.user.name; + sleepOffIcon = builtins.fromJSON ''"\udb81\udcb3"''; # Renders and toggles mako's do-not-disturb mode. diff --git a/configs/nixos/modules/desktop/utilities/theming.nix b/configs/nixos/modules/desktop/utilities/theming.nix index 2fb9f80..e1278fb 100644 --- a/configs/nixos/modules/desktop/utilities/theming.nix +++ b/configs/nixos/modules/desktop/utilities/theming.nix @@ -7,7 +7,6 @@ # Nord theming for the graphical layer, driven from one base16 scheme by Stylix. let cfg = config.modules.desktop.utilities.theming; # NOLINT(let_order) - user = config.user.name; # A single static Nord wallpaper, drawn as a vertical gradient across the # Polar Night shades so it needs no committed binary and no network fetch. @@ -16,6 +15,7 @@ let -size 2560x1440 gradient:'#2E3440'-'#3B4252' \ "$out" ''; + user = config.user.name; in { options.modules.desktop.utilities.theming.enable = diff --git a/configs/nixos/modules/network/ssh.nix b/configs/nixos/modules/network/ssh.nix index 1571352..4d7c2bb 100644 --- a/configs/nixos/modules/network/ssh.nix +++ b/configs/nixos/modules/network/ssh.nix @@ -7,32 +7,6 @@ # SSH on this machine, in both directions. let cfg = config.modules.network.ssh; # NOLINT(let_order) - user = config.user.name; - - inherit (lib) - concatLists - concatStringsSep - elem - filter - genAttrs - hasAttr - imap0 - listToAttrs - mapAttrs - mapAttrsToList - mkIf - mkMerge - mkOption - nameValuePair - optional - optionalAttrs - types - unique - ; - - hostKeySecret = type: "ssh-host-${type}-key"; - userKeySecret = "ssh-user-ed25519-key"; - targetType = types.submodule ( { name, ... }: { @@ -90,54 +64,18 @@ let } ); - keyWithoutComment = key: concatStringsSep " " (lib.take 2 (lib.splitString " " key)); - - targetNamesIn = names: filter (name: hasAttr name cfg.targets) names; - - workstationNames = targetNamesIn cfg.hosts.workstations; - serverNames = targetNamesIn cfg.hosts.servers; - - clientKeysFor = names: filter (key: key != null) (map (name: cfg.targets.${name}.clientKey) names); - - currentHost = config.networking.hostName; - isServer = elem currentHost cfg.hosts.servers; - isWorkstation = elem currentHost cfg.hosts.workstations; - defaultAuthorizedKeys = lib.flatten ( clientKeysFor workstationNames ++ optional isServer (clientKeysFor serverNames) ); - outboundTargetNames = - let - groupTargets = - if isServer then - [ "gitea" ] ++ cfg.hosts.servers - else if isWorkstation then - [ "gitea" ] ++ cfg.hosts.servers ++ cfg.hosts.workstations - else - [ "gitea" ]; - in - filter (name: name != currentHost) (targetNamesIn groupTargets); + clientKeysFor = names: filter (key: key != null) (map (name: cfg.targets.${name}.clientKey) names); - sshSettingsFor = - name: - let - target = cfg.targets.${name}; - in - { - header = "Host ${concatStringsSep " " target.aliases}"; - HostName = target.hostName; - User = target.user; - } - // optionalAttrs (target.port != 22) { Port = target.port; }; + workstationNames = targetNamesIn cfg.hosts.workstations; + targetNamesIn = names: filter (name: hasAttr name cfg.targets) names; - knownHostNamesFor = - target: - let - names = unique (target.aliases ++ [ target.hostName ]); - withPort = name: if target.port == 22 then name else "[${name}]:${toString target.port}"; - in - map withPort names; + isServer = elem currentHost cfg.hosts.servers; + currentHost = config.networking.hostName; + serverNames = targetNamesIn cfg.hosts.servers; knownHosts = listToAttrs ( concatLists ( @@ -153,6 +91,68 @@ let ) cfg.targets ) ); + knownHostNamesFor = + target: + let + withPort = name: if target.port == 22 then name else "[${name}]:${toString target.port}"; + names = unique (target.aliases ++ [ target.hostName ]); + in + map withPort names; + + keyWithoutComment = key: concatStringsSep " " (lib.take 2 (lib.splitString " " key)); + + sshSettingsFor = + name: + let + target = cfg.targets.${name}; + in + { + header = "Host ${concatStringsSep " " target.aliases}"; + HostName = target.hostName; + User = target.user; + } + // optionalAttrs (target.port != 22) { Port = target.port; }; + + outboundTargetNames = + let + groupTargets = + if isServer then + [ "gitea" ] ++ cfg.hosts.servers + else if isWorkstation then + [ "gitea" ] ++ cfg.hosts.servers ++ cfg.hosts.workstations + else + [ "gitea" ]; + in + filter (name: name != currentHost) (targetNamesIn groupTargets); + + isWorkstation = elem currentHost cfg.hosts.workstations; + + hostKeySecret = type: "ssh-host-${type}-key"; + user = config.user.name; + + inherit (lib) + concatLists + concatStringsSep + elem + filter + genAttrs + hasAttr + imap0 + listToAttrs + mapAttrs + mapAttrsToList + mkIf + mkMerge + mkOption + nameValuePair + optional + optionalAttrs + types + unique + ; + + userKeySecret = "ssh-user-ed25519-key"; + in { options.modules.network.ssh = { diff --git a/configs/nixos/modules/services/copyparty.nix b/configs/nixos/modules/services/copyparty.nix index 488ec45..25c1459 100644 --- a/configs/nixos/modules/services/copyparty.nix +++ b/configs/nixos/modules/services/copyparty.nix @@ -38,6 +38,31 @@ let }; }; + configScript = pkgs.writeShellScript "copyparty-config" '' + set -eu + + umask 077 + password="$(${pkgs.coreutils}/bin/tr -d '\n' < "$CREDENTIALS_DIRECTORY/password")" + + cat > /run/copyparty/copyparty.conf < /run/copyparty/copyparty.conf < 1) (serviceNamesByUid entries); serviceNamesByUid = entries: @@ -13,10 +10,6 @@ let groupBy (entry: toString entry.value) entries ); - duplicateUids = - entries: - filterAttrs (_uid: serviceNames: builtins.length serviceNames > 1) (serviceNamesByUid entries); - in { # Next stable UID: 20005 diff --git a/src/dotfiles/guests.nix b/src/dotfiles/guests.nix index 4085661..ba4cad9 100644 --- a/src/dotfiles/guests.nix +++ b/src/dotfiles/guests.nix @@ -8,6 +8,7 @@ util, }: let + files = util.collectNixFiles root; mkGuest = name: { config, lib, ... }: @@ -167,22 +168,22 @@ let config = lib.mkIf cfg.enable { assertions = let - hasDirectorySettings = 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 ); + hasOneSource = mount: (mount.directory != null) != (mount.file != null); fileMountsWithHostSettings = lib.attrNames ( lib.filterAttrs (_: mount: mount.file != null && hasDirectorySettings mount) cfg.mounts ); + hasDirectorySettings = mount: mount.owner != null || mount.group != null || mount.mode != null; directoryMountsWithPartialHostSettings = lib.attrNames ( lib.filterAttrs ( _: mount: mount.directory != null && hasDirectorySettings mount && !hasCompleteDirectorySettings mount ) cfg.mounts ); + hasCompleteDirectorySettings = + mount: mount.owner != null && mount.group != null && mount.mode != null; in [ { @@ -275,11 +276,10 @@ let }; }; - files = util.collectNixFiles root; + names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles); 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 { imports = files ++ map mkGuest names; diff --git a/src/dotfiles/hosts.nix b/src/dotfiles/hosts.nix index 09ff2dd..5ce6e53 100644 --- a/src/dotfiles/hosts.nix +++ b/src/dotfiles/hosts.nix @@ -9,6 +9,8 @@ registryModule, }: let + names = lib.attrNames directories; + directories = lib.filterAttrs (_name: type: type == "directory") (builtins.readDir root); mkHost = { root, @@ -36,7 +38,5 @@ let ]; }; - directories = lib.filterAttrs (_name: type: type == "directory") (builtins.readDir root); - names = lib.attrNames directories; in lib.genAttrs names (name: mkHost { inherit root name; }) -- 2.47.3