[Nix#9501] Locking error on 2.19 with path:. #93

Open
opened 2024-03-16 06:44:52 +00:00 by lix-bot · 0 comments
Member

Upstream-Issue: NixOS/nix#9501

Describe the bug

When trying to lock a new flake input using 2.19 it complains about using a relative path:

$ nix run nix/2.19.2 -- flake lock path:.                                                                                
warning: creating lock file './flake.lock':
• Added input 'nixpkgs':
    'github:NixOS/nixpkgs/0b35753f0128c4a34d6712e60b0a23f893665f31' (2023-11-30)
error:
       … while updating the lock file of flake 'path:.?lastModified=1701373273&narHash=sha256-eS8tjCsvpjD3exYqpI8ttnikplpBdEYh5UtkM
1jzJw8%3D'

       error: cannot fetch input 'path:.' because it uses a relative path

Note that using the implicit path: works (either use just the . without path: or nothing at all) since it seems to use the full path in these cases

$ nix run nix/2.19.2 -- flake lock .
warning: creating lock file '/tmp/test/flake.lock': 
• Added input 'nixpkgs':
    'github:NixOS/nixpkgs/0b35753f0128c4a34d6712e60b0a23f893665f31' (2023-11-30)
$ nix run nix/2.19.2 -- flake lock
warning: creating lock file '/tmp/test/flake.lock': 
• Added input 'nixpkgs':
    'github:NixOS/nixpkgs/0b35753f0128c4a34d6712e60b0a23f893665f31' (2023-11-30)

though the docs seem to suggest that these should behave the same:

If the flake at path is not inside a git repository, the path: prefix is implied and can be omitted.

and of course since the error is about relative paths it works just fine with full paths and works as a workaround

$ nix run nix/2.19.2 -- flake lock path:$PWD
warning: creating lock file '/tmp/test/flake.lock': 
• Added input 'nixpkgs':
    'github:NixOS/nixpkgs/0b35753f0128c4a34d6712e60b0a23f893665f31' (2023-11-30)

Steps To Reproduce

  1. Create simple flake
    { inputs.nixpkgs.url = "github:NixOS/nixpkgs"; outputs = _: { }; }
    
  2. Try to lock explicitly using path:.
    $ nix run nix/2.19.2 -- flake lock path:.  
    
  3. See error above

Expected behavior

The docs state the following:

path generally must be an absolute path. However, on the command line, it can be a relative path (e.g. . or ./foo) which is interpreted as relative to the current directory. In this case, it must start with . to avoid ambiguity with registry lookups (e.g. nixpkgs is a registry lookup; ./nixpkgs is a relative path).

but it does not seem to be the case.

It is also regression compared to 2.18.1:

$ nix run nix/2.18.1 -- flake lock path:.
warning: creating lock file './flake.lock'

Additional context

  1. I was specifically working inside of a git repo with untracked changes that I was trying to quickly test before committing.

  2. Tried looking at the git blame, and to me it seems like #9239 might have introduced the issue.

    Here it seems to assume that the path is always absolute, but I'm not confident enough with my knowledge of the nix code base to be 100% sure. The error might come from elsewhere and I'm just making a fool of myself here.
    3d46fa85c8/src/libfetchers/path.cc (L90-L98)

Priorities

Add 👍 to issues you find important.

Upstream-Issue: https://git.lix.systems/NixOS/nix/issues/9501 **Describe the bug** When trying to lock a new flake input using 2.19 it complains about using a relative path: ```shell $ nix run nix/2.19.2 -- flake lock path:. warning: creating lock file './flake.lock': • Added input 'nixpkgs': 'github:NixOS/nixpkgs/0b35753f0128c4a34d6712e60b0a23f893665f31' (2023-11-30) error: … while updating the lock file of flake 'path:.?lastModified=1701373273&narHash=sha256-eS8tjCsvpjD3exYqpI8ttnikplpBdEYh5UtkM 1jzJw8%3D' error: cannot fetch input 'path:.' because it uses a relative path ``` Note that using the implicit `path:` works (either use just the `.` without `path:` or nothing at all) since it seems to use the full path in these cases ```shell $ nix run nix/2.19.2 -- flake lock . warning: creating lock file '/tmp/test/flake.lock': • Added input 'nixpkgs': 'github:NixOS/nixpkgs/0b35753f0128c4a34d6712e60b0a23f893665f31' (2023-11-30) ``` ```shell $ nix run nix/2.19.2 -- flake lock warning: creating lock file '/tmp/test/flake.lock': • Added input 'nixpkgs': 'github:NixOS/nixpkgs/0b35753f0128c4a34d6712e60b0a23f893665f31' (2023-11-30) ``` though the docs seem to suggest that these should behave the same: > If the flake at path is not inside a git repository, the `path:` prefix is implied and can be omitted. and of course since the error is about relative paths it works just fine with full paths and works as a workaround ```shell $ nix run nix/2.19.2 -- flake lock path:$PWD warning: creating lock file '/tmp/test/flake.lock': • Added input 'nixpkgs': 'github:NixOS/nixpkgs/0b35753f0128c4a34d6712e60b0a23f893665f31' (2023-11-30) ``` **Steps To Reproduce** 1. Create simple flake ```nix { inputs.nixpkgs.url = "github:NixOS/nixpkgs"; outputs = _: { }; } ``` 2. Try to lock explicitly using `path:.` ```shell $ nix run nix/2.19.2 -- flake lock path:. ``` 3. See error above **Expected behavior** The docs state the following: > path generally must be an absolute path. However, on the command line, it can be a relative path (e.g. `.` or `./foo`) which is interpreted as relative to the current directory. In this case, it must start with `.` to avoid ambiguity with registry lookups (e.g. `nixpkgs` is a registry lookup; `./nixpkgs` is a relative path). but it does not seem to be the case. It is also regression compared to 2.18.1: ```shell $ nix run nix/2.18.1 -- flake lock path:. warning: creating lock file './flake.lock' ``` **Additional context** 1. I was specifically working inside of a git repo with untracked changes that I was trying to quickly test before committing. 2. Tried looking at the git blame, and to me it seems like #9239 might have introduced the issue. Here it seems to assume that the path is always absolute, but I'm not confident enough with my knowledge of the nix code base to be 100% sure. The error might come from elsewhere and I'm just making a fool of myself here. https://github.com/NixOS/nix/blob/3d46fa85c8fcb579bb1756668cba38245d5f174a/src/libfetchers/path.cc#L90-L98 **Priorities** Add :+1: to [issues you find important](https://github.com/NixOS/nix/issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc).
lix-bot added the
bug
imported
labels 2024-03-16 06:44:52 +00:00
jade added the
Area/flakes
label 2024-03-30 00:06:39 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#93
No description provided.