lib.modules: support strings with absolute paths in disabledModules
This is particularly useful for disabling modules defined in a flake. Example: disabledModules = [ "${flake}/modules/mymodule.nix" ]; Previously, absolute string paths were internally prepended with `modulesPath`, which caused the module filtering to fail.
This commit is contained in:
parent
cbf9a129d2
commit
e2cc361970
3 changed files with 9 additions and 1 deletions
|
@ -433,7 +433,9 @@ rec {
|
|||
# modules recursively. It returns the final list of unique-by-key modules
|
||||
filterModules = modulesPath: { disabled, modules }:
|
||||
let
|
||||
moduleKey = m: if isString m then toString modulesPath + "/" + m else toString m;
|
||||
moduleKey = m: if isString m && (builtins.substring 0 1 m != "/")
|
||||
then toString modulesPath + "/" + m
|
||||
else toString m;
|
||||
disabledKeys = map moduleKey disabled;
|
||||
keyFilter = filter (attrs: ! elem attrs.key disabledKeys);
|
||||
in map (attrs: attrs.module) (builtins.genericClosure {
|
||||
|
|
|
@ -130,6 +130,7 @@ checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-foo-enab
|
|||
set -- config.enable ./define-enable.nix ./declare-enable.nix
|
||||
checkConfigOutput '^true$' "$@"
|
||||
checkConfigOutput '^false$' "$@" ./disable-define-enable.nix
|
||||
checkConfigOutput '^false$' "$@" ./disable-define-enable-string-path.nix
|
||||
checkConfigError "The option .*enable.* does not exist. Definition values:\n\s*- In .*: true" "$@" ./disable-declare-enable.nix
|
||||
checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-define-enable.nix ./disable-declare-enable.nix
|
||||
checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-enable-modules.nix
|
||||
|
|
5
lib/tests/modules/disable-define-enable-string-path.nix
Normal file
5
lib/tests/modules/disable-define-enable-string-path.nix
Normal file
|
@ -0,0 +1,5 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
disabledModules = [ (toString ./define-enable.nix) ];
|
||||
}
|
Loading…
Reference in a new issue