-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Prevent some rebuilds for future Nix reformats #326430
Conversation
This doesn't strike me as a great solution tbh. It just kicks the bucket down the road and will cause rebuilds again when the formatting rules are changed again in the future. |
The |
bd8dae7
to
c05dd3a
Compare
Speaking for the formatting team, we don't expect to have to make any significant changes to the format in the foreseeable future. The only changes to expect soon are bug fixes, which won't change much. So I don't think we need to worry very much about it :) @sternenseemann Thanks, done that in the last commit now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few curious comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh, this is on my list of #208242 things to go make better.
source=${lib.fileset.toSource { | ||
root = ./.; | ||
fileset = lib.fileset.unions [ | ||
(./. + "/${testname}.cmdline") | ||
(./. + "/${testname}.c") | ||
(lib.fileset.maybeMissing (./. + "/${testname}.env")) | ||
]; | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be clearer if extracted to another binding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine, I don't think much is gained from having an intermediate Nix binding (we already assign it to a bash variable here)
src = lib.fileset.toSource { | ||
root = ./local; | ||
fileset = lib.fileset.unions [ | ||
./local/app | ||
./local/CHANGELOG.md | ||
./local/local.cabal | ||
]; | ||
}; | ||
# This prevents the source from depending on the formatting of the ./local/generated.nix file | ||
localRaw = haskell.lib.compose.overrideSrc { | ||
inherit src; | ||
} (haskellPackages.callPackage ./local/generated.nix {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the src = ./.
line in local/generated.nix
is not needed now, right? It can be the same as the src
above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since that's technically a generated file, I think it's cleaner to override the source from here instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's named as such but is in no way generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure it was generated using cabal2nix
, e.g. check see here, but I guess that's not very relevant at this point anyways
Please also tag @NixOS/nix-formatting for PRs touching that topic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not happy about the formatting at all, but I don't want to block the process of implementing formatting, because that would be even worse.
👍 from me.
&& lib.hasAttrByPath [ | ||
"src" | ||
"outputHash" | ||
] value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a nixpkgs-fmt user this feels ugly.
I wonder if this would be ok? I think it's cleaner to use the built-in syntax anyway.
&& lib.hasAttrByPath [ | |
"src" | |
"outputHash" | |
] value; | |
&& (value?src.outputHash); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed this can be simplified and reformatted to just
hasChecksum = value: value ? src.outputHash;
Relevant motto from the RFC:
Bad code does not deserve good formatting.
😆
options.nested.nestedLine30 = lib.mkOption { | ||
type = lib.types.int; | ||
}; | ||
options.nested.nestedLine30 = lib.mkOption { type = lib.types.int; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like my mkOption
s multi-line, consistently.
Will I have to adjust?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this is actually an inconsistency in the formatter that should be fixed, because
options.nested.nestedLine30 = { type = lib.types.int; };
expands to
options.nested.nestedLine30 = {
type = lib.types.int;
};
The same should be done here.
See also this part of the standard
Edit: NixOS/nixfmt#222
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though this is actually less prevalent in practice than it looks like here, because as soon as you have at least two attribute values, it will also get expanded. And effectively all options in NixOS have both a type
and a description
, which makes two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured it might not be as bad.
Sometimes I start out with only a description
or only a type
if it's more "technical" like testing or trying something out.
I do anticipate the other attrs, which is why this stood out to me.
'' | ||
pkgs = import <nixpkgs> { }; | ||
in | ||
pkgs.runCommand "diagnostics-sandbox" { __noChroot = true; } '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to collapse this attrset into a single line format?
This will add a bunch of diff noise when new attrset are added, won't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we'll go for that in the end, but with NixOS/nixfmt#222 (which also fixes your other complaint), this file would look like this instead:
let
pkgs = import <nixpkgs> { };
in
pkgs.runCommand "diagnostics-sandbox"
{
__noChroot = true;
}
''
set -x
# no cache: ${toString builtins.currentTime}
test -d "$(dirname "$out")/../var/nix"
touch $out
''
@roberth Even if the formatting isn't perfect, having a standard enforced formatting is better than the current churn. Considering that these cases you highlighted are somewhat rare, I don't think we need to block on this. We can also improve the formatter and then do another reformatting pass later (which will then be much smaller in diff size!). If you have more feedback about the formatting, it would be best to open issues in https://github.com/NixOS/nixfmt instead btw :) |
As you've read, I agreed with this part.
Unnecessary formatter-induced churn is not ok. If the formatter doesn't behave correctly, or some aspects of it are still in development, don't both users with it.
So I think we should block on this, fix the formatter, and do another pass.
I assume you haven't run nixfmt on the whole repo. |
I'd say we should distinguish between different levels of correctness:
So we have 1 now but probably not 2 or 3. These can arguably never be perfect and take more brainpower to resolve, so it's important to consider the cost/value tradeoff. (And in a twisted way, forcing something imperfect onto people might actually get us more help with improving it :P). But okay, let's reconsider this and either improve this case or have a better justification for not needing to improve it now.
Complete opposite! We've been automatically running nixfmt on the entirety of Nixpkgs already during development of the RFC to help us decide (e.g. see here), and we're continuing to run it on all PRs that change nixfmt (e.g. see here), and of course there's also the treewide reformatting PR that is being worked on recently 😉 |
Ah sorry, I was unclear. I meant to refer to this PR specifically, which I conclude is not tree-wide.
Oh, that was a bit harsh maybe, out of context at least. I meant to refer to your judgement that this may not be the desired behavior. Anyway, I think we're on the same page now, and I'd really like to thank you for the effort you're putting into this! |
@infinisil, any reason not to merge this? |
93f2a29
to
a0427be
Compare
This is a rare case of a Nix file actually ending up in the build result. We reformat this now, causing a rebuild, so that we won't cause a rebuild in the treewide reformatting PR.
This is a rare case of a Nix file actually ending up in the build result. We reformat this now, causing a rebuild, so that we won't cause a rebuild in the treewide reformatting PR.
There's no need to use a Nix file in the path here. By using a different file we won't cause rebuilds when we change the Nix file, in particular also when the Nix file is reformatted.
The source included way more files than it really needed. This commit limits it to exactly those it needs. This also makes sure that no rebuild is necessary when any Nix file changes, in particular useful when we reformat the Nix files.
The generated file sets its own directory as the source, including the generated file itself, which causes rebuilds when that file is reformatted. We can avoid this by overriding the source with a filtered version and using that throughout the tests. See NixOS#320572 for more context
And fix locations to not break the test. This is a rare case where another change is required after formatting. We do this in a separate commit so that we don't need to do it in the treewide reformatting PR.
a0427be
to
8f425c2
Compare
@roberth's feedback in #326430 (comment) and #326430 (comment) is now addressed with NixOS/nixfmt#224, force pushed to make use of it: diff |
Description of changes
This is motivated by #322537, which I'd like to get close to 0 rebuilds, although due to the nature of that PR not formatting files modified by other PRs, me making this PR makes the other PR avoid these files entirely, so this PR doesn't have to be merged before the other one.
This PR either avoids Nix files ending up in the build result (so that changing them won't cause rebuilds), or formats Nix files in advance, so that they don't need to be changed in the treewide reformat.
This is effectively part of #301014
Things done
This work is sponsored by Antithesis ✨
Add a 👍 reaction to pull requests you find important.