Nix flake: the development enviornment created by running "nix develop" contains "usr/bin" in $PATH

Hi, I am new to Nix and trying out nix flake.
I have created an emptyEnv.nix file which as the name suggests it is empty with no tools.

{ pkgs, mkShellNoCC }:

with pkgs;

mkShellNoCC {
  buildInputs = [];
}

I created a flake.nix file which imports emptyEnv as a package.

{
  description = "my description";

  inputs = { 
    flake-utils.url = "github:numtide/flake-utils";
    };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachSystem ["x86_64-linux"] (system:
      let 
        pkgs = nixpkgs.legacyPackages.${system};
        callPackage = pkgs.callPackage;
        mkShellNoCC = pkgs.mkShell.override { stdenv = pkgs.stdenvNoCC; };
      in {
        packages = {
          emptyEnv = callPackage ./nix/env/emptyenv.nix { };
      };
   
      }); 
  
}

Now when i run nix develop .#emptyEnv and echo $PATH, then this is the output i get

/nix/store/b92bv871ikpy48w6fw01lz0x91hd2m2h-patchelf-0.12/bin
/nix/store/203srbndvymk3pngvndmfcmprzk14333-coreutils-8.32/bin
/nix/store/al1x84ykihyf0yd6f1hh6llrlj7as23s-findutils-4.7.0/bin
/nix/store/1rz07gzbf4p2l1v0r6idag6gfncgblmy-diffutils-3.7/bin
/nix/store/fvyll1a0lxcny4jb817l9aqlsm2v371z-gnused-4.8/bin
/nix/store/1ismzpy211c3wlj7mg75mrkih9k0w5i1-gnugrep-3.6/bin
/nix/store/as093a69gbw9nsyd6y320hcim0z214dm-gawk-5.1.0/bin
/nix/store/ndzg51fshjcbzrd9mpm56ccv6nykaf16-gnutar-1.34/bin
/nix/store/03mk28nb2iplxs68cvjnnk9jmbigzaja-gzip-1.10/bin
/nix/store/1qcbk59wdmzv6w64i9lkasnk9f11knx0-bzip2-1.0.6.0.2-bin/bin
/nix/store/qwxz3m0xpqk9sjdgcpzjwbnzi911q5jp-gnumake-4.3/bin
/nix/store/26a78ync552m8j4sbjavhvkmnqir8c9y-bash-4.4-p23/bin
/nix/store/ba9vnjihlsqibrirx0jh10pjv1k6y2rn-patch-2.7.6/bin
/nix/store/i21d0gvqylil237bwbxxywi938yhh77a-xz-5.2.5-bin/bin
/root/.nix-profile/bin 
/usr/local/sbin 
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin

I was under an impression that shell environment created in nix flake is pure and hence should not contain following paths in $PATH

/root/.nix-profile/bin 
/usr/local/sbin 
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin

Am i missing anything?
Is my code incorrect?
Is it a bug in nix flake? (I highly doubt it)

When i run nix-shell -p cmake then also i get usr/bin in my path; however when i run nix-shell -p cmake --pure, then i do not get usr/bin in my path.

No, the environment created by nix develop is not pure by default: it keeps the environment of the caller, and it sources the bashrc scripts. To get around this, add something like --ignore-environment --command bash --norc.

6 Likes