Detect that bash script is running under NixOS

How do I check if I’m running on NixOS (vs a different Linux distribution) in a bash script?

You can test whether the file /etc/NIXOS exists. From the manual:

/etc/NIXOS officializes that this is now a NixOS partition (the bootup scripts require its presence).

1 Like

You could read /etc/os-release, especially NAME and ID might be of interest.

1 Like

grep ‘NAME=NixOS’ /etc/os-release