Skip to content

nixos/systemd-nspawn: Refactor options and output - #512577

Merged
RossSmyth merged 1 commit into
NixOS:masterfrom
m1cr0man:rfc108-nspawn
Oct 26, 2026
Merged

RossSmyth merged 1 commit into
NixOS:masterfrom
m1cr0man:rfc108-nspawn

Conversation

@m1cr0man

@m1cr0man m1cr0man commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Part of breaking up #216025

This PR comprises of three main changes:

  • Writing individual units to /etc/systemd/nspawn instead of making the entire directory a derivation (and thus symlink to the nix store), so that extra units can be added ad-hoc.
  • Add systemd.nspawn.unit property which mimics systemd.unit.text but is the actual unit file instead, which in imperative container generation avoids needing to evaluate the entirety of environment.etc to get a single nspawn unit.
  • RFC42 refactor of options.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

@m1cr0man
m1cr0man requested a review from a team April 22, 2026 23:04
@m1cr0man m1cr0man self-assigned this Apr 22, 2026
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 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/` 6.topic: systemd Software suite that provides an array of system components for Linux operating systems. labels Apr 22, 2026
@m1cr0man m1cr0man changed the title Accommodate out of band nspawn units nixos/systemd-nspawn: Accommodate out of band nspawn units Apr 23, 2026
@m1cr0man
m1cr0man requested review from Ma27 and fpletz April 25, 2026 12:42
@m1cr0man
m1cr0man requested review from ElvishJerricco and nikstur May 6, 2026 19:43

@Lyndeno Lyndeno left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Untested on my end, but looks sound

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Jun 20, 2026
@m1cr0man m1cr0man changed the title nixos/systemd-nspawn: Accommodate out of band nspawn units nixos/systemd-nspawn: Refactor options and output Jul 4, 2026
@m1cr0man
m1cr0man requested review from ElvishJerricco and Ma27 July 4, 2026 18:49
@m1cr0man

m1cr0man commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

I built nixosTests.systemd-nspawn-configfile and nixosTests.systemd-machinectl to verify this change.

@nixpkgs-ci nixpkgs-ci Bot added 2.status: merge conflict This PR has merge conflicts with the target branch 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. 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. labels Jul 4, 2026
@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 3+ This PR was reviewed and approved by three or more persons. label Oct 13, 2026

@Ma27 Ma27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Without having tested it (hence no approval), looks sensible to me 👍

@m1cr0man

Copy link
Copy Markdown
Contributor Author

Thanks @Ma27 . Still need approval from a merger/maintainer though.

Just rebased.

@nixpkgs-ci nixpkgs-ci Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for contributing to the documentation.

Follow the documentation style guide, especially:

  • Show, don’t tell. Start with a minimal working example. Explain after the code.
  • Avoid meta-commentary. Don’t write "This section explains how to…".
  • Use present tense, imperative mood, and active voice. For example: "Run the command," not "The user should run the following command."
  • Avoid vague references like "this" when the referent is unclear. Write "This command creates a folder," not "This will create a folder."
  • Be direct. Avoid "should", "might", "typically", and "usually".
  • Cut filler words like "simply", "just", "easily", and "basically". Use "to" instead of "in order to".

For larger changes, such as adding or removing whole sections, ask the NixOS documentation team for review.

@nixpkgs-ci nixpkgs-ci Bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Oct 24, 2026
@axodentally

Copy link
Copy Markdown
Contributor

I guess this PR introduces a breaking change, so as per the release schedule (#567567), this will probably not make it into 26.11 anymore.
But after 2026-11-16 breaking changes can be merged again. At this point, the release notes need to be updated for the new release.

I really hope we can get this merged soon!

@m1cr0man

Copy link
Copy Markdown
Contributor Author

Well, I guess 3 weeks on top of 3.75 years is not going to hurt.

@m1cr0man

Copy link
Copy Markdown
Contributor Author

I guess this PR introduces a breaking change

Wait, no it doesn't.

This change is backwards compatible thanks to the option renames. Existing nspawn configs would continue to function but would just raise a warning.

Comment thread nixos/tests/all-tests.nix Resolved
@RossSmyth

Copy link
Copy Markdown
Contributor

Ran nixosTests.systemd-nspawn, and it failed with:

vm-test-run-systemd-nspawn> !!! Test "renamed options generate the expected .nspawn file" failed with error: "missing 'Boot=1' in:
vm-test-run-systemd-nspawn> [Exec]
vm-test-run-systemd-nspawn> Boot=true
vm-test-run-systemd-nspawn>
vm-test-run-systemd-nspawn>
vm-test-run-systemd-nspawn> [Files]
vm-test-run-systemd-nspawn> Bind=/home/alice
vm-test-run-systemd-nspawn>
vm-test-run-systemd-nspawn>
vm-test-run-systemd-nspawn> [Network]
vm-test-run-systemd-nspawn> Private=true
vm-test-run-systemd-nspawn>
vm-test-run-systemd-nspawn> "

Two major changes in this commit:

- Refactor options to use `.settings` pattern and use settingsToSections
  to generate the content. This brings the module in line with other
  modern systemd modules.
- Write individual units to etc/: This allows imperative container
  management to create unit files in /etc/systemd/nspawn
@m1cr0man

Copy link
Copy Markdown
Contributor Author

I tried tracing back when the value was written as "1" and not "true" but it goes way further back than when I added that test, so I don't know how that happened. Anyway, fixed now. Thanks for catching it.

@RossSmyth

Copy link
Copy Markdown
Contributor

Ok the VM test passes now. I'll test it with some nspawn stuff I have laying around as well.

@RossSmyth

Copy link
Copy Markdown
Contributor

Ok, my test container works.

@m1cr0man
m1cr0man dismissed ElvishJerricco’s stale review October 25, 2026 23:12

All changes addressed and re-reviewed by others.

@RossSmyth

Copy link
Copy Markdown
Contributor

I'm doing one more test and will hit the button whenever it finishes

@RossSmyth

Copy link
Copy Markdown
Contributor

I cannot get any container tests to run to see if this effects them. But I do not think this change does? Can you confirm this?

@RossSmyth

Copy link
Copy Markdown
Contributor

Ok they are uneffected.

@RossSmyth
RossSmyth added this pull request to the merge queue Oct 26, 2026
@m1cr0man

Copy link
Copy Markdown
Contributor Author

I cannot get any container tests to run to see if this effects them. But I do not think this change does? Can you confirm this?

You mean NixOS containers? I have a backwards compatibility test suite in my other repo. I'll give that another quick run but it has been tested previously and this specific change doesn't otherwise effect them.

@RossSmyth

Copy link
Copy Markdown
Contributor

No, I was just making sure that the nixosTests that use nspawn containers rather than qemu vms were uneffected by this change

Merged via the queue into NixOS:master with commit 58287f3 Oct 26, 2026
30 checks passed
@m1cr0man

Copy link
Copy Markdown
Contributor Author

Thanks for merging! 🥳

@m1cr0man
m1cr0man deleted the rfc108-nspawn branch October 26, 2026 01:30
@trofi

trofi commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Caused minor eval failure. Proposed possible fix as:

@m1cr0man

Copy link
Copy Markdown
Contributor Author

Thanks for finding and fixing that.

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 6.topic: systemd Software suite that provides an array of system components for Linux operating systems. 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 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 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 3+ This PR was reviewed and approved by three or more persons.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

9 participants