Determine whether NixOS or Nix Package Manager on Another Linux Distro

Is there a way to determine in a derivation whether you are using NixOS or just the package manager on another distro? I’ve used isLinux and isDarwin before, but this doesn’t cover this specific use-case of detecting NixOS or a non-NixOS Linux.

At runtime yes, by checking for the presence of /etc/NIXOS. But not at eval/build time. Linux packages should work on both NixOS and non-NixOS Linux.

That’s a shame if not at build time.

My primary reason for doing this is for software that requires the use of nixGL - this is for my own software repository flakes rather than for nixpkgs.

I already have a script being written to launch the software, so I can do the presence check (don’t know why I didn’t think of that before) but I suppose I would have to include nixGL in both cases if there’s no way to do it at build time.

I understand the normal approach would be to tell non-NixOS users to use nixGL rather than include it within my derivations - although the particular users in mind aren’t as nix fluent as I. I suppose I could have the script use something nix run github:guibou/nixGL -- program in this particular case, although it certainly wouldn’t be a deterministic package it would mean nixGL is up to date.

Thanks for your response.

FWIW, it’s my understanding that at some future point, something will change in Mesa so that nixGL will no longer be required, but I don’t know the specifics.

2 Likes