Skip to content

overriding a non-flake input with a subdirectory of a git repository does not work #16388

Description

@marienz

Describe the bug

Pointing --override-input at a subdirectory of a git repository results in a git+file: url with a dir attribute pointing at the subdirectory. For a non-flake input, this subdirectory seems to be ignored.

Steps To Reproduce

Create a flake like this:

.
├── data
│   └── file
├── flake.lock
└── flake.nix

with flake.nix containing:

{
  inputs = {
    data = {
      url = ./data;
      flake = false;
    };
  };

  outputs = {data, ...}: {
    packages.x86_64-linux = {
      default = builtins.toFile "demo" (builtins.readFile "${data}/file");
    };
  };
}

The contents of file do not matter. (And what we do with data does not really matter.)

Running nix build . copies the contents of file, as expected.

If the flake is not in a git repository, running nix build . --override-input data ./data does the same thing, as expected, and we can see the input being overridden to a path: url:

$ nix build . --override-input data ./data
warning: not writing modified lock file of flake 'path:/tmp/flake-demo':
• Updated input 'data':
    'path:data'
  → 'path:/tmp/flake-demo/data?lastModified=1788008901&narHash=sha256-sz6PxoNpM5SL6UiBvOFFvSFSEf2UsjfWX1w8r2bPenc%3D' (2026-08-29)

But if the flake is in a git repository, we get:

$ nix build . --override-input data ./data
warning: Git tree '/home/marienz/tmp/flake-demo' is dirty
warning: not writing modified lock file of flake 'git+file:///home/marienz/tmp/flake-demo':
• Updated input 'data':
    'path:data'
  → 'git+file:///home/marienz/tmp/flake-demo?dir=data' (1970-01-01)
error:
       … while calling the 'toFile' builtin
         at /home/marienz/tmp/flake-demo/flake.nix:11:17:
           10|     packages.x86_64-linux = {
           11|       default = builtins.toFile "demo" (builtins.readFile "${data}/file");
             |                 ^
           12|     };

       … while evaluating the second argument passed to builtins.toFile

       … while calling the 'readFile' builtin
         at /home/marienz/tmp/flake-demo/flake.nix:11:41:
           10|     packages.x86_64-linux = {
           11|       default = builtins.toFile "demo" (builtins.readFile "${data}/file");
             |                                         ^
           12|     };

       error: Path 'file' does not exist in Git repository "/home/marienz/tmp/flake-demo".

Similarly, if we print "${data}" or use it in a derivation, we get a store path that contains the entire git repository, not the subdir we wanted.

Expected behavior

The behavior when not in a git repository is the behavior I expect: when overriding a non-flake input with a local path, the local path should be used.

I'm not sure if it makes more sense for --override-input on a non-flake input to use a path: instead of git+file: url, or if the dir attribute should work.

Metadata

nix-env (Nix) 2.34.8

Additional context

Explicitly passing a path: url to --override-input works around the problem:

nix build . --override-input data path:./data
warning: Git tree '/home/marienz/tmp/flake-demo' is dirty
warning: not writing modified lock file of flake 'git+file:///home/marienz/tmp/flake-demo':
• Updated input 'data':
    'path:data'
  → 'path:/home/marienz/tmp/flake-demo/data?lastModified=1788007640&narHash=sha256-sz6PxoNpM5SL6UiBvOFFvSFSEf2UsjfWX1w8r2bPenc%3D' (2026-08-29)

But this is not very intuitive.

Checklist

#5401 looks related (but I don't think it's a duplicate.)


Add 👍 to issues you find important.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions