Using `stdenv` in `shell.nix` file?

I want to write a nix-shell shell.nix file like

let
  # Last updated: 2023-05-25. Check for new `nixpkgs-unstable` commits at https://status.nixos.org.
  pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/21eb6c6ba74dcbe3ea5926ee46287300fb066630.tar.gz") {
    config.allowUnfree = true;
    config.cudaSupport = !stdenv.isDarwin;
  };
in
pkgs.mkShell {
  buildInputs = with pkgs; [ cowsay ];
}

but I’m faced with a challenge: stdenv is a member of nixpkgs and is not built-in AFAICT…

How does one get the platform info without importing nixpkgs first?

You can use builtins.currentSystem, though that would be impure

1 Like

Well, getting platform info is impure in principle, right?

Platform logic is independent of stdenv:

let
  nixpkgsSrc = …;
  lib = import (nixpkgsSrc + "/lib");
  evalPlatform = lib.systems.elaborate { system = builtins.currentSystem; };
  pkgs = import nixpkgsSrc {
    config.cudaSupport = !evalPlatform.isDarwin;
  };
in

…