From 253b46eee078ebad26bea99a09c6e1ea9a1ddd53 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Mon, 7 Jul 2025 07:25:39 +0800 Subject: [PATCH 1/2] feat(hm): add sharedModules, move configurations.nix to hosts.nix --- nix/modules/home-manager.nix | 13 +++++++++---- nix/{configurations.nix => modules/hosts.nix} | 0 2 files changed, 9 insertions(+), 4 deletions(-) rename nix/{configurations.nix => modules/hosts.nix} (100%) diff --git a/nix/modules/home-manager.nix b/nix/modules/home-manager.nix index e81050f..2d6bf83 100644 --- a/nix/modules/home-manager.nix +++ b/nix/modules/home-manager.nix @@ -1,13 +1,18 @@ -{ inputs, ... }: +{ inputs, config, ... }: let + inherit (cfg.lib) flattenAttrs; + cfg = config.flake; hm = inputs.home-manager; globalCfg = { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; + useGlobalPkgs = true; + useUserPackages = true; + sharedModules = [ + (flattenAttrs (cfg.modules.homeManager or { })) + ]; }; in { imports = [ hm.flakeModules.home-manager ]; flake.modules.nixos.default.imports = [ hm.nixosModules.home-manager ]; - flake.modules.nixos.default.config = globalCfg; + flake.modules.nixos.default.config.home-manager = globalCfg; } diff --git a/nix/configurations.nix b/nix/modules/hosts.nix similarity index 100% rename from nix/configurations.nix rename to nix/modules/hosts.nix From de72f9a869183b1b214a94eb7b2ca496084fc004 Mon Sep 17 00:00:00 2001 From: Mohammad Rafiq Date: Mon, 7 Jul 2025 07:58:15 +0800 Subject: [PATCH 2/2] feat(nix): add system module, pass config to lib This commit introduces a system module for NixOS and Home Manager, and passes the configuration to the lib file. --- nix/lib/default.nix | 6 ++++-- nix/manifest.nix | 1 - nix/modules/system.nix | 10 ++++++++++ nix/modules/users.nix | 14 +++++++++++--- 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 nix/modules/system.nix diff --git a/nix/lib/default.nix b/nix/lib/default.nix index 710a658..b75aefc 100644 --- a/nix/lib/default.nix +++ b/nix/lib/default.nix @@ -1,9 +1,11 @@ -{ lib, ... }: +{ lib, config, ... }: let - inherit (lib.attrsets) concatMapAttrs; + cfg = config.flake; + inherit (lib.attrsets) mapAttrs concatMapAttrs; in { flake.lib = { flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset; + forAllUsers = f: mapAttrs f cfg.manifest.users; }; } diff --git a/nix/manifest.nix b/nix/manifest.nix index 5c46f9f..f3cd69c 100644 --- a/nix/manifest.nix +++ b/nix/manifest.nix @@ -8,7 +8,6 @@ let }; nixpkgs.hostPlatform = "x86_64-linux"; boot.loader.systemd-boot.enable = true; - system.stateVersion = "25.05"; networking = { inherit hostName; }; }; in diff --git a/nix/modules/system.nix b/nix/modules/system.nix new file mode 100644 index 0000000..c2af5c0 --- /dev/null +++ b/nix/modules/system.nix @@ -0,0 +1,10 @@ +{ + flake.modules.nixos.default = { + system.stateVersion = "25.11"; + }; + flake.modules.homeManager.default = + { osConfig, ... }: + { + home.stateVersion = osConfig.system.stateVersion; + }; +} diff --git a/nix/modules/users.nix b/nix/modules/users.nix index cfdeba5..6a423fd 100644 --- a/nix/modules/users.nix +++ b/nix/modules/users.nix @@ -1,12 +1,13 @@ { config, lib, ... }: let - inherit (config.flake.lib) flattenAttrs; + cfg = config.flake; + inherit (config.flake.lib) forAllUsers flattenAttrs; inherit (lib.attrsets) filterAttrs; - owner = flattenAttrs (filterAttrs (_: v: (v.primary or false)) config.flake.manifest.users); + owner = flattenAttrs (filterAttrs (_: v: (v.primary or false)) cfg.manifest.users); in { flake.modules.nixos.default = - { pkgs, ... }: + { pkgs, config, ... }: { #TODO: move sudo/security options elsewhere security.sudo.wheelNeedsPassword = false; @@ -26,5 +27,12 @@ in openssh.authorizedKeys.keys = [ owner.pubkey ]; }; }; + home-manager.users = forAllUsers ( + name: _: { + #TODO: move into nixos/darwin config - should not apply to homeConfigurations + home.username = name; + home.homeDirectory = config.users.users.${name}.home; + } + ); }; }