nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

lib/modules: Only interpret class declaration in non-shorthand mode

This is to avoid stealing keys from submodules. `class` might be
common enough that reinterpreting existing `class` attributes in
configurations as a declaration leads to fairly widespread problems.

+19 -1
+1 -1
lib/modules.nix
··· 511 511 imports = m.require or [] ++ m.imports or []; 512 512 options = {}; 513 513 config = addFreeformType (removeAttrs m ["_file" "key" "disabledModules" "require" "imports" "freeformType"]); 514 - class = m.class or null; 514 + class = null; 515 515 }; 516 516 517 517 applyModuleArgsIfFunction = key: f: args@{ config, options, lib, ... }:
+2
lib/tests/modules.sh
··· 255 255 ## Freeform modules 256 256 # Assigning without a declared option should work 257 257 checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix 258 + # Shorthand modules interpret `meta` and `class` as config items 259 + checkConfigOutput '^true$' options._module.args.value.result ./freeform-attrsOf.nix ./define-freeform-keywords-shorthand.nix 258 260 # No freeform assignments shouldn't make it error 259 261 checkConfigOutput '^{ }$' config ./freeform-attrsOf.nix 260 262 # but only if the type matches
+1
lib/tests/modules/class-check.nix
··· 25 25 ./module-class-is-nixos.nix 26 26 { _file = "foo.nix#darwinModules.default"; 27 27 class = "darwin"; 28 + config = {}; 28 29 imports = []; 29 30 } 30 31 ];
+15
lib/tests/modules/define-freeform-keywords-shorthand.nix
··· 1 + { config, ... }: { 2 + class = { "just" = "data"; }; 3 + a = "one"; 4 + b = "two"; 5 + meta = "meta"; 6 + 7 + _module.args.result = 8 + let r = builtins.removeAttrs config [ "_module" ]; 9 + in builtins.trace (builtins.deepSeq r r) (r == { 10 + a = "one"; 11 + b = "two"; 12 + class = { "just" = "data"; }; 13 + meta = "meta"; 14 + }); 15 + }