When rebuilding and switching my config with impermanence I keep getting this error after a few rebuilds.
I then remove /etc/machine-id but it keeps coming back after a while.
I also saw if for /etc/ssh/ssh_host… , I don’t see it for the directories.
Any suggestions?
...
A file already exists at /etc/machine-id!
Activation script snippet 'persist-files' failed (1)
reloading user units for some-user...
setting up tmpfiles
warning: the following units failed: persist--persist-etc-machine-id-.service
× persist--persist-etc-machine-id-.service - Bind mount or link '/persist/etc/machine-id' to '/etc/machine-id'
Loaded: loaded (/etc/systemd/system/persist--persist-etc-machine-id-.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2022-07-10 20:19:49 CEST; 3s ago
Process: 51040 ExecStart=/nix/store/ydjw9khp0kixn9la6pmqsgaaaaaaaaaa-impermanence-mount-file /etc/machine-id /persist/etc/machine-id (code=exited, status=1/FAILURE)
Main PID: 51040 (code=exited, status=1/FAILURE)
IP: 0B in, 0B out
CPU: 8ms
Jul 10 20:19:49 some-hostname systemd[1]: Starting Bind mount or link '/persist/etc/machine-id' to '/etc/machine-id'...
Jul 10 20:19:49 some-hostname ydjw9khp0kixn9la6pmqsgaaaaaaaaaa-impermanence-mount-file[51040]: A file already exists at /etc/machine-id!
Jul 10 20:19:49 some-hostname systemd[1]: persist--persist-etc-machine-id-.service: Main process exited, code=exited, status=1/FAILURE
Jul 10 20:19:49 some-hostname systemd[1]: persist--persist-etc-machine-id-.service: Failed with result 'exit-code'.
Jul 10 20:19:49 some-hostname systemd[1]: Failed to start Bind mount or link '/persist/etc/machine-id' to '/etc/machine-id'.
I suspect it comes back on reboot, specifically. This is because impermanence’s units are activating too late to properly redirect that file. systemd itself needs it, and will create it with a random value if it’s not present, so a systemd service is kinda by definition too late.
Also, /etc/machine-id actually doesn’t ever need to be modified, so you can install it into place with environment.etc instead, as I do in my config here.
As for actual state that’s needed very early, I use an initrd snippet to get it into place like this.
Showing the machine-id at other locations (git) is not considered safe?
man machine-id
This ID uniquely identifies the host. It should be considered
"confidential", and must not be exposed in untrusted environments, in
particular on the network. If a stable unique identifier that is tied
to the machine is needed for some application, the machine ID or any
part of it must not be used directly. Instead the machine ID should be
hashed with a cryptographic, keyed hash function, using a fixed,
application-specific key. That way the ID will be properly unique, and
derived in a constant way from the machine ID but there will be no way
to retrieve the original machine ID from the application-specific one.
The sd_id128_get_machine_app_specific(3) API provides an
implementation of such an algorithm.
I see the ideal situation as:
the machine-id is auto-generated on first boot.
a way to move it to /persist or generate it at /persist
symlink
The symlink part you did with some other paths. I’m unsure about the second.
Hmm, I wasn’t aware that the machine-id was considered confidential… unfortunately, there’s no explanation of why it’s considered confidential. Anyway, you can just use quotes on the value of .source like I did here to make it a symlink to some persisted location.
Ignore the error, it’s a warning. Your machine-id file will be regenerated on boot and be placed into the persistent location since a symlink will point to it. If you want it to happen ahead of time then simply rm /etc/machine-id and then activate the system configuration. The same thing happens with home-manager if you try to write your .basrhc with it, but you already have a .bashrc in your home directory. Similarly, in that case, you need to rm ~/.bashrc before home-manager can take over. Home-manager has an option to force the replacement of the file, which I enjoy. Impermanence has no such ‘force’ option, but I think it would be a good idea to add.