I’d like to setup some things in my environment slightly differently depending on whether the environment is pure or not.
Can the code in
shell.nix tell? I know about the
IN_NIX_SHELL environment variable, but would prefer to know at the nix level and not shell level.
(And let’s assume I know what I want and this is a good idea )
You can do it in nix depending on what builtins exist. This would clearly tell you:
builtins ? currentSystem. I think you could then just use that information within the build script too.
You can see this method in nixpkgs where one of nipxkgs’s arguments is
system ? builltins.currentSystem. So if your in pure mode your supposed to explicitly pass a system to nixpkgs. But if your in impure mode nixpkgs will auto set it to your current system.
Does not seem to be the case in Nix 2.3.10:
builtins ? currentSystem yields
true both under
nix-shell and under
Well nix commands <2.4 don’t set pure mode by default. So when you run
nix-build they will evaluate in impure mode unless you explicitly pass
--pure. Therefore, it makes sense that
builtins.currentSystem exists in that case.