From fc7d95acfd438081b4dc89c6e2b2909e70e11eaf Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Sat, 3 May 2025 12:40:20 +0800 Subject: [PATCH] refactor(modules): make username not hardcoded --- hosts/common.nix | 1 + modules/hm/default.nix | 7 ++++--- modules/hm/hardware.nix | 5 ++++- modules/nixos/default.nix | 6 ++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/hosts/common.nix b/hosts/common.nix index 1423679..4533ddf 100644 --- a/hosts/common.nix +++ b/hosts/common.nix @@ -17,6 +17,7 @@ ]; nixosModules.enable = true; nixosModules.hostname = hostname; + nixosModules.mainUser = "rafiq"; hmModules.enable = true; nix-config.enable = true; boot-config.enable = true; diff --git a/modules/hm/default.nix b/modules/hm/default.nix index bfdac62..5a79b01 100644 --- a/modules/hm/default.nix +++ b/modules/hm/default.nix @@ -8,6 +8,7 @@ let moduleName = "hmModules"; cfg = config."${moduleName}"; + username = config.nixosModules.mainUser; in { imports = [ @@ -26,9 +27,9 @@ in useGlobalPkgs = true; useUserPackages = true; extraSpecialArgs = specialArgs; - users.rafiq.home = { - username = "rafiq"; - homeDirectory = "/home/rafiq"; + users."${username}".home = { + username = username; + homeDirectory = "/home/${username}"; stateVersion = "25.05"; }; }; diff --git a/modules/hm/hardware.nix b/modules/hm/hardware.nix index c8a5ba5..476685a 100644 --- a/modules/hm/hardware.nix +++ b/modules/hm/hardware.nix @@ -3,10 +3,13 @@ lib, ... }: +let + username = config.nixosModules.mainUser; +in { config = lib.mkMerge [ (lib.mkIf config."hardware-config".usbAutoMount { - home-manager.users.rafiq.services.udiskie = { + home-manager.users.${username}.services.udiskie = { enable = true; settings = { # workaround for diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index bc619e3..09e679a 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -27,6 +27,12 @@ in example = "goron"; description = "The name this machine will be known by."; }; + mainUser = lib.mkOption { + type = lib.types.str; + default = ""; + example = "link"; + description = "The main user of pantheon."; + }; }; };