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

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

  # Last updated: 2023-05-25. Check for new `nixpkgs-unstable` commits at
  pkgs = import (fetchTarball "") {
    config.allowUnfree = true;
    config.cudaSupport = !stdenv.isDarwin;
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:

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

Hosted by Flying Circus.