From db54e3ca4f1dfa4dcba13924bf2fc197bbdcd8b0 Mon Sep 17 00:00:00 2001 From: chn Date: Tue, 1 Aug 2023 16:34:08 +0800 Subject: [PATCH] make manual decrypt devices exist before cryptsetup.target reached --- flake.nix | 2 +- modules/fileSystems/default.nix | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index 6395393f..4e186568 100644 --- a/flake.nix +++ b/flake.nix @@ -296,7 +296,7 @@ "/dev/mapper/root" = { "/nix" = "/nix"; "/nix/rootfs/current" = "/"; }; }; }; - decrypt.manual = { enable = true; devices = [ "/" ]; }; + decrypt.manual = { enable = true; devices = [ "/dev/mapper/root" ]; }; rollingRootfs = { device = "/dev/mapper/root"; path = "/nix/rootfs"; }; }; packages = diff --git a/modules/fileSystems/default.nix b/modules/fileSystems/default.nix index eeeafded..9120e6a1 100644 --- a/modules/fileSystems/default.nix +++ b/modules/fileSystems/default.nix @@ -56,7 +56,7 @@ inputs: }; config = let - inherit (builtins) listToAttrs map concatLists; + inherit (builtins) listToAttrs map concatLists concatStringsSep; inherit (inputs.lib) mkMerge mkIf; inherit (inputs.localLib) stripeTabs attrsToList; inherit (inputs.config.nixos) fileSystems; @@ -134,15 +134,28 @@ inputs: boot.initrd = { luks.forceLuksSupportInInitrd = true; - systemd.extraBin = + systemd = { - cryptsetup = "${inputs.pkgs.cryptsetup.bin}/bin/cryptsetup"; - usbip = "${inputs.config.boot.kernelPackages.usbip}/bin/usbip"; + extraBin = + { + cryptsetup = "${inputs.pkgs.cryptsetup.bin}/bin/cryptsetup"; + usbip = "${inputs.config.boot.kernelPackages.usbip}/bin/usbip"; + }; + services.wait-manual-decrypt = + { + wantedBy = [ "cryptsetup.target" ]; + before = [ "cryptsetup.target" ]; + unitConfig.DefaultDependencies = false; + serviceConfig.Type = "oneshot"; + script = concatStringsSep "\n" (map + (device: "while [ ! -e ${device} ]; do sleep 1; done") + fileSystems.decrypt.manual.devices); + }; }; }; - fileSystems = listToAttrs (map - (device: { name = device; value.options = [ "x-systemd.mount-timeout=1h" ]; }) - fileSystems.decrypt.manual.devices); + # fileSystems = listToAttrs (map + # (device: { name = device; value.options = [ "x-systemd.mount-timeout=1h" ]; }) + # fileSystems.decrypt.manual.devices); } ) # mdadm