From cca85f737e22b97ca77423eb8acf4f2e785066a0 Mon Sep 17 00:00:00 2001 From: Chris Toph Date: Mon, 21 Apr 2025 02:07:52 -0400 Subject: [PATCH] Refactor user home directory references to use config.hostSpec.home for consistency across configurations --- home/toph/common/core/default.nix | 12 ++++++--- home/toph/common/optional/gaming/switch.nix | 6 ++--- hosts/common/core/default.nix | 7 ++---- hosts/common/optional/system/pool.nix | 14 +++++++---- hosts/nixos/rune/hardware.nix | 28 +++++---------------- hosts/nixos/vm/hardware.nix | 26 +++---------------- hosts/users/default.nix | 2 +- hosts/users/toph/default.nix | 14 ++++++----- 8 files changed, 41 insertions(+), 68 deletions(-) diff --git a/home/toph/common/core/default.nix b/home/toph/common/core/default.nix index 6ee2dd7..f0b69d4 100644 --- a/home/toph/common/core/default.nix +++ b/home/toph/common/core/default.nix @@ -7,6 +7,10 @@ hostSpec, ... }: +let + username = config.hostSpec.username; + homeDir = config.hostSpec.home; +in { imports = lib.flatten [ (map lib.custom.relativeToRoot [ @@ -31,15 +35,15 @@ services.ssh-agent.enable = true; home = { - username = lib.mkDefault config.hostSpec.username; - homeDirectory = lib.mkDefault config.hostSpec.home; + username = lib.mkDefault username; + homeDirectory = lib.mkDefault homeDir; stateVersion = lib.mkDefault "24.05"; sessionPath = [ - "$HOME/.local/bin" + "${homeDir}/.local/bin" ]; sessionVariables = { EDITOR = "micro"; - FLAKE = "$HOME/git/dot.nix"; + FLAKE = "${homeDir}/git/dot.nix"; MANPAGER = "batman"; # see ./cli/bat.nix SHELL = "fish"; TERM = "foot"; diff --git a/home/toph/common/optional/gaming/switch.nix b/home/toph/common/optional/gaming/switch.nix index 6deaa25..11f00c3 100644 --- a/home/toph/common/optional/gaming/switch.nix +++ b/home/toph/common/optional/gaming/switch.nix @@ -14,7 +14,7 @@ let # inherit pkgs; # }; - user = config.hostSpec.username; + homeDir = config.hostSpec.home; borg-wrapper = pkgs.writeScript "borg-wrapper" '' #!${lib.getExe pkgs.fish} @@ -176,7 +176,7 @@ in name = "Ryujinx w/ Borg Backups"; comment = "Ryujinx Emulator with Borg Backups"; exec = mkLaunchCommand { - savePath = "/home/${user}/.config/Ryujinx/bis/user/save"; + savePath = "${homeDir}/.config/Ryujinx/bis/user/save"; backupPath = "/pool/Backups/Switch/RyubingSaves"; maxBackups = 30; command = "ryujinx"; @@ -206,7 +206,7 @@ in name = "Citron w/ Borg Backups"; comment = "Citron Emulator with Borg Backups"; exec = mkLaunchCommand { - savePath = "/home/${user}/.local/share/citron/nand/user/save"; + savePath = "${homeDir}/.local/share/citron/nand/user/save"; backupPath = "/pool/Backups/Switch/CitronSaves"; maxBackups = 30; command = "citron-emu"; diff --git a/hosts/common/core/default.nix b/hosts/common/core/default.nix index ed21537..53e1c9a 100644 --- a/hosts/common/core/default.nix +++ b/hosts/common/core/default.nix @@ -7,9 +7,6 @@ pkgs, ... }: -let - hostSpec = config.hostSpec; -in { imports = lib.flatten [ inputs.home-manager.nixosModules.home-manager @@ -60,7 +57,7 @@ in enable = true; clean.enable = true; clean.extraArgs = "--keep-since 20d --keep 20"; - flake = "/home/${hostSpec.username}/git/dot.nix/"; + flake = "${config.hostSpec.home}/git/dot.nix/"; }; ## SUDO and Terminal ## @@ -71,7 +68,7 @@ in security.sudo = { extraRules = [ { - users = [ hostSpec.username ]; + users = [ config.hostSpec.username ]; commands = [ { command = "ALL"; diff --git a/hosts/common/optional/system/pool.nix b/hosts/common/optional/system/pool.nix index a9840a6..a200893 100644 --- a/hosts/common/optional/system/pool.nix +++ b/hosts/common/optional/system/pool.nix @@ -1,29 +1,33 @@ { config, ... }: +let + username = config.hostSpec.username; + homeDir = config.hostSpec.home; +in { # For less permission issues with SSHFS programs.fuse.userAllowOther = true; # Create the directories if they do not exist systemd.tmpfiles.rules = [ - "d /pool 2775 ${config.hostSpec.username} ryot -" - "d /home/${config.hostSpec.username}/git 2775 ${config.hostSpec.username} ryot -" + "d /pool 2775 ${username} ryot -" + "d ${homeDir}/git 2775 ${username} ryot -" ]; # File system configuration fileSystems = { "/pool" = { - device = "${config.hostSpec.username}@cloud:/pool"; + device = "${username}@cloud:/pool"; fsType = "sshfs"; options = [ "defaults" "reconnect" "_netdev" "allow_other" - "identityfile=/home/${config.hostSpec.username}/.ssh/pve" + "identityfile=${homeDir}/.ssh/pve" ]; }; - "/home/${config.hostSpec.username}/git" = { + "${homeDir}/git" = { fsType = "none"; device = "/pool/git"; options = [ diff --git a/hosts/nixos/rune/hardware.nix b/hosts/nixos/rune/hardware.nix index 4aff2da..dc782cb 100644 --- a/hosts/nixos/rune/hardware.nix +++ b/hosts/nixos/rune/hardware.nix @@ -11,7 +11,12 @@ }: { - imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + imports = lib.flatten [ + (modulesPath + "/installer/scan/not-detected.nix") + (map lib.custom.relativeToRoot [ + "hosts/common/optional/system/pool.nix" + ]) + ]; ## Boot ## boot = { @@ -63,27 +68,6 @@ "dmask=0077" ]; }; - - "/pool" = { - device = "${config.hostSpec.username}@cloud:/pool"; - fsType = "sshfs"; - options = [ - "defaults" - "reconnect" - "_netdev" - "allow_other" - "identityfile=/home/${config.hostSpec.username}/.ssh/pve" - ]; - }; - - "/home/${config.hostSpec.username}/git" = { - fsType = "none"; - device = "/pool/git"; - options = [ - "bind" - "nofail" - ]; - }; }; swapDevices = [ { device = "/dev/disk/by-uuid/6586847d-eba9-4317-9077-98ae9b2812c9"; } ]; diff --git a/hosts/nixos/vm/hardware.nix b/hosts/nixos/vm/hardware.nix index d4c905b..9cd389e 100644 --- a/hosts/nixos/vm/hardware.nix +++ b/hosts/nixos/vm/hardware.nix @@ -9,8 +9,11 @@ let username = config.hostSpec.username; in { - imports = [ + imports = lib.flatten [ (modulesPath + "/profiles/qemu-guest.nix") + (map lib.custom.relativeToRoot [ + "hosts/common/optional/system/pool.nix" + ]) ]; ## Boot ## @@ -48,27 +51,6 @@ in device = "/dev/disk/by-uuid/7ec7d686-6f4c-482f-8b9d-4337a06afc48"; fsType = "ext4"; }; - - "/pool" = { - device = "${username}@cloud:/pool"; - fsType = "sshfs"; - options = [ - "defaults" - "reconnect" - "_netdev" - "allow_other" - "identityfile=/home/${username}/.ssh/pve" - ]; - }; - - "/home/${username}/git" = { - fsType = "none"; - device = "/pool/git"; - options = [ - "bind" - "nofail" - ]; - }; }; swapDevices = [ ]; diff --git a/hosts/users/default.nix b/hosts/users/default.nix index 9f77ef1..c3ec31d 100644 --- a/hosts/users/default.nix +++ b/hosts/users/default.nix @@ -20,7 +20,7 @@ in users.mutableUsers = false; # Only allow declarative credentials; Required for password to be set via sops during system activation! users.users.${hostSpec.username} = { - home = "/home/${hostSpec.username}"; + home = "${hostSpec.home}"; isNormalUser = true; createHome = true; description = "Admin"; diff --git a/hosts/users/toph/default.nix b/hosts/users/toph/default.nix index 43c69d9..8bde777 100644 --- a/hosts/users/toph/default.nix +++ b/hosts/users/toph/default.nix @@ -7,10 +7,12 @@ }: let hostSpec = config.hostSpec; + username = hostSpec.username; + homeDir = hostSpec.home; pubKeys = lib.filesystem.listFilesRecursive ./keys; in { - users.users.${hostSpec.username} = { + users.users.${username} = { name = hostSpec.username; shell = pkgs.fish; # default shell @@ -21,11 +23,11 @@ in # Create ssh sockets directory for controlpaths when homemanager not loaded (i.e. isMinimal) systemd.tmpfiles.rules = let - user = config.users.users.${hostSpec.username}.name; - group = config.users.users.${hostSpec.username}.group; + user = config.users.users.${username}.name; + group = config.users.users.${username}.group; in [ - "d /home/${hostSpec.username}/.ssh 0750 ${user} ${group} -" + "d ${homeDir}/.ssh 0750 ${user} ${group} -" ]; # No matter what environment we are in we want these tools @@ -38,11 +40,11 @@ in inherit pkgs inputs; hostSpec = config.hostSpec; }; - users.${hostSpec.username}.imports = lib.flatten ( + users.${username}.imports = lib.flatten ( lib.optional (!hostSpec.isMinimal) [ ( { config, ... }: - import (lib.custom.relativeToRoot "home/${hostSpec.username}/${hostSpec.hostName}") { + import (lib.custom.relativeToRoot "home/${username}/${hostSpec.hostName}") { inherit pkgs inputs