Skip to content
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

nixos: Cut off virtualisation.vmVariant.virtualisation.vmVariant #390717

Merged
merged 1 commit into from
Mar 21, 2025

Conversation

roberth
Copy link
Member

@roberth roberth commented Mar 17, 2025

This produced an unnecessarily infinitely deep config tree, which is troublesome for configuration diffing.

The "cut off" option can be written to, but not read from. Being written to is important, because it allows users to conveniently define vmVariant config without having to check isVmVariant.

There's a small chance that someone reads from vmVariant config in their normal config, and for them it will not be possible to evaluate with nixos-rebuild build-vm anymore.

If this is a problem, we could perhaps make the vmVariant root appear instead of the mkSinkUndeclaredOptions error. This could be done using mkOption apply.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • 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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 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
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@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 Mar 17, 2025
@roberth roberth force-pushed the vmvariant-no-nesting branch from f1d462b to 656c2f4 Compare March 17, 2025 17:45
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Mar 17, 2025
@roberth
Copy link
Member Author

roberth commented Mar 17, 2025

@ofborg test nixos-rebuild-specialisations nixos-rebuild-specialisations-ng

@github-actions github-actions bot added 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux and removed 10.rebuild-linux: 1-10 labels Mar 18, 2025
Copy link
Contributor

@aforemny aforemny left a comment

Choose a reason for hiding this comment

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

LGTM!

The following tests were successful to my expectation:

nix-build $(nix-instantiate --expr 'let inherit ((import ./nixos {
  configuration = { modulesPath, ... }: {
    imports = [ "${modulesPath}/installer/cd-dvd/installation-cd-minimal.nix" ];
    config = {
      virtualisation.vmVariant.networking.hostName = "vm";
    };
  };
}).config.system.build) toplevel vm vmWithBootLoader; in [ toplevel vm vmWithBootLoader ]')
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/sfr7grrdh5v4y978q492qvphvgd828d4-nixos-system-nixos-25.05pre-git
/nix/store/ihxssrwczgqnrr2x69illciai2d3j8ws-nixos-vm
/nix/store/zps0bk3wk24nx474ddm8sfw8cqp4ax99-nixos-vm
nix-instantiate --eval --strict --expr 'let inherit (import ./nixos {
  configuration = { modulesPath, ... }: {
    config = {
      virtualisation.vmVariant.networking.hostName = "vm";
    };
  };
}) config; in [ config.networking.hostName config.virtualisation.vmVariant.networking.hostName ]'
[ "nixos" "vm" ]
nix-instantiate --eval --strict --expr 'let inherit (import ./nixos {
  configuration = { modulesPath, ... }: {
    config = {
      virtualisation.vmVariant.networking.hostName = "vm";
    };
  };
}) config; in config.virtualisation.vmVariant.virtualisation.vmVariant'
error: virtualisation.vmVariant*.virtualisation.vmVariant is not supported

PS. I rebased onto master before testing.

@@ -2,6 +2,7 @@
config,
extendModules,
lib,
specialArgs,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is now unused! :-)

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Mar 19, 2025
Comment on lines 836 to 846
nixos-rebuild-build-vm-image-script = callTest {
test =
(pkgs.nixos { nixpkgs.hostPlatform = pkgs.stdenv.hostPlatform; })
.config.virtualisation.vmVariant.system.build.vm;
};
nixos-rebuild-build-vm-with-bootloader-image-script = callTest {
test =
(pkgs.nixos { nixpkgs.hostPlatform = pkgs.stdenv.hostPlatform; })
.config.virtualisation.vmVariantWithBootLoader.system.build.vmWithBootLoader;
};
Copy link
Member

Choose a reason for hiding this comment

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

Since #391021 has been merged these seem extraneous.

@roberth roberth force-pushed the vmvariant-no-nesting branch 2 times, most recently from fd778ef to 5b9533d Compare March 20, 2025 22:26
This produced an unnecessarily infinitely deep config tree.

The "cut off" option can be written to, but not read from.
Being written to is important, because it allows users to
conveniently define vmVariant config without having to check
isVmVariant.

There's a small chance that someone *reads* from vmVariant config
in their normal config, and for them it will not be possible
to evaluate with `nixos-rebuild build-vm` anymore.

If this is a problem, we could perhaps make the vmVariant root
appear instead of the `throw` error.
This could also be done using mkOption apply.
@github-actions github-actions bot added 10.rebuild-linux: 1-10 and removed 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Mar 20, 2025
@roberth roberth force-pushed the vmvariant-no-nesting branch from 5b9533d to 9aab8b8 Compare March 20, 2025 22:32
@roberth
Copy link
Member Author

roberth commented Mar 20, 2025

@ofborg test vm-variant

@wegank wegank added 12.approvals: 2 This PR was reviewed and approved by two reputable people and removed 12.approvals: 1 This PR was reviewed and approved by one reputable person labels Mar 21, 2025
@roberth roberth merged commit 202ac0e into NixOS:master Mar 21, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 12.approvals: 2 This PR was reviewed and approved by two reputable people
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants