-
-
Notifications
You must be signed in to change notification settings - Fork 17k
nixos/systemd: Support setting machineId #268995
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
Conversation
i'm trying to understand the implications of this statement from the documentation you linked:
do you know the details on that? |
Quoting more from the manpage:
We should make sure systemd is able to write to this during installation / first boot, but putting it into NixOS configuration sounds wrong. For the special usecases where it's desired to set this via kernel cmdline, we already have the cmdline config option, but I wouldn't encourage further to set this. |
I'm not aware of anything in systemd itself which relies on Theoretically, putting
Are “impermanent” / root-on-tmpfs systems such a special usecase? I made the PR because someone asked me to upstream that option (which I wrote in my config monorepo some years ago) and it seems to be a common pitfall for impermanent systems. It causes unexpected behavior with the journal, among other things: every boot gets a different |
5a2eaa8
to
6542d06
Compare
This is quite useful for “impermanent” (root-on-tmpfs) configurations.
6542d06
to
9ac50e1
Compare
In the netboot scenario, can't you set / extend the kernel cmdline independently of the system closure? That's what I used to do, in cases where I wanted to pass along the ipxe machine UUID to systemd. Similar things were also suggested to people asking for this to be added into CoreOS:
If you don't want to have a new machine UUID on such systems, simply exclude this file from being wiped on every reboot. Having a static value part of your system config is only a big footgun, having two machines with the same UUID. I don't think we should introduce this as a config option. |
Yes, there are other options too in the netboot scenario specifically.
I don't see how it's more of a footgun than the plethora of extent options for setting a MAC address (worse, those have the potential for breaking the entire LAN the devices sit on) but I won't insist either; close as “won't fix” if the maintainers do not wish to provide such an option. |
boot.kernelParams = lib.foldr (a: b: a ++ b) [] [ | ||
(optional (cfg.machineId != null) "systemd.machine_id=${cfg.machineId}") | ||
(optional (!cfg.enableUnifiedCgroupHierarchy) "systemd.unified_cgroup_hierarchy=0") | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick. My brain and nix processes this code much faster (also less parentheses):
boot.kernelParams = lib.foldr (a: b: a ++ b) [] [ | |
(optional (cfg.machineId != null) "systemd.machine_id=${cfg.machineId}") | |
(optional (!cfg.enableUnifiedCgroupHierarchy) "systemd.unified_cgroup_hierarchy=0") | |
]; | |
boot.kernelParams = optional (cfg.machineId != null) "systemd.machine_id=${cfg.machineId}" | |
++ optional (!cfg.enableUnifiedCgroupHierarchy) "systemd.unified_cgroup_hierarchy=0"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a static value part of your system config is only a big footgun, having two machines with the same UUID. I don't think we should introduce this as a config option.
I don't see how it's more of a footgun than the plethora of extent options for setting a MAC address (worse, those have the potential for breaking the entire LAN the devices sit on) but I won't insist either; close as “won't fix” if the maintainers do not wish to provide such an option.
The machine-id is even more considered state:
The machine ID is usually generated from a random source during system installation or first boot and stays constant for all subsequent boots.
Pease pass it in externally where you have to keep it static across reboots, but can't keep state that state on the machine (for example netboot scenarios by appending via kernel cmdline), use it as state wherever you can (impermanence setups), and only resort to setting the kernel cmdline via NixOS options where you can't do otherwise. I don't think there should be a NixOS config option for this.
I'm also not a big fan of this change. https://systemd.io/BUILDING_IMAGES/ also recommends people not setting machine-id when building images. Also there are multiple ways for people to set this. (kernel command line vs environment.etc). I think people should just use environment.etc or the kernel command line if they want to mess with this. |
After speaking about @flokli on this, @nbraud I would recommend the way forward is to document it in the NixOS manual about which situations may require to use a persistent |
@RaitoBezarius What part of the manual do you think this should go in? |
This could go in https://nixos.org/manual/nixos/stable/#ch-running under its own section potentially. |
Suggested in the discussion of NixOS#268995.
Description of changes
Add new
systemd.machineId
configuration option.In principle,
machine-id(5)
can be an arbitrary, 128b string in hex-encoding; however, systemd v30 onwards (2011) generate UUIDv4 values, and various tools may rely on that.Set the machine-id through
boot.kernelParams
.Things done
Priorities
Add a 👍 reaction to pull requests you find important.