From 4c8cd258c1b3f4b73278d90954ef10a950a95768 Mon Sep 17 00:00:00 2001 From: Mariano Uvalle Date: Thu, 7 Aug 2025 15:33:00 -0700 Subject: [PATCH] Introduce a "user" module that can be interpolated everywhere. Signed-off-by: Mariano Uvalle --- flake.nix | 5 +++-- hosts/msft-mac/configuration.nix | 15 ++++++++++----- hosts/msft-mac/home.nix | 31 ++++++++++++++++++------------- modules/common/default.nix | 5 +++++ modules/common/user-config.nix | 24 ++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 modules/common/default.nix create mode 100644 modules/common/user-config.nix diff --git a/flake.nix b/flake.nix index 0ea8c55..41b3cab 100644 --- a/flake.nix +++ b/flake.nix @@ -159,14 +159,15 @@ modules = [ ./hosts/msft-mac/configuration.nix home-manager.darwinModules.home-manager - { + ({ config, ... }: { home-manager.extraSpecialArgs = { pkgs-unstable = pkgs-unstable_aarch64-darwin; + inherit (config) user; }; home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; home-manager.users.jmug.imports = [ ./hosts/msft-mac/home.nix ]; - } + }) ]; }; }; diff --git a/hosts/msft-mac/configuration.nix b/hosts/msft-mac/configuration.nix index 720791f..cac66c8 100644 --- a/hosts/msft-mac/configuration.nix +++ b/hosts/msft-mac/configuration.nix @@ -1,10 +1,13 @@ -{ self, pkgs, ... }: { +{ self, pkgs, config, ... }: { - imports = [ ./hotkeys.nix ]; + imports = [ + ./hotkeys.nix + ../../modules/common + ]; # To reflect hotkeys without a login cycle. system.activationScripts.postActivation.text = '' - sudo -u jmug /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u + sudo -u ${config.user.name} /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u ''; # List packages installed in system profile. To search by name, run: @@ -14,7 +17,9 @@ git-credential-manager ]; - system.primaryUser = "jmug"; + user.name = "jmug"; + + system.primaryUser = config.user.name; homebrew = { enable = true; @@ -45,7 +50,7 @@ nerd-fonts.bigblue-terminal ]; - users.users.jmug.home = "/Users/jmug"; + users.users.${config.user.name}.home = config.user.homeDirectory; nixpkgs.config.allowUnfree = true; diff --git a/hosts/msft-mac/home.nix b/hosts/msft-mac/home.nix index 164a4a1..7c30986 100644 --- a/hosts/msft-mac/home.nix +++ b/hosts/msft-mac/home.nix @@ -2,8 +2,13 @@ config, pkgs, pkgs-unstable, + user, ... -} : { +} : +let + username = user.name; + homeDirectory = user.homeDirectory; +in { imports = [ ../../home-modules/default.nix @@ -28,8 +33,8 @@ }; home = { - username = "jmug"; - homeDirectory = "/Users/jmug"; + username = username; + homeDirectory = homeDirectory; packages = with pkgs; [ jq @@ -67,24 +72,24 @@ enable = true; extraConfig = '' Host * - IdentityAgent /Users/jmug/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh + IdentityAgent ${homeDirectory}/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh ''; }; programs.zsh = { shellAliases = { # TODO BEGIN Interpolate the name of the host here. - flakeconf = "nvim /Users/jmug/nixos/flake.nix"; - sysconf = "nvim /Users/jmug/nixos/hosts/macbook/configuration.nix"; - homeconf = "nvim /Users/jmug/nixos/hosts/macbook/home.nix"; - nvconf = "nvim /Users/jmug/nixos/home-modules/explicit-configs/nvim/init.lua"; + flakeconf = "nvim ${homeDirectory}/nixos/flake.nix"; + sysconf = "nvim ${homeDirectory}/nixos/hosts/macbook/configuration.nix"; + homeconf = "nvim ${homeDirectory}/nixos/hosts/macbook/home.nix"; + nvconf = "nvim ${homeDirectory}/nixos/home-modules/explicit-configs/nvim/init.lua"; # TODO: Interpolate the name of the host here. - rshellconf="source /Users/jmug/.zshrc"; - radev = "/Users/jmug/dev/aks-rp/bin/aksdev"; - ksc = "KUBECONFIG=/Users/jmug/Downloads/cxkubeconfig.yaml kubectl"; - kso = "KUBECONFIG=/Users/jmug/Downloads/overlaykubeconfig.yaml kubectl"; + rshellconf="source ${homeDirectory}/.zshrc"; + radev = "${homeDirectory}/dev/aks-rp/bin/aksdev"; + ksc = "KUBECONFIG=${homeDirectory}/Downloads/cxkubeconfig.yaml kubectl"; + kso = "KUBECONFIG=${homeDirectory}/Downloads/overlaykubeconfig.yaml kubectl"; k = "kubectl"; - nrsw = "sudo darwin-rebuild switch --flake /Users/jmug/nixos#msft-mac"; + nrsw = "sudo darwin-rebuild switch --flake ${homeDirectory}/nixos#msft-mac"; }; initExtra = '' export GONOPROXY='github.com,golang.org,googlesource.com,opentelemetry.io,uber.org' diff --git a/modules/common/default.nix b/modules/common/default.nix new file mode 100644 index 0000000..6cc450f --- /dev/null +++ b/modules/common/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./user-config.nix + ]; +} \ No newline at end of file diff --git a/modules/common/user-config.nix b/modules/common/user-config.nix new file mode 100644 index 0000000..5528be2 --- /dev/null +++ b/modules/common/user-config.nix @@ -0,0 +1,24 @@ +{ lib, pkgs, config, ... }: + +{ + options.user = lib.mkOption { + type = lib.types.submodule { + options = { + name = lib.mkOption { + type = lib.types.str; + description = "Primary username for the system"; + }; + + homeDirectory = lib.mkOption { + type = lib.types.str; + description = "Home directory path for the user"; + default = + if pkgs.stdenv.isDarwin + then "/Users/${config.user.name}" + else "/home/${config.user.name}"; + }; + }; + }; + description = "User configuration options"; + }; +}