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/activation: Add pre-switch checks #236375

Merged
merged 1 commit into from
Nov 23, 2024

Conversation

jmbaur
Copy link
Contributor

@jmbaur jmbaur commented Jun 6, 2023

Description of changes

Add an option for shell script fragments that are ran before switching to a new NixOS system configuration (pre installation of bootloader or system activation). Also add a new subcommand for
switch-to-configuration called "check" that will cause the program to always exit after checks are ran. If the NO_CHECK environment variable is set to 1 during switch, the checks are skipped.

Fixes #169820

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.11 Release Notes (or backporting 23.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.

@jmbaur jmbaur requested a review from dasJ as a code owner June 6, 2023 23:43
@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 Jun 6, 2023
@jmbaur jmbaur force-pushed the pre-switch-checks branch from efe665e to 66c452b Compare June 7, 2023 18:07
@ktrinh-anduril
Copy link
Contributor

any movements on this? This is a pretty important feature to have especially since NixOS is on so many targets now

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/2604

Copy link
Contributor

@ktrinh-anduril ktrinh-anduril left a comment

Choose a reason for hiding this comment

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

lgtm

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Sep 7, 2023
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/2678

@jmbaur jmbaur force-pushed the pre-switch-checks branch from a915366 to a1ea206 Compare January 23, 2024 22:13
@jmbaur jmbaur force-pushed the pre-switch-checks branch from a1ea206 to c58227f Compare January 24, 2024 20:29
@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Mar 8, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 22, 2024
@jmbaur jmbaur force-pushed the pre-switch-checks branch 2 times, most recently from 5564302 to 3503749 Compare July 18, 2024 02:49
@jmbaur
Copy link
Contributor Author

jmbaur commented Jul 18, 2024

@ofborg test switchTest switchTestNg

@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 18, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 10, 2024
@jmbaur
Copy link
Contributor Author

jmbaur commented Nov 19, 2024

@ofborg test switchTest switchTestNg

@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 20, 2024
@ConnorBaker ConnorBaker added the backport release-24.11 Backport PR automatically label Nov 21, 2024
Copy link
Contributor

@ConnorBaker ConnorBaker left a comment

Choose a reason for hiding this comment

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

This should have been merged ages ago.

EDIT: Looks like the recent rebase broke something.

Copy link
Contributor

@ConnorBaker ConnorBaker left a comment

Choose a reason for hiding this comment

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

switchTestNg fails:

vm-test-run-switch-test> machine # [   12.400333] nixos[1057]: finished switching to system configuration /nix/store/9658x4bx9cn567a04776bg9qwsbw95qr-nixos-system-other-test
vm-test-run-switch-test> (finished: must succeed: /nix/store/69vika84p4i1qpgvnqaqrmnd2hqr38dh-stderr-runner /nix/store/9658x4bx9cn567a04776bg9qwsbw95qr-nixos-system-other-test/bin/switch-to-configuration test, in 1.23 seconds)
vm-test-run-switch-test> subtest: pre-switch checks
vm-test-run-switch-test> machine: must succeed: /nix/store/69vika84p4i1qpgvnqaqrmnd2hqr38dh-stderr-runner /nix/store/9658x4bx9cn567a04776bg9qwsbw95qr-nixos-system-other-test/bin/switch-to-configuration check
vm-test-run-switch-test> machine # Usage: switch-to-configuration [check|switch|boot|test|dry-activate]
vm-test-run-switch-test> machine # check:        run pre-switch checks and exit
vm-test-run-switch-test> machine # switch:       make the configuration the boot default and activate now
vm-test-run-switch-test> machine # boot:         make the configuration the boot default
vm-test-run-switch-test> machine # test:         activate the configuration, but don't make it the boot default
vm-test-run-switch-test> machine # dry-activate: show what would be done if this configuration were activated
vm-test-run-switch-test> machine # 
vm-test-run-switch-test> machine: output:
vm-test-run-switch-test> Test "pre-switch checks" failed with error: "command `/nix/store/69vika84p4i1qpgvnqaqrmnd2hqr38dh-stderr-runner /nix/store/9658x4bx9cn567a04776bg9qwsbw95qr-nixos-system-other-test/bin/switch-to-configuration check` failed (exit code 1)"
vm-test-run-switch-test> cleanup
vm-test-run-switch-test> kill machine (pid 9)
vm-test-run-switch-test> qemu-kvm: terminating on signal 15 from pid 6 (/nix/store/px2nj16i5gc3d4mnw5l1nclfdxhry61p-python3-3.12.7/bin/python3.12)
vm-test-run-switch-test> kill vlan (pid 7)
vm-test-run-switch-test> (finished: cleanup, in 0.01 seconds)
error: builder for '/nix/store/541460imnjxn66pvfx3jiqp1gd43k9l0-vm-test-run-switch-test.drv' failed with exit code 1

Add an option for shell script fragments that are ran before switching
to a new NixOS system configuration (pre installation of bootloader or
system activation). Also add a new subcommand for
switch-to-configuration called "check" that will cause the program to
always exit after checks are ran.
Copy link
Contributor

@ConnorBaker ConnorBaker left a comment

Choose a reason for hiding this comment

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

Fix applied in latest, tests pass.

@wegank wegank added the 12.approvals: 2 This PR was reviewed and approved by two reputable people label Nov 22, 2024
@ConnorBaker ConnorBaker merged commit 4e54bbd into NixOS:master Nov 23, 2024
32 checks passed
Copy link
Contributor

Successfully created backport PR for release-24.11:

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: 1-10 10.rebuild-linux: 1-10 12.approvals: 2 This PR was reviewed and approved by two reputable people backport release-24.11 Backport PR automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

switch-to-configuration assertions
5 participants