The file gets linked there thanks to the following two options:
Simple way to insert your own file there is creating a single file package using writeTextFile and passing the result to environment.systemPackages.
Note that this method only works for packages that look for files in /run/current-system/sw like update-mime-database does. Most packages will search their own store paths so this is not a generally applicable technique.
error: builder for '/nix/store/q99l4nmyrinaf2nbvvwpa94r5kcgyndi-override.xml.drv' failed to produce output path for output 'out' at '/nix/store/q99l4nmyrinaf2nbvvwpa94r5kcgyndi-override.xml.drv.chroot/nix/store/spyiqabfk2rbzkl6nbpd3dpl9a8f5zyd-override.xml'
Most packages will search their own store paths so this is not a generally applicable technique.
Is there general way of doing this?
I notice you can create a file in /etc with “environment.etc”, and you get the file in /etc. You’ve got this method for /usr and the files appear under /run/current-system/sw. What happens, say, if you want a config file under /var/lib?
Just note that unlike stuff linked to /run/current-system/sw, it will not be changed atomically and it is no longer congruent management we love about NixOS – systemd.tmpfiles option delegates the file creation to systemd which will do it divergently at its leisure. If you later remove the option from your configuration and switch to system built from it, the file will not be removed because systemd loses track of it.