Refactor user home directory references to use config.hostSpec.home for consistency across configurations

This commit is contained in:
Chris Toph 2025-04-21 02:07:52 -04:00
parent 2fd5d6df58
commit cca85f737e
8 changed files with 41 additions and 68 deletions

View file

@ -7,6 +7,10 @@
hostSpec, hostSpec,
... ...
}: }:
let
username = config.hostSpec.username;
homeDir = config.hostSpec.home;
in
{ {
imports = lib.flatten [ imports = lib.flatten [
(map lib.custom.relativeToRoot [ (map lib.custom.relativeToRoot [
@ -31,15 +35,15 @@
services.ssh-agent.enable = true; services.ssh-agent.enable = true;
home = { home = {
username = lib.mkDefault config.hostSpec.username; username = lib.mkDefault username;
homeDirectory = lib.mkDefault config.hostSpec.home; homeDirectory = lib.mkDefault homeDir;
stateVersion = lib.mkDefault "24.05"; stateVersion = lib.mkDefault "24.05";
sessionPath = [ sessionPath = [
"$HOME/.local/bin" "${homeDir}/.local/bin"
]; ];
sessionVariables = { sessionVariables = {
EDITOR = "micro"; EDITOR = "micro";
FLAKE = "$HOME/git/dot.nix"; FLAKE = "${homeDir}/git/dot.nix";
MANPAGER = "batman"; # see ./cli/bat.nix MANPAGER = "batman"; # see ./cli/bat.nix
SHELL = "fish"; SHELL = "fish";
TERM = "foot"; TERM = "foot";

View file

@ -14,7 +14,7 @@ let
# inherit pkgs; # inherit pkgs;
# }; # };
user = config.hostSpec.username; homeDir = config.hostSpec.home;
borg-wrapper = pkgs.writeScript "borg-wrapper" '' borg-wrapper = pkgs.writeScript "borg-wrapper" ''
#!${lib.getExe pkgs.fish} #!${lib.getExe pkgs.fish}
@ -176,7 +176,7 @@ in
name = "Ryujinx w/ Borg Backups"; name = "Ryujinx w/ Borg Backups";
comment = "Ryujinx Emulator with Borg Backups"; comment = "Ryujinx Emulator with Borg Backups";
exec = mkLaunchCommand { exec = mkLaunchCommand {
savePath = "/home/${user}/.config/Ryujinx/bis/user/save"; savePath = "${homeDir}/.config/Ryujinx/bis/user/save";
backupPath = "/pool/Backups/Switch/RyubingSaves"; backupPath = "/pool/Backups/Switch/RyubingSaves";
maxBackups = 30; maxBackups = 30;
command = "ryujinx"; command = "ryujinx";
@ -206,7 +206,7 @@ in
name = "Citron w/ Borg Backups"; name = "Citron w/ Borg Backups";
comment = "Citron Emulator with Borg Backups"; comment = "Citron Emulator with Borg Backups";
exec = mkLaunchCommand { exec = mkLaunchCommand {
savePath = "/home/${user}/.local/share/citron/nand/user/save"; savePath = "${homeDir}/.local/share/citron/nand/user/save";
backupPath = "/pool/Backups/Switch/CitronSaves"; backupPath = "/pool/Backups/Switch/CitronSaves";
maxBackups = 30; maxBackups = 30;
command = "citron-emu"; command = "citron-emu";

View file

@ -7,9 +7,6 @@
pkgs, pkgs,
... ...
}: }:
let
hostSpec = config.hostSpec;
in
{ {
imports = lib.flatten [ imports = lib.flatten [
inputs.home-manager.nixosModules.home-manager inputs.home-manager.nixosModules.home-manager
@ -60,7 +57,7 @@ in
enable = true; enable = true;
clean.enable = true; clean.enable = true;
clean.extraArgs = "--keep-since 20d --keep 20"; clean.extraArgs = "--keep-since 20d --keep 20";
flake = "/home/${hostSpec.username}/git/dot.nix/"; flake = "${config.hostSpec.home}/git/dot.nix/";
}; };
## SUDO and Terminal ## ## SUDO and Terminal ##
@ -71,7 +68,7 @@ in
security.sudo = { security.sudo = {
extraRules = [ extraRules = [
{ {
users = [ hostSpec.username ]; users = [ config.hostSpec.username ];
commands = [ commands = [
{ {
command = "ALL"; command = "ALL";

View file

@ -1,29 +1,33 @@
{ config, ... }: { config, ... }:
let
username = config.hostSpec.username;
homeDir = config.hostSpec.home;
in
{ {
# For less permission issues with SSHFS # For less permission issues with SSHFS
programs.fuse.userAllowOther = true; programs.fuse.userAllowOther = true;
# Create the directories if they do not exist # Create the directories if they do not exist
systemd.tmpfiles.rules = [ systemd.tmpfiles.rules = [
"d /pool 2775 ${config.hostSpec.username} ryot -" "d /pool 2775 ${username} ryot -"
"d /home/${config.hostSpec.username}/git 2775 ${config.hostSpec.username} ryot -" "d ${homeDir}/git 2775 ${username} ryot -"
]; ];
# File system configuration # File system configuration
fileSystems = { fileSystems = {
"/pool" = { "/pool" = {
device = "${config.hostSpec.username}@cloud:/pool"; device = "${username}@cloud:/pool";
fsType = "sshfs"; fsType = "sshfs";
options = [ options = [
"defaults" "defaults"
"reconnect" "reconnect"
"_netdev" "_netdev"
"allow_other" "allow_other"
"identityfile=/home/${config.hostSpec.username}/.ssh/pve" "identityfile=${homeDir}/.ssh/pve"
]; ];
}; };
"/home/${config.hostSpec.username}/git" = { "${homeDir}/git" = {
fsType = "none"; fsType = "none";
device = "/pool/git"; device = "/pool/git";
options = [ options = [

View file

@ -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 ##
boot = { boot = {
@ -63,27 +68,6 @@
"dmask=0077" "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"; } ]; swapDevices = [ { device = "/dev/disk/by-uuid/6586847d-eba9-4317-9077-98ae9b2812c9"; } ];

View file

@ -9,8 +9,11 @@ let
username = config.hostSpec.username; username = config.hostSpec.username;
in in
{ {
imports = [ imports = lib.flatten [
(modulesPath + "/profiles/qemu-guest.nix") (modulesPath + "/profiles/qemu-guest.nix")
(map lib.custom.relativeToRoot [
"hosts/common/optional/system/pool.nix"
])
]; ];
## Boot ## ## Boot ##
@ -48,27 +51,6 @@ in
device = "/dev/disk/by-uuid/7ec7d686-6f4c-482f-8b9d-4337a06afc48"; device = "/dev/disk/by-uuid/7ec7d686-6f4c-482f-8b9d-4337a06afc48";
fsType = "ext4"; 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 = [ ]; swapDevices = [ ];

View file

@ -20,7 +20,7 @@ in
users.mutableUsers = false; # Only allow declarative credentials; Required for password to be set via sops during system activation! users.mutableUsers = false; # Only allow declarative credentials; Required for password to be set via sops during system activation!
users.users.${hostSpec.username} = { users.users.${hostSpec.username} = {
home = "/home/${hostSpec.username}"; home = "${hostSpec.home}";
isNormalUser = true; isNormalUser = true;
createHome = true; createHome = true;
description = "Admin"; description = "Admin";

View file

@ -7,10 +7,12 @@
}: }:
let let
hostSpec = config.hostSpec; hostSpec = config.hostSpec;
username = hostSpec.username;
homeDir = hostSpec.home;
pubKeys = lib.filesystem.listFilesRecursive ./keys; pubKeys = lib.filesystem.listFilesRecursive ./keys;
in in
{ {
users.users.${hostSpec.username} = { users.users.${username} = {
name = hostSpec.username; name = hostSpec.username;
shell = pkgs.fish; # default shell shell = pkgs.fish; # default shell
@ -21,11 +23,11 @@ in
# Create ssh sockets directory for controlpaths when homemanager not loaded (i.e. isMinimal) # Create ssh sockets directory for controlpaths when homemanager not loaded (i.e. isMinimal)
systemd.tmpfiles.rules = systemd.tmpfiles.rules =
let let
user = config.users.users.${hostSpec.username}.name; user = config.users.users.${username}.name;
group = config.users.users.${hostSpec.username}.group; group = config.users.users.${username}.group;
in 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 # No matter what environment we are in we want these tools
@ -38,11 +40,11 @@ in
inherit pkgs inputs; inherit pkgs inputs;
hostSpec = config.hostSpec; hostSpec = config.hostSpec;
}; };
users.${hostSpec.username}.imports = lib.flatten ( users.${username}.imports = lib.flatten (
lib.optional (!hostSpec.isMinimal) [ lib.optional (!hostSpec.isMinimal) [
( (
{ config, ... }: { config, ... }:
import (lib.custom.relativeToRoot "home/${hostSpec.username}/${hostSpec.hostName}") { import (lib.custom.relativeToRoot "home/${username}/${hostSpec.hostName}") {
inherit inherit
pkgs pkgs
inputs inputs