Hi,
I’ve recently started using NixOS and would like to store part of my defined packages, in a separate file (packages.nix). I would like to import the file into my configuration.nix and then do something along the lines of:
environment.systemPackages = with pkgs; [
package1
package2
] ++ myPackages;
with myPackages being a variable of the content imported from packages.nix. This however, just doesn’t seem to work the way I want it to.
Unfortunatly neither this, nor other things I tried seemed to work. I also tried this whole mkOptions thing, but it still won’t work and even if it did, I can’t imagine that being the best approach available to me.
You can do that in theory, but it’s nicer to just use the module system as intended. If you write to a list in two different modules, the NixOS module system will merge them:
Custom options are usually a code smell IMO, they’re practically never necessary if you use the module system well, unless you want to write a new module for something completely independent from scratch. Composition should be done with the module system, not import/conditions.
Yep, the NixOS module system merges together all values defined in different modules (~files). If the module system can’t merge something nix will give you an error telling you to use mkForce or such, this is true for simple strings or such (though there’s also types.lines which look like strings and get merged together just fine).