Comments (4)
Sorry for the delay (life's been crazy)!
What I am wondering is how the service dependencies make sense.
I'm actually not using systemd in initrd for now, I've tried my best to make that unit work, but I always get the dependency cycles or race conditions :/
The main benefit it offers (for me, at least) is having plymouth start up before the LUKS password prompt, but it seems it's still missing a few features.
A fellow nixer (Tom) e-mailed me with a clever solution for this issue:
let
rootfsDevice = "/dev/disk/by-label/${hostname}";
wipeScript = ''
counter=0
# systemd initrd offers no way to hook in between
# 'root device is ready' and 'mount the root device at /sysroot'.
# Instead, lets poll for the root device.
# https://github.com/systemd/systemd/issues/24904
echo wipe: Waiting for ${rootfsDevice}
while [ ! -e ${rootfsDevice} ]; do
sleep 0.1
counter=$((counter + 1))
if [ $counter -ge 300 ]; then
echo wipe: Timed out waiting for ${rootfsDevice}
exit
fi
done
echo wipe: Found ${rootfsDevice}. Wiping ephemeral.
mkdir -p /btrfs
mount -o subvol=/ ${rootfsDevice} /btrfs
echo "Cleaning subvolume"
btrfs subvolume list -o /btrfs/root | cut -f9 -d ' ' |
while read subvolume; do
btrfs subvolume delete "/btrfs/$subvolume"
done && btrfs subvolume delete /btrfs/root
echo "Restoring blank subvolume"
btrfs subvolume snapshot /btrfs/root-blank /btrfs/root
umount /btrfs
rm -d /btrfs
'';
in {
options = {
/* truncated */
};
config = {
boot.initrd = {
supportedFilesystems = [ "btrfs" ];
systemd = {
enable = true;
emergencyAccess = true;
initrdBin = with pkgs; [ coreutils btrfs-progs ];
services.initrd-btrfs-root-wipe = {
description = "Wipe ephemeral btrfs root";
script = wipeScript;
serviceConfig.Type = "oneshot";
unitConfig.DefaultDependencies = "no";
after = [ "cryptsetup.target" "initrd-root-device.target" ];
before = [ "sysroot.mount" ];
wantedBy = [ "sysroot.mount" ];
};
};
};
};
/* truncated */
}
from nix-config.
Thank you for having this as well as the nix-starter-config repository
Thanks a lot for your kind words! I'm very glad to be able to help out :)
from nix-config.
That solution seems similar to my own, but perhaps a little more janky. Anyway, thanks for getting back to me, good to know that my solution is reasonable.
from nix-config.
I'm happy to say that I've finally found a elegant fix for this!
There's a .device
unit for each and every device, so you can simply add the relevant one to your wipe service after
/requires
.
In my case, my btrfs partition is /dev/disk/by-lavel/${hostname}
, so the relevant unit is dev-disk-by\x2dlabel-${hostname}.device
(\x2d
is how systemd escapes -
). I found that out trying systemctl list-units -a | grep "dev-disk-by"
Note: if your unit has backslashes like mine, you have to either (if using regular nix strings) do double backslashes, or do the ''
multiline string.
That means, "\foo"
does not work, while "\\foo"
and ''\foo''
does.
from nix-config.
Related Issues (20)
- Ci/Cd? HOT 1
- SOPS and fresh installation HOT 12
- libsForQt5.qtstyleplugins messes up QT apps. HOT 1
- Do you persist `/etc/nixos`? HOT 2
- Question: How to deploy on Raspberry Pi 4 HOT 2
- Home Manager environment not activating under an impermanence setup HOT 1
- Advice for encrypt secrets that can't be encrypted with sops-nix because they are needed during runtime HOT 3
- QUESTION: How did you fix the problem of wofi on waybar with systemd integration setup? HOT 2
- Firefox add-ons issue HOT 2
- error: The option `home-manager.users.eyduh.fontProfiles' does not exist. HOT 1
- Thanks for sharing, helped me setup sops, multiuser multi nodes :) HOT 2
- Invalid Hyprland configuration generated with hyprbars
- Redundant directory creation in ephemeral-btrfs.nix
- QUESTION: how to configure new Hydra project? HOT 5
- How does Hydra know the ip of the two worker desktops?
- Installation guide HOT 1
- Question on LSP in nvim
- QUESTION about nix-shell getting error: input 'hyprland-plugins/systems' follows a non-existent input 'hyprland-plugins/hyprland/systems'
- QUESTION: impermanence and standalone home-manager
- Question: Purpose of what seems to be a double import of home-manager configuration
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nix-config.