Skip to content

Commit

Permalink
Handle final handling for old lock files with improper narHash fields
Browse files Browse the repository at this point in the history
This fixes the error

  '{"__final":true,"lastModified":1686592866,"narHash":"sha256-riGg89eWhXJcPNrQGcSwTEEm7CGxWC06oSX44hajeMw","owner":"nixos","repo":"nixpkgs","rev":"0eeebd64de89e4163f4d3cf34ffe925a5cf67a05","type":"github"}' resulted in different input
  '{"__final":true,"lastModified":1686592866,"narHash":"sha256-riGg89eWhXJcPNrQGcSwTEEm7CGxWC06oSX44hajeMw=","owner":"nixos","repo":"nixpkgs","rev":"0eeebd64de89e4163f4d3cf34ffe925a5cf67a05","type":"github"}'

in flake-regressions/tests/nix-community/patsh/0.2.1 (note the lack of
a trailing '=' in the NAR hash in the lock file).
  • Loading branch information
edolstra committed Nov 1, 2024
1 parent 4fcd458 commit 5c49d0b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,22 @@ void InputScheme::checkLocks(const Input & specified, const Input & final) const
final.to_string(), *prevRevCount);
}

if (specified.isFinal() && specified.attrs != final.attrs)
throw Error("fetching final input '%s' resulted in different input '%s'",
attrsToJSON(specified.attrs), attrsToJSON(final.attrs));
/* If the original input is final, then the result must be the
same (i.e. cannot remove, add or change fields. */
if (specified.isFinal()) {

/* Backwards compatibility hack: we had some lock files in the
past that 'narHash' fields with incorrect base-64
formatting (lacking the trailing '=', e.g. 'sha256-ri...Mw'
instead of ''sha256-ri...Mw='). So fix */
auto specified2 = specified;
if (auto prevNarHash = specified2.getNarHash())
specified2.attrs.insert_or_assign("narHash", prevNarHash->to_string(HashFormat::SRI, true));

if (specified2.attrs != final.attrs)
throw Error("fetching final input '%s' resulted in different input '%s'",
attrsToJSON(specified2.attrs), attrsToJSON(final.attrs));
}
}

std::pair<ref<SourceAccessor>, Input> Input::getAccessor(ref<Store> store) const
Expand Down

0 comments on commit 5c49d0b

Please sign in to comment.