Skip to content

darwin.builder: Fix gratuitous rebuilds#207902

Merged
domenkozar merged 1 commit intoNixOS:masterfrom
Gabriella439:gabriella/fix_rebuilds
Dec 27, 2022
Merged

darwin.builder: Fix gratuitous rebuilds#207902
domenkozar merged 1 commit intoNixOS:masterfrom
Gabriella439:gabriella/fix_rebuilds

Conversation

@Gabriella439
Copy link
Contributor

See the discussion starting here:

#206951 (comment)

The darwin.builder derivation had a gratuitous dependency on the current Nixpkgs revision due to
config.system.nixos.revision. Setting the revision explicitly to null fixes this problem and prevents the derivation from being rebuilt on every change to Nixpkgs.

I verified that this change works by testing that nix-instantiate --attr darwin.builder produces
the exact same derivation before and after a trivial commit based on this branch.

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

See the discussion starting here:

NixOS#206951 (comment)

The `darwin.builder` derivation had a gratuitous dependency
on the current Nixpkgs revision due to
`config.system.nixos.revision`.  Setting the revision explicitly
to null fixes this problem and prevents the derivation from being
rebuilt on every change to Nixpkgs.
@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Dec 27, 2022
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Dec 27, 2022
@Gabriella439 Gabriella439 mentioned this pull request Dec 27, 2022
13 tasks
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Dec 27, 2022
system.stateVersion = "22.05";
system = {
# To prevent gratuitous rebuilds on each change to Nixpkgs
nixos.revision = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter if this is null instead of a string?

{ nixpkgs ? { outPath = (import ../../lib).cleanSource ../..; revCount = 1234; shortRev = "abcdef"; revision = "0000000000000000000000000000000000000000"; }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's totally valid for it to be null, but not sure if we'd prefer that or a dummy string:

nixos.revision = mkOption {
internal = true;
type = types.nullOr types.str;
default = trivial.revisionWithDefault null;
description = lib.mdDoc "The Git revision from which this NixOS configuration was built.";
};

Copy link
Contributor Author

@Gabriella439 Gabriella439 Dec 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to nix-diff, the only thing that this option affects is the output of the nixos-version --json command. If you set it to null then the output is:

{"nixosVersion":"23.05pre-git"}

… whereas if you were to set it to a dummy revision then the output would be:

{"nixosVersion":"23.05pre-git","nixpkgsRevision":"0000000000000000000000000000000000000000"}

I personally feel that setting it to null is the cleaner solution rather than generating a sentinel value that is invalid

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null sgtm. It seems to be the better solution, considering the intent of the type. If it breaks something, we'd learn what to fix, which is great.

# To prevent gratuitous rebuilds on each change to Nixpkgs
nixos.revision = null;

stateVersion = "22.05";
Copy link
Contributor

@zowoq zowoq Dec 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how the nixos tests set stateVersion, can we do the same here?

system.stateVersion = lib.mkDefault lib.trivial.release;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(IMO, this should be a separate commit.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config should be independent of stateVersion. It's within reach

I'll merge the uncontroversial bit, so that it can be made to work with disabledModules instead of the two more or less breaking changes in that PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can fix the stateVersion, but I feel like that should be a separate PR, which I'm happy to do afterwards

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, setting the stateVersion to match the current release is not necessarily the correct behavior here. If you were to do that then any necessary migrations would never get applied if the user updates their nixpkgs pin in order to upgrade the builder. The stateVersion is not supposed to change after the machine is deployed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, and I don't think a bare NixOS should depend on stateVersion for any such migrations, which is why I've opened #207958 as an alternative.

@github-actions
Copy link
Contributor

Successfully created backport PR #207979 for release-22.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: darwin Running or building packages on Darwin 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants