Skip to content

passAsFile paths aren't available for nix develop #7265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aameen-tulip opened this issue Nov 4, 2022 · 3 comments
Open

passAsFile paths aren't available for nix develop #7265

aameen-tulip opened this issue Nov 4, 2022 · 3 comments
Labels
bug nix-shell nix-shell, nix develop, nix print-dev-env, etc

Comments

@aameen-tulip
Copy link
Contributor

aameen-tulip commented Nov 4, 2022

Describe the bug

Derivations that use passAsFile don't have access to those paths in nix-command nix develop mode.

Steps To Reproduce

$ mkdir -p /tmp/whoops;
$ cd /tmp/whoops;
$ git init;
$ cat <<'EOF' > flake.nix
{  
  outputs = { nixpkgs, ... }: let
    fes = fn: builtins.foldl' ( a: s: a // { ${s} = fn s; } ) {} [
      "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux"
    ];
  in {
    packages = fes ( system: {
      default = nixpkgs.legacyPackages.${system}.stdenv.mkDerivation {
        name = "whoops";
        data = builtins.concatStringsSep "" ( builtins.genList toString 1024 );
        passAsFile = ["data"];
        buildCommand = ''
          line="$( <"$dataPath"; )";
          echo "$line" > "$out";
        '';
      };
    } );
  };
}
EOF
$ git add ./flake.nix;
$ nix flake lock;
$ git add ./flake.lock;
$ nix build && cat ./result;  # Works
$ rm ./result;
$ nix develop;
$ genericBuild;
bash: /private/tmp/nix-build-whoops-env.drv-0/.attr-1dy8mlivplr3m6ln28k025l0w4ax5kfv4miq9z4qgb1r1xwv0vis: No such file or directory

Expected behavior

Temporary files should be created during devShell initialization.

nix-env --version output

nix-env (Nix) 2.10.3

Additional context

The trivial example above uses buildCommand with stdenv.mkDerivation, but the same issue occurs with (unpack|build|install|...)Phase definition, and even with a direct derivation { ... }.
Defining the installable as devShells = ... in the flake has the same behavior as well.

@roberth roberth added the nix-shell nix-shell, nix develop, nix print-dev-env, etc label Dec 19, 2022
@stale stale bot added the stale label Jun 18, 2023
@lilyinstarlight
Copy link
Member

It looks like nix-shell has custom code to handle this (currently here but originally committed in 08355643a). It doesn't seem to check if structured attrs are in use prior to setting env vars either, unlike local-derivation-goal.cc, so I'm not sure if that's a bug or not in nix-shell

@stale stale bot removed the stale label Jul 13, 2023
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-replace-nix-develop-with-nix-shell-for-a-flake-based-output/31333/1

@dguibert
Copy link
Member

I've identified this issue as well.

Adding __structuredAttrs = true and replacing line="$( <"$dataPath"; )"; by line="$data" provides a workaround.

But despite within a nix-shell, the variable data is not listed by the env command

$ env | grep dataPath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug nix-shell nix-shell, nix develop, nix print-dev-env, etc
Projects
None yet
Development

No branches or pull requests

5 participants