-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Superfluous use of finalAttrs.{pname,version}
introducing overriding traps
#310373
Comments
@oxalica in description
i think you mean
|
|
This is more of a design flaw in hash name itself. It will happen during override and update. See NixOS/rfcs#171 |
I would be interested in some kind of function based src attribute. Something like this: stdenv.mkDerivation {
pname = "foo";
version = "1.2.3";
srcHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
srcFor = { version, hash, ... }: fetchFromGitHub {
owner = "foobar";
repo = "foo";
rev = "refs/tags/${version}";
inherit hash;
};
}; stdenv.mkDerivation {
pname = "foo";
version = "1.2.3";
srcRev = "f853c074c86ce58df79fab3cfb80ae69133a31e1";
srcHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
srcFor = { rev, hash, ... }: fetchFromGitHub {
owner = "foobar";
repo = "foo";
inherit rev hash;
};
}; Where src = attrs.src or srcFor = {
inherit (finalAttrs) version;
inherit (stdenv) system;
rev = finalAttrs.srcRev or null;
hash = finalAttrs.srcHash;
}; A bigger shortcoming of this would be that it only works for derivations that need a single source. |
in my humble opinion,
|
I think the root cause for this issue is that maintainers do not want to repeat the version number for Maybe we can try to embed version numbers into Example: {
stdenv,
fetchFromGitHub,
src ? fetchFromGitHub {
owner = "foobar";
repo = "foo";
version = "1.2.3";
tagPrefix = "v";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
},
}:
stdenv.mkDerivation {
pname = "foobar";
inherit (src) version;
inherit src;
} Obviously we would have to implement In the case of rev = if rev == null then
"refs/tags/${toString tagPrefix}${version}"
else rev; I think this could be a viable way forward, as it makes overriding sources much easier, while directly tying |
i believe we should be thinking of as an alternative - and still keeping with the idea of using inputs - why not place {
stdenv,
fetchFromGitHub,
version ? "0.1.0",
src ? fetchFromGitHub {
owner = "foobar";
repo = "foo";
# here we can reuse `version` like before - or not! `src` and `version` are no longer tied
# but both are still reusable, overridable, and accessible
rev = "v${version}";
hash = "...";
}
}:
stdenv.mkDerivation {
pname = "foo";
inherit version src;
# ...
} i don't think this pattern is exactly new either, as i've seen (and used) it a good number of times in flakes to pass |
This should be a bit more polished. |
But then, when you override the I agree with @Scrumplex's examples above, putting Also my #316668 seems very relevant here, given it introduces a bunch of |
Quoted from @eclairevoyant, original link #293452 (comment) So it's still simpler to use |
Well I am doing some experiments, and indeed it is way superior: |
It almost got me1, but yes, this do work as intended and can simplify the overriding code, as long as you already known this issue and check all usages of However, the main point in the issue title still stands. It's introducing a trap when under-overriding
As a Footnotes
|
Then let's add |
In all seriousness a problem of this nature is a genuine possibility, but prefixing simply named non-package arguments with an underscore, e.g. |
Yeah, we discussed in this issue #309892 |
How does this work when using |
Overriding lists doesn't work very well. |
Describe the bug
There are many code adopting
finalAttrs
to reuse variables, rather than provide an overridable option. Specifically, usingfinalAttrs.version
andfinalAttrs.pname
insrc =
is incorrect since overriding them will NOT cause it to automatically use the source from new name/version, because the hash literal is still unchanged. It will be a silent incorrect behavior when the FOD is cached locally (reusing the old one), and will be a hash-mismatch error if it's not, both causing a hard-to-debug trap.There are also usages in build script like
cp -r ${finalAttrs.pname}-${finalAttrs.version}/* $out
, which is still incorrect for.overideAttrs { pname = "foo-patched"; }
use case.A quick search shows that there are even more incorrect usages than correct usages on the first glance:
finalAttrs.version
: https://github.com/search?q=finalAttrs.version&type=codefinalAttrs.pname
: https://github.com/search?q=finalAttrs.pname&type=codeExpected usage
Users should always override
src
manually, thus making a overridable illusion viafinalAttrs
is more misleading than not supporting it at all.It seems the even the good old
rec
is more correct for thepname
usages because it's fixed at parse time and will not be overridden anyway, which is the intended behavior forrepo
andinstallPhase
. 🤔Inspired by #277994. cc @AndersonTorres
Add a 👍 reaction to issues you find important.
The text was updated successfully, but these errors were encountered: