readFile doesn't find file

So, I’m trying to move a bash script out of a flake with writeShellScriptBin and readFile, as follows:

nanolibs-script = rec {                                               
  name = "nanolibs-path";                                             
  source = builtins.readFile ./;                    
  script = (pkgs.writeShellScriptBin name source).overrideAttrs(old: {
    buildCommand = "${old.buildCommand}\n patchShebangs $out";        
  buildInputs = [                                                     

But I’m constantly getting the following error:

error: getting status of '/nix/store/r0bfh3zd9prbkwd4ip9pl7y3i1qxj2g9-source/': No such file or directory

It seems to be looking for a store but shouldn’t instead be looking into the current directory where the script is? Tried with writeScriptBin also with a simple script and got the the same result. Also found this, which seems to suggest that there’s some sort of impurity but I dunno what that could be.

git add

Then try again.

1 Like

That was it, thanks! I don’t get it though, where does git come into the picture?

1 Like

Flakes and git are somewhat intertwined. If a flake is a git repo, then git’s view of the world is taken into account in the flake. In particular, files unknown to git are not copied to the nix store before evaluation. The git commit is also available from self.rev, so long as the worktree isn’t dirty.

This is rather unintuitive because nix still takes account of uncommitted changes to files, so long as git doesn’t view them as “untracked”, but it is what it is.