From c7ce343d9bf1a329056a4dd5b32ea8cc43b55e15 Mon Sep 17 00:00:00 2001 From: GrizzlT <13691001+GrizzlT@users.noreply.github.com> Date: Wed, 24 Jan 2024 11:30:39 +0100 Subject: [PATCH] home-manager: add extendModules attribute The `home-manager.lib.homeManagerConfiguration` function now has an additional attribute that can be used to extend a Home Manager configuration with additional modules outside the project tree. It works similar to the result of `lib.nixosSystem` from Nixpkgs --- modules/default.nix | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/modules/default.nix b/modules/default.nix index ba43fec5c..ad0e67646 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -28,28 +28,34 @@ let specialArgs = { modulesPath = builtins.toString ./.; } // extraSpecialArgs; }; - module = showWarnings (let - failed = collectFailed rawModule.config; - failedStr = concatStringsSep "\n" (map (x: "- ${x}") failed); - in if failed == [ ] then - rawModule - else - throw '' + moduleChecks = raw: + showWarnings (let + failed = collectFailed raw.config; + failedStr = concatStringsSep "\n" (map (x: "- ${x}") failed); + in if failed == [ ] then + raw + else + throw '' - Failed assertions: - ${failedStr}''); + Failed assertions: + ${failedStr}''); -in { - inherit (module) options config; + withExtraAttrs = rawModule: + let module = moduleChecks rawModule; + in { + inherit (module) options config; - activationPackage = module.config.home.activationPackage; + activationPackage = module.config.home.activationPackage; - # For backwards compatibility. Please use activationPackage instead. - activation-script = module.config.home.activationPackage; + # For backwards compatibility. Please use activationPackage instead. + activation-script = module.config.home.activationPackage; - newsDisplay = rawModule.config.news.display; - newsEntries = sort (a: b: a.time > b.time) - (filter (a: a.condition) rawModule.config.news.entries); + newsDisplay = rawModule.config.news.display; + newsEntries = sort (a: b: a.time > b.time) + (filter (a: a.condition) rawModule.config.news.entries); - inherit (module._module.args) pkgs; -} + inherit (module._module.args) pkgs; + + extendModules = args: withExtraAttrs (rawModule.extendModules args); + }; +in withExtraAttrs rawModule