Allow modulesPath in NixOS modules (#536)

This commit is contained in:
Naïm Favier 2022-09-08 16:29:53 +02:00 committed by GitHub
parent 9e64e2f6c3
commit 4776108b4b
Failed to generate hash of commit

View file

@ -44,7 +44,7 @@ let
) )
) apps; ) apps;
readOptions = let readNixOSOptions = let
declarations = module: ( declarations = module: (
lib.evalModules { lib.evalModules {
modules = (if lib.isList module then module else [ module ]) ++ [ modules = (if lib.isList module then module else [ module ]) ++ [
@ -54,6 +54,13 @@ let
} }
) )
]; ];
specialArgs = {
# !!! NixOS-specific. Unfortunately, NixOS modules can rely on the `modulesPath`
# argument to import modules from the nixos tree. However, most of the time
# this is done to import *profiles* which do not declare any options, so we
# can allow it.
modulesPath = "${nixpkgs.path}/nixos/modules";
};
} }
).options; ).options;
@ -95,14 +102,14 @@ let
readFlakeOptions = let readFlakeOptions = let
nixosModulesOpts = builtins.concatLists (lib.mapAttrsToList (moduleName: module: nixosModulesOpts = builtins.concatLists (lib.mapAttrsToList (moduleName: module:
readOptions { readNixOSOptions {
inherit module; inherit module;
modulePath = [ flake moduleName ]; modulePath = [ flake moduleName ];
} }
) (resolved.nixosModules or {})); ) (resolved.nixosModules or {}));
nixosModuleOpts = lib.optionals (resolved ? nixosModule) ( nixosModuleOpts = lib.optionals (resolved ? nixosModule) (
readOptions { readNixOSOptions {
module = resolved.nixosModule; module = resolved.nixosModule;
modulePath = [ flake ]; modulePath = [ flake ];
} }