Repository navigation
Conversation
…pted-devic.patch" This reverts commit b5611f9.
|
If you simply put a filesystem on /dev/mapper/cryptkey and create the keyfile on this fs (e.g. as /key) this will satisfy your usecase. IMO this doesn't justify patching systemd. |
@nikstur which file system are you referring to? I have a setup where I have some random data on a partition (called cryptkey) which is unlocked with a password. The contents of I was quite surprised when this suddenly broke. Granted the old shell script boot worked with this just fine, and even when the default switched to systemd boot it also worked fine (albeit having systemd manage doing the unlock). As of right now, I can no longer boot any of my machines with this setup. Sure I suppose leaning on password reuse is something I can try instead of using a key-file, but I just wanted to ask, is it intentional to break what has been a valid luks setup (as far as NixOS has supported it for years until now)? If yes, is this documented anywhere with any suggested alternative? I don't mind rolling some systemd glue code but I'm not exactly sure what's the path forward. Hence the revert just to get things back in working order. Happy if this goes away in the long term as long as there's some suggested path on how to make keyfiles work! EDIT: rereading I think I see what you mean, though this will require some surgery which may end up locking me out of my disks. Probably worth documenting this loudly for anyone else who gets bitten by this if the breakage is intentional |
|
Is adding the udev rules in |
Maybe? Hadn't had a chance to try it out yet, not an expert in udev or systemd, just came across the patch as part of a bisect to figure out what caused the breakage. Are you suggesting I add this to my own configs or make this a default setting for everyone? |
|
Also the patch appears to remove some rules, not add new ones, not sure if that can be done via |
|
You should be able to fix this by: Before doing anything I suggest you to enroll a password into a new keyslot of all of your LUKS volumes that you can use to recover via (1) On a booted system write they keyfile to a backup location on your rootfs (something like Re-adding this patch doesn't make sense as this is not a particularly useful use-case and violates our patch policy. The "normal" way (for which we also have a test) to unlock something like a swap partition without typing multiple passwords or relying on password re-use by systemd-cryptsetup is to store keyfiles on your rootfs. There is no need to go via this indirection of a separate LUKS volume just for the key. What you're doing wouldn't have worked on any other distro. Additionally, re-adding this patch would only land in unstable in around a month as that's our typical staging cycle right now. |
|
I think this was also at least partially dropped because the actual usecase / implications of the patch were not really documented in / visible from the commit message. Is there a reason this is not upstream? If this is generally desirable behaviour, upstream might be receptive to it, and it might make more sense to get it into systemd proper, rather than shipping it only in the NixOS systemd. And if not, upstream might have a suggestion with how to accomplish the same goal differently. |
|
Edit: tongue in cheek joke. Didn't mean to say this is not a valid usecase. |
It is my opinion that the patch should be upstream, and that systemd only ever had this udev rule to work around some rather clumsy behavior. The comment suggests that the device isn't ready because "we are probably still calling mke2fs or mkswap on it", but this is sort of a nonsense reason. For a systemd unit to be doing mkfs on the device, either it would have to depend on the device or it would have to be the one that did It doesn't really make sense, and it certainly violates the principle of least astonishment. It must exist because of some clumsy tooling that existed long ago that no one uses now, like something that does All that said, there are plenty of ways to work around it. @ipetkov, for one thing you can set So I agree that NixOS shouldn't be carrying this patch. It's easily worked around, and it's a way that NixOS's behavior inexplicably differs from other distros. But I do think this patch should be upstream. |
|
Thanks for the detailed writeups on alternatives I can take. I'm going to triple check my backups and carefully rework my configs! In the mean time I'm going to close this as its unlikely to get this landed back in nixpkgs. Will leave it to someone better versed to attempt at upstreaming this as well |
When I originally installed NixOS (all those years ago) I'll admit I didn't fully know what I was doing (first "real" Linux install and all, much less NixOS specifics) so I was following whatever random guides I found online on how to set up disk encryption. At the time I ended up just making an encrypted partition, blasting some random bytes on to it and using that as the keyfile for the other (root/swap) partitions. Perhaps at the time password caching/reuse was annoying so this was a good way to have to type in the password only once at boot? Anyway, this apparently only worked on NixOS on the happenstance that systemd was patched up to make it work. Recently that patch is being dropped from NixOS (to minimize carrying non-upstreamed patches) which ends up breaking this setup (systemd will decrypt the device but other units depending on it end up hanging). One easy solution (besides just using the same password on every other encrypted partition and remembering to change them all in sync if necessary) is to back up the cryptkey contents, reinitialize the partition with a filesystem, and put the contents back in as a regular file. With some special syntax, systemd will end up wiring things up correctly at runtime. NixOS/nixpkgs#525118 (comment)
|
Ran into this today as well. First time NixOS hangs on boot after update in 7 years :) The fix below worked for me: |
|
@nikstur I guess we should retroactively add this to the release notes. noone really was aware this was a legitimate (very race) usecase). It would still help people running into this when migrating to 26.05 now. @MMesch the udev rule could be racy, upstream is not aware of it either and this is even less likely to stay working. It's probably safer to migrate to simply using the same passphrase for all partitions. That usecase is known and used by lots of people. If you absolutely want two layers of luks, you can put the keys as a literal file on a filesystem on the encrypted keyfile volume, as ipetkov/dotfiles@2de353c did. |
|
Yes that makes sense. The above is more a temporary workaround. Regarding putting the key in an actual file on a file system, I'm a bit scared of the migration. @ipetkov how did you safely get to the new state from the old? Using same passphrase everywhere seems relatively simple in comparison. |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |

The systemd
Start-device-units-for-uninitialised-encrypted-devic.patchwas recently removed in b5611f9 via #488508 (cc @nikstur ).The cited reason was that this is no longer need due to b138917, however, dropping the patch breaks booting configurations where a password-encrypted luks volume is then used as key-file to decrypt another luks volume. I've added a test case/reproduction for this (breaks without the patch, fixed after reverting).
Note: the existing systemd patches were reflowed after this patch was dropped. As part of the revert I renamed the prefix to
0000to avoid having to reflow patches again, but let me know if there's a preferred approach hereThings done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.