Closed Fuuzetsu closed 1 year ago
Probably something like this enough, but as per #224 I don't really know how to update the tests etc...
diff --git a/crate2nix/templates/Cargo.nix.tera b/crate2nix/templates/Cargo.nix.tera
index 64f8403..73da725 100644
--- a/crate2nix/templates/Cargo.nix.tera
+++ b/crate2nix/templates/Cargo.nix.tera
@@ -125,7 +125,7 @@ rec {
# We can't filter paths with references in Nix 2.4
# See https://github.com/NixOS/nix/issues/5410
src = if (lib.versionOlder builtins.nixVersion "2.4pre20211007")
- then lib.cleanSourceWith { filter = sourceFilter; src = {{crate.source.LocalDirectory.path | safe}}; }
+ then lib.cleanSourceWith { filter = sourceFilter; src = {{crate.source.LocalDirectory.path | safe}}; name = {{crate.crate_name}}; }
else {{crate.source.LocalDirectory.path | safe}};
{%- elif crate.source.Git %}
workspace_member = null;
I guess we don't want crate name but the dir name of the source... whichever, should be easy
I found even more problems with this nix 2.3 codepath: for example, it'll remove .gitignore
from the workspace crates while later versions will not: this is due to current sourceFilter
behaviour...
Rather than trying to keep fixing it, I'm just adding an assert
in our codebase that >= 2.4 is used. So I no longer really care about this ticket either.
crate2nix
generates things like these inCargo.nix
:On
nix
2.3.x and presumably older, this crate ends up depending on its sources (obviously) like so:On modern nix (I'm using 2.9 pre), it looks like this:
The content of
/nix/store/a87gw94pj9l5z1zr4b4bd6hxrcj6y1dg-source
and/nix/store/4i4av9wvdx6djid9phrwqp2vnc2r69pr-tsu-mini-std
is identical! The only thing that's different is the name which changes the hash which then changes hash of everything upstream. I guess since nix 2.4, the../path
syntax gets a proper name aspath
:lib.cleanSourceWith
uses this name if present. I guess on nix 2.3 the name is missing so the"source"
default gets used. I was unable to locate the exact commit which caused the change as there are a lot of these between 2.3.16 and 2.4 though it doesn't matter much anyway.One very simple thing we can do to make the hashes identical again is this:
This makes the source be
/nix/store/4i4av9wvdx6djid9phrwqp2vnc2r69pr-tsu-mini-std
even on nix 2.3 and everything is happy: binary caching keeps working for people on 2.3 and 2.9 all the same.I guess then maybe
crate2nix
should unconditionally (or based on command line flag) insert this attribute with the crate name? This gives consistent results across more versions which seems nice/desirable.