Skip to content

Enabling lfs for flake calculates incorrect narHash #15350

@BloodStainedCrow

Description

@BloodStainedCrow

Describe the bug

I have a flake.nix, which enables git-lfs for itself:

inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    nixpkgs-codium.url = "github:nixos/nixpkgs?ref=91c9a64ce2a84e648d0cf9671274bb9c2fb9ba60";
    [...]
  };
inputs.self.lfs = true;
outputs = [...];

After adding it to the inputs of another flake:

inputs = {
  factory_game = {
    inputs.nixpkgs.follows = "nixpkgs";
    url = "git+https://github.com/BloodStainedCrow/FactoryGame.git?ref=master";
  };
};

(Note: Using git+ instead of github: since the latter does not support lfs)

and then building this flake, immediately results in a narHash mismatch:

Full error ``` error: mismatch in field 'narHash' of input '{"__final":true,"lastModified":1771523185,"lfs":true,"narHash":"sha256-gEG1QSb7jOx8WFUXHyo0shXSK7JsKrQkxvFhoazmLwE=","ref":"master","rev":"0ffa7000cd403156dc2236296d29d738fc10d8e4","revCount":304,"shallow":true,"type":"git","url":"https://github.com/BloodStainedCrow/FactoryGame.git"}', got '{"__final":true,"lastModified":1771523185,"lfs":true,"narHash":"sha256-2Z42B+0IgrugH15YeLn64gc53v598ogSNsDBxhh8WwU=","ref":"master","rev":"0ffa7000cd403156dc2236296d29d738fc10d8e4","revCount":304,"shallow":true,"type":"git","url":"https://github.com/BloodStainedCrow/FactoryGame.git"} ```

My guess is that the initial calculation does not take lfs into account.

This is fixable by adding to &lfs=1 the input url.
Ideally the user of a flake should not need to know whether it is using git-lfs at all, but if this is working as intended, nix should at least show a better error message, hinting users to the correct solution.

Steps To Reproduce

Add

factory_game = {
    inputs.nixpkgs.follows = "nixpkgs";
    url = "git+https://github.com/BloodStainedCrow/FactoryGame.git?ref=master";
};

to the input of a flake.
Try to build this flake.
Get narHash mismatch

Expected behavior

The flake should build.
Or at least it should give a better error message, i.e.
narHash mismatch. input flake uses git-lfs, but input url does use lfs. Try adding '&lfs=1' to the input git url

Metadata

nix-env (Nix) 2.31.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions