r/NixOS • u/akSkwYX_ • 1d ago
programs.enable or package ?
Is there some difference between:
programs.great_program.enable = true;
configuration.packages = [
pkgs.grear_program
]
44
u/paulstelian97 1d ago
programs.enable generally does more than simply adding to packages would. The .enable one would also adjust various system configurations, integrations etc in relevant situations. That said not all packages have a programs.enable switch (no integration available) and thus those you can just put in the packages list.
35
u/Additional-Point-824 1d ago
programs.<name>.enable = true; will generally provide additional integration, configuring the software or enabling services.
environment.systemPackages = [ pkgs.<name> ]; will just make the package available in the system path.
In general, you should prefer programs. where they exist.
3
u/CaptainBlase 1d ago edited 1d ago
programs.enable will do things like set file/url associations so links open in firefox or images open in KDE Photos (né Koko).
edit: this incorrect. file associates are handling by the desktop files which are created when the application is installed via systemPackages. Primarily, programs.enable disables automatic updates in the case of firefox, thunderbird, and others. It also let's you set things like policies and preferences, so you can set those things and install the application in the same code block.
3
u/MattiDragon 1d ago
Pretty sure that actually happens automatically by desktop files being exposed in a standard location within the derivation.
1
u/CaptainBlase 1d ago
Pretty sure that actually happens automatically by desktop files being exposed in a standard location within the derivation.
I think you're right. I'm trying to remember why I came to the conclusion about what programs does. I think it was when first installed firefox into the packages collection and found that it didn't handle something correctly until I programs.enabled it. I thought it was file associations; but maybe it was something more complicated like link handling? I'm doubting my memory now.
2
u/karmicgoober 19h ago
fyi, you can use the xdg.mimeApps modu in home-manager if you want to manage the file associations declaratively
1
u/n1x_cybersec 1d ago edited 1d ago
If you read the module source code, programs.enable will do things like install to the correct location, create a config file, desktop file, etc, so this is generally preferred over simply adding the pkgs. There is overlap between adding to packages and using the module, but modules generally do a bit more.
If you are talking about the module option for packages, e.g. programs.example.package, you would use this to install a variation of a package. Such as gitFull instead of git.
My system uses stable, but I added unstable as a flake input and I use the package option to specify an unstable package instead of stable.
You should definitely read the module source though if you are interested, it can be really helpful to see exactly what each option is doing.
-2
89
u/GlassCommission4916 1d ago
As a general rule always use the option if it exists, since it probably exists for a good reason. You can read the source code to see what it does besides installing the package.