Hi all,
as far as I understood, nix automatically “merges” lists, if they are defined in more than one place. So a list of packages to be install can be appended.
However, I cannot get this working for the nixpkgs.config.allowUnfreePredicate
setting, as this is using a list, but has some more functions in it, which apparently prevents simple appending.
Say, I have a file host.nix that imports from whatever.nix
.
vagrant.nix
uses this:
nixpkgs.config = {
allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"vagrant"
];
};
After I import this, I would like to add another string to this list. What do I need to put into the host.nix
file to not overwrite, but rather add an entry to this list?
Kind Regards,
Johannes
If you have full control over both files, the easiest thing would probably be to define your own option and then use that in the predicate:
{ config, lib, ... }: {
# This defines an option with list type so that you get
# the desired merging behaviour.
options.my-allowed-unfree-packages = lib.mkOption {
type = lib.types.listOf lib.types.str;
};
config.my-allowed-unfree-packages = [
# Unfree packages you want to use go here.
];
# Here we define the predicate using our own
# `config.my-allowed-unfree-packages` list.
config.nixpkgs.config.allowUnfreePredicate = pkg:
builtins.elem (lib.getName pkg) config.my-allowed-unfree-packages;
}
If you don’t have control over one or more of the files that define an allowUnfreePredicate
you might need to override the predicates in those other files by wrapping yours in lib.mkForce
, and then just include the packages in your own list.
No, the module system in nixpkgs defines a merge
function for options that are defined as lib.types.listOf <something>
. This option is a function, not a list (“predicate” is jargon that means “function”, here) so it’s not going to behave the same (especially since the option nixpkgs.config.allowUnfreePredicate
isn’t even explicitly declared anywhere in nixpkgs, instead nixpkgs.config
is a freeform submodule defined as lazyAttrsOf raw
, which has its own behaviour…).
Ultimately, that’s why you’ll have to go with @olmokramer’s suggestions.
Thanks for the reply. Using my own variable was my first guess, but I was not sure if there was a better way.
I’ll give it a try.
Hmm, no matter if I use home.allowed-unfree-packages
or config.allowed-unfree-packages
, it seems to overwrite the home-manager home
variable. I’ll read up on how to set this properly…
... has an unsupported attribute `home'. This is caused by introducing a top-level `config' or `options' attribute. Add configuration attributes immediately on the top level instead, or move all of them (namely: home nix nixpkgs programs services targets) into the explicit `config' attribute.
move all of them (namely: home nix nixpkgs programs services targets) into the explicit config
attribute.
The error tells you the issue and how to fix it. Everything in a module needs to be under config
/options
/imports
if you start using config
/options
at the top level.
See NixOS Manual and the example there.
OK, this took a little more work, as I had to refactor multiple files and move all their content to be under config
, but now it seems to work.
Thanks for the help, guys!
Kind Regards,
Johannes
FYI you only have to refactor the one file that uses options
/config
. Or whichever other file that uses it.