This is somewhat a related question. Consider the following:
- This works
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
(if virtCfg.virtualbox.enable then "Oracle_VirtualBox_Extension_Pack" else null)
];
- this fails (not possible to evaluate unfree pkg) even when the option is set to true
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
(lib.mkIf virtCfg.virtualbox.enable "Oracle_VirtualBox_Extension_Pack")
];
- this also works
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) ([ ]
++ (if virtCfg.virtualbox.enable then ["Oracle_VirtualBox_Extension_Pack"] else [])
);
- this fails with
expected a list but found a set: : { _type = "if"; condition = «thunk»; content = «thunk»; }
nixpkgs.config. allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) ([ ]
++ (lib.mkIf virtCfg.virtualbox.enable ["Oracle_VirtualBox_Extension_Pack"])
);
Indeed, lib.mkIf
returns a set according to the source.
From what I could understand:
if
/else
is a Nix lang construct so it’s evaluated before the module system (?)lib.mkIf
returns a set but it’s wrapped inside a function and the module system doesn’t further evaluate (?) so the set doesnt match any name and the package is never allowed.- same as 1
- similar to 2 but the concat early fails
This is all due to the difference between what is the Nix Lang and the Nix module system. Am I in the right track?
This is a broad question but I lack enough knowledge to better pose it, when is the module system evaluated in comparison to the language itself?
Pointing documentation/source/blog post is also appreciated.