Skip to content

Commit

Permalink
Add support for extraModules input
Browse files Browse the repository at this point in the history
NixOS offers the possibility to pass a list of extraModules to
lib.nixosSystem which later get merged with the modules list and
baseModules.
This offers the possibility to read additional modules from environment
files or a custom module-list.nix.

NixOS implementation is
[here](https://github.com/NixOS/nixpkgs/blob/8601973cec591ab18357eb7c26c52769d990d1ed/nixos/lib/eval-config.nix#L33).

Dor nix-darwin an implementation was started in #592.
I restarted the implementation and removed the usage of
`NIXOS_EXTRA_MODULE_PATH` env variable because NixOS deprecated this
one.
  • Loading branch information
oliverwiegers committed Jan 27, 2025
1 parent 62ba0a2 commit 81f1989
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions eval-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ in
{ lib
, modules
, baseModules ? import ./modules/module-list.nix
, extraModules ? []
, specialArgs ? { }
, check ? true
, enableNixpkgsReleaseCheck ? true
Expand Down Expand Up @@ -72,14 +73,14 @@ let
_file = ./eval-config.nix;
config = {
_module.args = {
inherit baseModules modules;
inherit baseModules extraModules modules;
};
};
};

eval = lib.evalModules (builtins.removeAttrs args [ "lib" "enableNixpkgsReleaseCheck" ] // {
eval = lib.evalModules (builtins.removeAttrs args [ "lib" "enableNixpkgsReleaseCheck" "extraModules" ] // {
class = "darwin";
modules = modules ++ [ argsModule ] ++ baseModules;
modules = baseModules ++ extraModules ++ modules ++ [ argsModule ];
specialArgs = { modulesPath = builtins.toString ./modules; } // specialArgs;
});
in
Expand Down
4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
lib = {
evalConfig = import ./eval-config.nix;

darwinSystem = args@{ modules, ... }: self.lib.evalConfig (
darwinSystem = args@{ modules, extraModules ? [], ... }: self.lib.evalConfig (
{ inherit (nixpkgs) lib; }
// nixpkgs.lib.optionalAttrs (args ? pkgs) { inherit (args.pkgs) lib; }
// builtins.removeAttrs args [ "system" "pkgs" "inputs" ]
// {
inherit extraModules;

modules = modules
++ nixpkgs.lib.optional (args ? pkgs) ({ lib, ... }: {
_module.args.pkgs = lib.mkForce args.pkgs;
Expand Down

0 comments on commit 81f1989

Please sign in to comment.