2014-04-15 21:43:39 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
2020-05-25 01:55:32 +00:00
|
|
|
let
|
|
|
|
cfg = config.services.lvm;
|
|
|
|
in {
|
|
|
|
options.services.lvm = {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "lvm2" // {
|
2022-10-26 15:21:07 +00:00
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
2020-05-25 01:55:32 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2022-02-01 17:20:49 +00:00
|
|
|
default = pkgs.lvm2;
|
2020-05-25 01:55:32 +00:00
|
|
|
internal = true;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "pkgs.lvm2";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2020-05-25 01:55:32 +00:00
|
|
|
This option allows you to override the LVM package that's used on the system
|
|
|
|
(udev rules, tmpfiles, systemd services).
|
2022-02-01 17:20:49 +00:00
|
|
|
Defaults to pkgs.lvm2, pkgs.lvm2_dmeventd if dmeventd or pkgs.lvm2_vdo if vdo is enabled.
|
2020-05-25 01:55:32 +00:00
|
|
|
'';
|
|
|
|
};
|
2024-04-13 12:54:15 +00:00
|
|
|
dmeventd.enable = mkEnableOption "the LVM dmevent daemon";
|
|
|
|
boot.thin.enable = mkEnableOption "support for booting from ThinLVs";
|
|
|
|
boot.vdo.enable = mkEnableOption "support for booting from VDOLVs";
|
2020-05-25 01:55:32 +00:00
|
|
|
};
|
2006-12-24 01:07:28 +00:00
|
|
|
|
2024-04-13 12:54:15 +00:00
|
|
|
options.boot.initrd.services.lvm.enable = mkEnableOption "booting from LVM2 in the initrd" // {
|
|
|
|
description = ''
|
2023-07-03 12:41:38 +00:00
|
|
|
*This will only be used when systemd is used in stage 1.*
|
|
|
|
|
|
|
|
Whether to enable booting from LVM2 in the initrd.
|
|
|
|
'';
|
2022-04-11 18:28:09 +00:00
|
|
|
};
|
|
|
|
|
2020-05-25 01:55:32 +00:00
|
|
|
config = mkMerge [
|
2020-11-14 13:40:32 +00:00
|
|
|
({
|
|
|
|
# minimal configuration file to make lvmconfig/lvm2-activation-generator happy
|
|
|
|
environment.etc."lvm/lvm.conf".text = "config {}";
|
|
|
|
})
|
2022-10-26 15:21:07 +00:00
|
|
|
(mkIf cfg.enable {
|
2020-07-25 18:43:12 +00:00
|
|
|
systemd.tmpfiles.packages = [ cfg.package.out ];
|
2020-05-25 01:55:32 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
systemd.packages = [ cfg.package ];
|
2009-03-06 12:27:28 +00:00
|
|
|
|
2020-05-25 01:55:32 +00:00
|
|
|
services.udev.packages = [ cfg.package.out ];
|
2023-07-05 08:59:04 +00:00
|
|
|
})
|
|
|
|
(mkIf config.boot.initrd.services.lvm.enable {
|
2022-04-11 18:28:09 +00:00
|
|
|
# We need lvm2 for the device-mapper rules
|
2023-07-05 08:59:04 +00:00
|
|
|
boot.initrd.services.udev.packages = [ cfg.package ];
|
2022-04-11 18:28:09 +00:00
|
|
|
# The device-mapper rules want to call tools from lvm2
|
2023-07-05 08:59:04 +00:00
|
|
|
boot.initrd.systemd.initrdBin = [ cfg.package ];
|
|
|
|
boot.initrd.services.udev.binPackages = [ cfg.package ];
|
2020-05-25 01:55:32 +00:00
|
|
|
})
|
|
|
|
(mkIf cfg.dmeventd.enable {
|
|
|
|
systemd.sockets."dm-event".wantedBy = [ "sockets.target" ];
|
|
|
|
systemd.services."lvm2-monitor".wantedBy = [ "sysinit.target" ];
|
2009-03-06 12:27:28 +00:00
|
|
|
|
2020-05-25 01:55:32 +00:00
|
|
|
environment.etc."lvm/lvm.conf".text = ''
|
|
|
|
dmeventd/executable = "${cfg.package}/bin/dmeventd"
|
|
|
|
'';
|
2022-02-01 17:20:49 +00:00
|
|
|
services.lvm.package = mkDefault pkgs.lvm2_dmeventd;
|
2020-05-25 01:55:32 +00:00
|
|
|
})
|
|
|
|
(mkIf cfg.boot.thin.enable {
|
|
|
|
boot.initrd = {
|
|
|
|
kernelModules = [ "dm-snapshot" "dm-thin-pool" ];
|
2010-01-07 15:55:05 +00:00
|
|
|
|
2022-04-11 18:28:09 +00:00
|
|
|
systemd.initrdBin = lib.mkIf config.boot.initrd.services.lvm.enable [ pkgs.thin-provisioning-tools ];
|
|
|
|
|
|
|
|
extraUtilsCommands = mkIf (!config.boot.initrd.systemd.enable) ''
|
2021-08-05 13:39:18 +00:00
|
|
|
for BIN in ${pkgs.thin-provisioning-tools}/bin/*; do
|
|
|
|
copy_bin_and_libs $BIN
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2022-04-11 18:28:09 +00:00
|
|
|
extraUtilsCommandsTest = mkIf (!config.boot.initrd.systemd.enable) ''
|
2021-08-05 13:39:18 +00:00
|
|
|
ls ${pkgs.thin-provisioning-tools}/bin/ | grep -v pdata_tools | while read BIN; do
|
|
|
|
$out/bin/$(basename $BIN) --help > /dev/null
|
|
|
|
done
|
2020-05-25 01:55:32 +00:00
|
|
|
'';
|
|
|
|
};
|
2010-01-07 22:39:35 +00:00
|
|
|
|
2021-08-05 13:39:18 +00:00
|
|
|
environment.etc."lvm/lvm.conf".text = concatMapStringsSep "\n"
|
|
|
|
(bin: "global/${bin}_executable = ${pkgs.thin-provisioning-tools}/bin/${bin}")
|
|
|
|
[ "thin_check" "thin_dump" "thin_repair" "cache_check" "cache_dump" "cache_repair" ];
|
2022-02-01 17:20:49 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.thin-provisioning-tools ];
|
|
|
|
})
|
|
|
|
(mkIf cfg.boot.vdo.enable {
|
|
|
|
boot = {
|
|
|
|
initrd = {
|
|
|
|
kernelModules = [ "kvdo" ];
|
|
|
|
|
2022-04-11 18:28:09 +00:00
|
|
|
systemd.initrdBin = lib.mkIf config.boot.initrd.services.lvm.enable [ pkgs.vdo ];
|
|
|
|
|
|
|
|
extraUtilsCommands = mkIf (!config.boot.initrd.systemd.enable)''
|
2022-07-20 12:50:51 +00:00
|
|
|
ls ${pkgs.vdo}/bin/ | while read BIN; do
|
2022-02-13 14:41:14 +00:00
|
|
|
copy_bin_and_libs ${pkgs.vdo}/bin/$BIN
|
2022-02-01 17:20:49 +00:00
|
|
|
done
|
2022-07-20 12:50:51 +00:00
|
|
|
substituteInPlace $out/bin/vdorecover --replace "${pkgs.bash}/bin/bash" "/bin/sh"
|
|
|
|
substituteInPlace $out/bin/adaptLVMVDO.sh --replace "${pkgs.bash}/bin/bash" "/bin/sh"
|
2022-02-01 17:20:49 +00:00
|
|
|
'';
|
|
|
|
|
2022-04-11 18:28:09 +00:00
|
|
|
extraUtilsCommandsTest = mkIf (!config.boot.initrd.systemd.enable)''
|
2022-07-20 12:50:51 +00:00
|
|
|
ls ${pkgs.vdo}/bin/ | grep -vE '(adaptLVMVDO|vdorecover)' | while read BIN; do
|
2022-02-01 17:20:49 +00:00
|
|
|
$out/bin/$(basename $BIN) --help > /dev/null
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
extraModulePackages = [ config.boot.kernelPackages.kvdo ];
|
|
|
|
};
|
|
|
|
|
|
|
|
services.lvm.package = mkOverride 999 pkgs.lvm2_vdo; # this overrides mkDefault
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.vdo ];
|
2020-05-25 01:55:32 +00:00
|
|
|
})
|
|
|
|
(mkIf (cfg.dmeventd.enable || cfg.boot.thin.enable) {
|
2022-04-11 18:28:09 +00:00
|
|
|
boot.initrd.systemd.contents."/etc/lvm/lvm.conf".text = optionalString (config.boot.initrd.services.lvm.enable && cfg.boot.thin.enable) (concatMapStringsSep "\n"
|
|
|
|
(bin: "global/${bin}_executable = /bin/${bin}")
|
|
|
|
[ "thin_check" "thin_dump" "thin_repair" "cache_check" "cache_dump" "cache_repair" ]
|
|
|
|
) + "\n" + optionalString cfg.dmeventd.enable ''
|
|
|
|
dmeventd/executable = /bin/false
|
|
|
|
activation/monitoring = 0
|
|
|
|
'';
|
|
|
|
|
|
|
|
boot.initrd.preLVMCommands = mkIf (!config.boot.initrd.systemd.enable) ''
|
2020-05-25 01:55:32 +00:00
|
|
|
mkdir -p /etc/lvm
|
|
|
|
cat << EOF >> /etc/lvm/lvm.conf
|
2021-08-05 13:39:18 +00:00
|
|
|
${optionalString cfg.boot.thin.enable (
|
|
|
|
concatMapStringsSep "\n"
|
|
|
|
(bin: "global/${bin}_executable = $(command -v ${bin})")
|
|
|
|
[ "thin_check" "thin_dump" "thin_repair" "cache_check" "cache_dump" "cache_repair" ]
|
|
|
|
)
|
|
|
|
}
|
2020-05-25 01:55:32 +00:00
|
|
|
${optionalString cfg.dmeventd.enable ''
|
|
|
|
dmeventd/executable = "$(command -v false)"
|
|
|
|
activation/monitoring = 0
|
|
|
|
''}
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
];
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2006-12-24 01:07:28 +00:00
|
|
|
}
|