NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.49k stars 12.99k forks source link

NixOS modules should not set environment variables to nix store paths #312224

Open amozeo opened 1 month ago

amozeo commented 1 month ago

Describe the bug

When updating system using nixos-rebuild switch or nixos-rebuild test, environment variables usually are not being updated in running processess and user sessions, and in order for them to be updated, a session relog or system restart would need to happen.

Thus, environement variables could contain outdated store path, and it's the reason why nix store paths should not be used in environment variables and be actively discouraged.

for configuration files, /etc directory could be used as an alternative.

I have found that these NixOS modules use nix store paths in environment variables

This issue was originally reported in https://github.com/NixOS/nixpkgs/issues/311207 however I believe a separating it from that issue is better.


Add a :+1: reaction to issues you find important.

Atemu commented 1 month ago

Note that this only concerns sessions variables; env vars that are part of some long-running "session" that keeps its initial set of environment variables such as the user session.

Using nix store paths in env vars of i.e. systemd system services however is fine as they are restarted automatically upon activation when anything has changed.

Note again that the same is not true for user services however; they are not restarted upon activation.