Repository navigation
nixos/switch-to-configuration: add new implementation - #308801
Conversation
211f98e to
36f7214
Compare
6e2c9bb to
deee302
Compare
|
@ofborg test switchTestNg |
deee302 to
8e920d6
Compare
|
@ofborg test switchTestNg |
|
Stellar work, thank you! I haven't looked at the Rust code in detail yet but scrolling over it quickly looked great. (Edit: The lack of One thing to keep in mind is the existence of #307562. Also, pretty much the last thing I wanted to do with Perl STC (apart from getting the sockets to work) was to port the fstab handling to the same logic the .mount unit uses. |
I did see that issue. I haven't tested against #307562 (comment) yet, but I'll do so shortly and paste the results. I started this PR as a 1-to-1 port of the perl code, so I'm "hoping" that this issue is also present in this PR, then they can be addressed together.
That sounds great, I believe the logic was if any of the mount options change (and nothing else changed), reload the unit, otherwise restart it?
Definitely no rush |
There was a problem hiding this comment.
We should definitely split this file into multiple smaller ones.
8e920d6 to
6c333a3
Compare
|
@ofborg test switchTestNg |
6c333a3 to
1391794
Compare
|
We need to be very careful about rewriting fundamental parts of NixOS in Rust, because we're going to break NixOS on platforms that Rust doesn't support, but do have some committed NixOS users, like MIPS, which had a lot of work put into it over the last couple of years. (Most scripting languages don't have this problem, so something like Python might be a better fit, but compiled languages, especially those using LLVM, will.) |
This adds an implementation of switch-to-configuration that allows for
closer interaction with the lifecycle of systemd units by using DBus
APIs directly instead of using systemctl. It is disabled by default, but
can be enabled by specifying `{ system.switch = { enable = false; enableNg = true; }; }`.
1391794 to
32bf051
Compare
|
@alyssais totally agree, though I would assume LLVM would give us great platform support? After fixing the derivation (using dbus interface definitions from |
|
Rust supports cross-compilation to more platforms than it supports running the compiler on, but the latter is what would be important for switch-to-configuration. Otherwise, we'd be completely removing the ability to switch configurations on those systems, since that system wouldn't be cross-compiled. So systems supported by Nixpkgs that would potentially lose out on being able to self-host NixOS from this change would be: Some of these, like microblaze and s390, likely can't even build all of NixOS anyway. MIPS definitely has actual users (one use case I think is NixOS on a router, but I don't really know) and I'm pretty sure armv7 does too, although that might be armv7l and it wouldn't surprise me if most of those systems were cross-compiled. |
|
I think MIPS64 is the main one to worry about. |
|
Is this even something to worry about? Afaik, NixOS has no official MIPS64 support and for these platforms I honestly think it would be okay to require cross-compilation. Also, while the new implementation is there now, it's still opt-in and I don't see why we wouldn't keep the old variant around for a bit after it has be come the default. This would also give the LLVM people more time (years probably) to fix the MIPS targets if they even intend doing so. |
|
It depends whether this would break anything for anybody in practice. I've drawn attention to this PR in places where users using those platforms are likely to be reachable (#exotic:nixos.org, #networking:nixos.org), and nobody has come forward, so it seems like that's a no, and so that's fine. It's just important to make sure of that when making this kind of decision. |
|
As written a bunch of times above, it's probably fine to introduce this additionally, even flip the default at some point. rustc platform support is gonna catch up at some point, and we can still keep the perl script around for these usecases - if people for these architectures really need it, they at some point need to step up with maintainership of the perl flavour. Having the activation script in something not-perl is such a long-term quality of life improvement, and empowers more people to fix it, so I'm heavily in favor of this. Thanks ❤️ |
|
Let's get this in - this is behind an explicit feature flag, so a no-op for anyone not explicitly enabling it. |
Fewer interpreters to reduce closure size, I hope you mean? :) Anyway, good effort on the rewrite @jmbaur! |
|
Using |
I think the perl implementation also hangs if it has to wait for I include the following in my config to make the service log which interface it's waiting on: |
Not for me, I tested it on both and the switch happened on the Perl implementation but hangs on this implementation. |
|
Made an issue here |
|
First: Great. I think the Perl-written key parts of NixOS are some of the weakest parts of it: Very difficult to read/understand, very easy to footgun. Now just Next: I recommend to make the following improvements to make this whole thing more likely to succeed:
|
Well, I just made a WIP port of |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
@jmbaur Did you ever get around to this? I am quite certain this issue is still present in I filed a draft PR: CC @dasJ |
| let distro_id_re = Regex::new(format!("^\"?{}\"?$", distro_id).as_str()) | ||
| .context("Invalid regex for distro ID")?; | ||
|
|
||
| // This is a NixOS installation if it has /etc/NIXOS or a proper /etc/os-release. |
There was a problem hiding this comment.
if it has /etc/NIXOS or a proper /etc/os-release
@jmbaur This says OR. If it has only one of them, is it still a NixOS installation?
If yes, the code is wrong:
&& !os_release.... short-circuiting && is implemented below, but
let os_release = parse_os_release().context("Failed to parse os-release")?;unconditonally fails if /etc/os-release doesn't exist.
The original Perl implemented a proper OR:
die "This is not a NixOS installation!\n" unless
-f "/etc/NIXOS" || (read_file("/etc/os-release", err_mode => 'quiet') // "") =~ /ID=nixos/s;This change broke deploying with NixOps (in my case, 1.7) to Hetzner, which only creates /etc/NIXOS in the target machine's /mnt chroot, before calling switch-to-configuration.
There was a problem hiding this comment.
The comment
// This is a NixOS installation if it has /etc/NIXOS or a proper /etc/os-release.
said OR but the code implemented AND because it errored out
if `/etc/os-release` did not exist.
This was a regression from the Perl-to-Rust rewrite.
See NixOS#308801 (review)
Assisted-by: Claude Opus 4.8 in Zoo Code, human comment cleanup
The comment
// This is a NixOS installation if it has /etc/NIXOS or a proper /etc/os-release.
said OR but the code implemented AND because it errored out
if `/etc/os-release` did not exist.
This was a regression from the Perl-to-Rust rewrite.
See NixOS#308801 (review)
Assisted-by: Claude Opus 4.8 in Zoo Code, human comment cleanup
(cherry picked from commit e022b86)
The comment
// This is a NixOS installation if it has /etc/NIXOS or a proper /etc/os-release.
said OR but the code implemented AND because it errored out
if `/etc/os-release` did not exist.
This was a regression from the Perl-to-Rust rewrite.
See NixOS#308801 (review)
Assisted-by: Claude Opus 4.8 in Zoo Code, human comment cleanup
Description of changes
This adds an implementation of switch-to-configuration that allows for closer interaction with the lifecycle of systemd units by using DBus APIs directly instead of using systemctl. It is disabled by default, but can be enabled by specifying
{ system.switch = { enable = false; enableNg = true; }; }.The goal of this change is to provide an implementation of switch-to-configuration that is compatible (bug-for-bug, feature-for-feature) with the current perl script. This means that it is expected that all current NixOS VM tests under
./nixos/testswill pass without any of the test scripts being modified. Assuming the changes here land, hopefully this implementation is found to be easier to maintain and more testable, allowing for easier modification of it in the future and eventually deprecation of the perl script.Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.