How can I split packages into different files?

I’ve found some references to how I can split up packages into different files

{
  imports =
    [ ./packages1.nix
      ./packages2.nix
    ];
  environment.systemPackages = with pkgs; lib.concatLists [
    packages1
    packages2
  ];
}

, but how would packages1.nix for example look like?

Modules actually get automatically composed. So:

# packages1.nix
{ pkgs, ... } : {
    environment.systemPackages = with pkgs; [ ... ];
}
# packages2.nix
{ pkgs, ... } : {
    environment.systemPackages = with pkgs; [ ... ];
}
# configuration.nix
{
    imports = [ packages1.nix packages2.nix ];
}

The environemnt.systemPackages values would automatically get concatenated when importing the modules.

Note that imports = [ ... ] is different from import file.nix (the second doesn’t use the module system and just reads the file).

1 Like

That’s just great;). Thanks;)