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

Systemd stage 1 networkd #169116

Merged
merged 10 commits into from
Apr 21, 2023
Merged

Conversation

ElvishJerricco
Copy link
Contributor

@ElvishJerricco ElvishJerricco commented Apr 17, 2022

Description of changes

Use systemd-networkd for networking in stage 1.

  • Adds a mechanism for users/groups in initrd, since that's required for the systemd-network user/group.
  • Configures networking.interfaces to the same level as scripted initrd.
  • Supports SSH and OpenVPN
  • Adds dbus with socket activation so that networkctl can work.
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/)
  • 22.05 Release Notes (or backporting 21.11 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
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

Copy link
Contributor

@flokli flokli left a comment

Choose a reason for hiding this comment

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

I don't quite understand why we can't just also ship all .network and .netdev files in the initrd. Did you run into troubles when doing that?

nixos/modules/system/boot/systemd/initrd.nix Outdated Show resolved Hide resolved
@@ -364,7 +356,7 @@ in {

"/etc/systemd/system.conf".text = ''
[Manager]
DefaultEnvironment=PATH=/bin:/sbin ${optionalString (isBool cfg.emergencyAccess && cfg.emergencyAccess) "SYSTEMD_SULOGIN_FORCE=1"}
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 unrelated to this PR, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sort of? I needed it because sshd requires the root account to be unlocked.

nixos/modules/system/boot/networkd.nix Outdated Show resolved Hide resolved
nixos/modules/system/boot/networkd.nix Outdated Show resolved Hide resolved
nixos/modules/services/networking/ssh/sshd.nix Outdated Show resolved Hide resolved
restartTriggers = optionals (!cfg.startWhenNeeded) [
config.environment.etc."ssh/sshd_config".source
];
path = [ cfgc.package pkgs.gawk pkgs.coreutils ];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
path = [ cfgc.package pkgs.gawk pkgs.coreutils ];
path = with pkgs; [ cfgc.package gawk coreutils ];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather avoid with whenever reasonable. Even in simple examples like this.

Copy link
Member

Choose a reason for hiding this comment

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

I actually would say we should highly recommend it to be used in small lists with repeating prefixes. With my change it is very easy to see with a glance what packages are added but with the extra pkgs. prefix I can barely parse it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On top of the fact that I and many others strongly disagree with that on account of with introducing dynamic scoping that requires logical analysis instead of simpler lexical analysis to understand, this is also not a matter of substance to this PR as the line being commented on is a pre-existing one.

nixos/modules/services/networking/ssh/sshd.nix Outdated Show resolved Hide resolved
nixos/modules/services/networking/ssh/sshd.nix Outdated Show resolved Hide resolved
nixos/modules/services/networking/ssh/sshd.nix Outdated Show resolved Hide resolved
nixos/modules/system/boot/initrd-ssh.nix Show resolved Hide resolved
nixos/modules/system/boot/networkd.nix Show resolved Hide resolved
nixos/modules/system/boot/systemd/initrd.nix Outdated Show resolved Hide resolved
pkgs/build-support/kernel/make-initrd-ng.nix Outdated Show resolved Hide resolved
@ElvishJerricco ElvishJerricco force-pushed the systemd-stage-1-networkd branch 2 times, most recently from ba27910 to 1ee4193 Compare July 23, 2022 10:22
@ElvishJerricco
Copy link
Contributor Author

I've added a warning if no networks are configured, since we don't automatically configure anything like the scripted initrd does.

I've also decided not to mangle sshd.nix to have it serve both stage 1 and 2. Instead I've made a much simpler patch to implement effectively what the scripted initrd does with a simple service.

@ElvishJerricco
Copy link
Contributor Author

Rebased on nixos-unstable-small, along with the openvpn mkdir /tmp change mentioned above

Copy link
Contributor

@flokli flokli left a comment

Choose a reason for hiding this comment

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

I'd personally feel more comfortable if the OpenVPN and flush bits would be separate PRs. It might trigger some more discussion, blocking this PR more than necessary.

@@ -71,6 +78,14 @@ in
boot.initrd.network.postCommands = ''
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have OpenVPN both as postCommand forking off and as a systemd unit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The network.postCommands part is for scripted stage 1. The systemd stage 1 has been deliberately designed not to implement the boot.initrd.*Commands options, for reasons outlined in the original PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed changes adopting the convention of using mkIf (!config.boot.initrd.systemd.enable) for these *Commands options in the ssh and openvpn modules, in order to make it clear what they're for, and to help ensure those options are not used at all when systemd initrd is in use.

nixos/modules/system/boot/initrd-openvpn.nix Outdated Show resolved Hide resolved
nixos/modules/services/system/dbus.nix Outdated Show resolved Hide resolved
nixos/modules/system/boot/networkd.nix Show resolved Hide resolved
@ElvishJerricco ElvishJerricco force-pushed the systemd-stage-1-networkd branch 3 times, most recently from d310410 to e94f56b Compare April 11, 2023 22:13
Copy link
Member

@lilyinstarlight lilyinstarlight left a comment

Choose a reason for hiding this comment

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

This looks pretty fabulous; thank you for this work!

Most of the technical questions I would have had seem to have already been asked or addressed, but I did leave a few review comments

nixos/modules/system/boot/systemd/initrd.nix Outdated Show resolved Hide resolved
nixos/modules/system/boot/initrd-ssh.nix Show resolved Hide resolved
nixos/modules/system/boot/networkd.nix Outdated Show resolved Hide resolved
nixos/modules/tasks/network-interfaces-systemd.nix Outdated Show resolved Hide resolved
nixos/tests/predictable-interface-names.nix Outdated Show resolved Hide resolved
@ElvishJerricco ElvishJerricco force-pushed the systemd-stage-1-networkd branch 2 times, most recently from 06f89d3 to 0ff1545 Compare April 15, 2023 08:04
@infinisil infinisil added the significant Novel ideas, large API changes, notable refactorings, issues with RFC potential, etc. label Apr 19, 2023
@flokli flokli merged commit 6b27ed3 into NixOS:master Apr 21, 2023
@colemickens
Copy link
Member

🎊 🚀 I've been excited for this one for a while, thank you to everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.