Skip to content

Shallow clones cannot be imported #74

@MattSturgeon

Description

@MattSturgeon

When the flake is a shallow clone (e.g. --depth=1) it cannot be imported by nix-instantiate or similar stable nix commands.

E.g.

$ git clone [email protected]:nix-community/nixvim.git --depth=1 nixvim_shallow
Cloning into 'nixvim_shallow'...
remote: Enumerating objects: 1977, done.
remote: Counting objects: 100% (1977/1977), done.
remote: Compressing objects: 100% (1255/1255), done.
remote: Total 1977 (delta 103), reused 1541 (delta 52), pack-reused 0 (from 0)
Receiving objects: 100% (1977/1977), 1.09 MiB | 3.11 MiB/s, done.
Resolving deltas: 100% (103/103), done.

$ cd nixvim_shallow

$ nix-instantiate --eval --show-trace -A outPath
error:
       … while evaluating the attribute 'defaultNix'
         at /nix/store/8694kanhi1kzc34kg81l33pvn638qvnh-source/default.nix:234:5:
          233|
          234|     defaultNix =
             |     ^
          235|       (builtins.removeAttrs result ["__functor"])

       … in the left operand of the update (//) operator
         at /nix/store/8694kanhi1kzc34kg81l33pvn638qvnh-source/default.nix:236:7:
          235|       (builtins.removeAttrs result ["__functor"])
          236|       // (if result ? defaultPackage.${system} then { default = result.defaultPackage.${system}; } else {})
             |       ^
          237|       // (if result ? packages.${system}.default then { default = result.packages.${system}.default; } else {});

       … while calling the 'removeAttrs' builtin
         at /nix/store/8694kanhi1kzc34kg81l33pvn638qvnh-source/default.nix:235:8:
          234|     defaultNix =
          235|       (builtins.removeAttrs result ["__functor"])
             |        ^
          236|       // (if result ? defaultPackage.${system} then { default = result.defaultPackage.${system}; } else {})

       … from call site
         at /nix/store/8694kanhi1kzc34kg81l33pvn638qvnh-source/default.nix:227:10:
          226|     else if lockFile.version >= 5 && lockFile.version <= 7
          227|     then allNodes.${lockFile.root}
             |          ^
          228|     else throw "lock file '${lockFilePath}' has unsupported version ${toString lockFile.version}";

       … while calling anonymous lambda
         at /nix/store/8694kanhi1kzc34kg81l33pvn638qvnh-source/default.nix:159:13:
          158|     builtins.mapAttrs
          159|       (key: node:
             |             ^
          160|         let

       … in the condition of the assert statement
         at /nix/store/8694kanhi1kzc34kg81l33pvn638qvnh-source/default.nix:214:13:
          213|           if node.flake or true then
          214|             assert builtins.isFunction flake.outputs;
             |             ^
          215|             result

       … while calling the 'isFunction' builtin
         at /nix/store/8694kanhi1kzc34kg81l33pvn638qvnh-source/default.nix:214:20:
          213|           if node.flake or true then
          214|             assert builtins.isFunction flake.outputs;
             |                    ^
          215|             result

       … while calling the 'import' builtin
         at /nix/store/8694kanhi1kzc34kg81l33pvn638qvnh-source/default.nix:170:19:
          169|
          170|           flake = import (outPath + "/flake.nix");
             |                   ^
          171|

       … while realising the context of path '/nix/store/vpn8hj1w4g8d6d6knc2sxy4ly5nrxsp1-nixvim_shallow/flake.nix'

       error: path '/nix/store/vpn8hj1w4g8d6d6knc2sxy4ly5nrxsp1-nixvim_shallow' is not valid

Incidentally, using the experimental nix eval command works fine; I'm guessing this has something to do with the subtle purity differences? Or maybe this has an implicit copy-to-store, similar to a flake eval?

$ nix eval --show-trace --file . outPath
"/nix/store/vpn8hj1w4g8d6d6knc2sxy4ly5nrxsp1-nixvim_shallow"

After a successful nix eval, nix-instantiate starts working correctly:

$ nix-instantiate --eval --show-trace -A outPath
"/nix/store/vpn8hj1w4g8d6d6knc2sxy4ly5nrxsp1-nixvim_shallow"

Invalidating the NAR hash (so that a different store path is used) reproduces the issue again:

$ touch foo
$ nix-instantiate --eval --show-trace -A outPath
error:

I cannot reproduce the issue with a normal "deep" clone:

$ git clone [email protected]:nix-community/nixvim.git nixvim_deep
Cloning into 'nixvim_deep'...
remote: Enumerating objects: 32490, done.
remote: Counting objects: 100% (414/414), done.
remote: Compressing objects: 100% (238/238), done.
remote: Total 32490 (delta 290), reused 195 (delta 175), pack-reused 32076 (from 3)
Receiving objects: 100% (32490/32490), 7.57 MiB | 7.77 MiB/s, done.
Resolving deltas: 100% (22144/22144), done.

$ cd nixvim_deep/

$ nix-instantiate --eval --show-trace -A outPath
"/nix/store/brjpjdl03imkqa3g35q7srd8ckhds2w4-source"

$ touch foo && git add -N foo

$ nix-instantiate --eval --show-trace -A outPath
warning: Git tree '/home/matt/nixvim_deep' is dirty
"/nix/store/x94djbggc5yzslvn8qrg4bf67r7gs276-source"

Tested with flake-compat revision: ff81ac9
And nixvim revision: nix-community/nixvim@4aad22c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions