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-rebuild-ng: re-exec in the current version if re-exec to a new one fails #366271

Merged
merged 1 commit into from
Dec 20, 2024

Conversation

thiagokokada
Copy link
Contributor

@thiagokokada thiagokokada commented Dec 18, 2024

This closes the last gap for issue #166499 (comment).

The idea here is that if we try to re-exec and it fails (for example, in case we are building for a CPU arch that our current system doesn't support), Python raise a OSError like below where I am trying to load nix from aarch64-darwin in x86_64-linux:

$ file /nix/store/c4kw7qpffsq7vd6brwgkfnglvj85ivqk-nix-2.24.11/bin/nix
/nix/store/c4kw7qpffsq7vd6brwgkfnglvj85ivqk-nix-2.24.11/bin/nix: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|PIE>

$ python
Python 3.12.7 (main, Oct  1 2024, 02:05:46) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.execv("/nix/store/c4kw7qpffsq7vd6brwgkfnglvj85ivqk-nix-2.24.11/bin/nix", ["nix"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 8] Exec format error

So we capture this (or any other exception really) and re-exec to the current version if the new one fails.

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 the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Dec 18, 2024
Copy link
Contributor Author

@thiagokokada thiagokokada left a comment

Choose a reason for hiding this comment

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

@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/4977

@thiagokokada
Copy link
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 366271


x86_64-linux

✅ 2 packages built:
  • nixos-rebuild-ng
  • nixos-rebuild-ng.dist

@thiagokokada
Copy link
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 366271


aarch64-darwin

✅ 2 packages built:
  • nixos-rebuild-ng
  • nixos-rebuild-ng.dist

@thiagokokada
Copy link
Contributor Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 366271


x86_64-darwin

✅ 2 packages built:
  • nixos-rebuild-ng
  • nixos-rebuild-ng.dist

Copy link
Contributor

@r-vdp r-vdp left a comment

Choose a reason for hiding this comment

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

Diff LGTM!

@thiagokokada thiagokokada merged commit dd32ac7 into NixOS:master Dec 20, 2024
50 of 51 checks passed
@thiagokokada thiagokokada deleted the catch-reexec-errors branch December 20, 2024 10:07
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 10.rebuild-darwin: 1-10 10.rebuild-darwin: 1 10.rebuild-linux: 1-10 10.rebuild-linux: 1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants