There are probably other reasons, but here is my favorite.
Here’s an example flake:
❯ cat flake.nix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
};
outputs = { self, nixpkgs }: {
packages.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.awk;
packages.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.sed;
};
}
Notice that I’m setting the default package to both sed
and awk
. If you try to build it:
❯ nix build
error: attribute 'packages.x86_64-linux.default' already defined at /nix/store/a8jzismmx028lx1igywd1g2xq0zw3lvn-source/flake.nix:6:5
at /nix/store/a8jzismmx028lx1igywd1g2xq0zw3lvn-source/flake.nix:7:5:
6| packages.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.awk;
7| packages.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.sed;
| ^
8| };
Having multiple sources of truth for the same thing is an error in nix. Elsewhere, a program may take its configuration from one of a variety of config files. The Apache webserver for example…
On most systems if you installed Apache with a package manager, or it came preinstalled, the Apache configuration file is located in one of these locations:
/etc/apache2/httpd.conf
/etc/apache2/apache2.conf
/etc/httpd/httpd.conf
/etc/httpd/conf/httpd.conf
You could have two of these and waste a bunch of time editing whichever one doesn’t have precedence and wondering why your edits don’t make a difference. I know I’ve wasted a lot of time being wrong about where a certain config was coming from. Errors, on the other hand, those you can fix almost immediately.
If there’s no risk of this kind of thing in your case, I think it’s perfectly fine to just use home manager to plop config files where the program expects them.
If you later need to update the contents of those files based on some parameter that is known to nix, you can use pkgs.substituteAll
to inject the parameter. I do this here. I want wezterm to use nushell and zellij, so I inject their /nix/store paths into wezterm.lua
.
Like Apache, wezterm has a similarly complex way of deciding which config file to use. So my config would break if I tried to use it on a machine which had $XDG_CONFIG_HOME set to something weird. But since I never do that it’s fine to just plop the file.
I guess the moral of the story is that conventional file locations are a bit of a mess, and it’s a mess that nix tries to clean up.