2014-04-15 23:43:39 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
2020-05-25 03:55:32 +02:00
|
|
|
let
|
|
|
|
cfg = config.services.lvm;
|
|
|
|
in {
|
|
|
|
options.services.lvm = {
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = if cfg.dmeventd.enable then pkgs.lvm2_dmeventd else pkgs.lvm2;
|
|
|
|
internal = true;
|
|
|
|
defaultText = "pkgs.lvm2";
|
|
|
|
description = ''
|
|
|
|
This option allows you to override the LVM package that's used on the system
|
|
|
|
(udev rules, tmpfiles, systemd services).
|
|
|
|
Defaults to pkgs.lvm2, or pkgs.lvm2_dmeventd if dmeventd is enabled.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
dmeventd.enable = mkEnableOption "the LVM dmevent daemon";
|
|
|
|
boot.thin.enable = mkEnableOption "support for booting from ThinLVs";
|
|
|
|
};
|
2006-12-24 02:07:28 +01:00
|
|
|
|
2020-05-25 03:55:32 +02:00
|
|
|
config = mkMerge [
|
2020-11-14 14:40:32 +01:00
|
|
|
({
|
|
|
|
# minimal configuration file to make lvmconfig/lvm2-activation-generator happy
|
|
|
|
environment.etc."lvm/lvm.conf".text = "config {}";
|
|
|
|
})
|
2020-05-25 03:55:32 +02:00
|
|
|
(mkIf (!config.boot.isContainer) {
|
2020-07-25 20:43:12 +02:00
|
|
|
systemd.tmpfiles.packages = [ cfg.package.out ];
|
2020-05-25 03:55:32 +02:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
systemd.packages = [ cfg.package ];
|
2009-03-06 13:27:28 +01:00
|
|
|
|
2020-05-25 03:55:32 +02:00
|
|
|
# TODO: update once https://github.com/NixOS/nixpkgs/pull/93006 was merged
|
|
|
|
services.udev.packages = [ cfg.package.out ];
|
|
|
|
})
|
|
|
|
(mkIf cfg.dmeventd.enable {
|
|
|
|
systemd.sockets."dm-event".wantedBy = [ "sockets.target" ];
|
|
|
|
systemd.services."lvm2-monitor".wantedBy = [ "sysinit.target" ];
|
2009-03-06 13:27:28 +01:00
|
|
|
|
2020-05-25 03:55:32 +02:00
|
|
|
environment.etc."lvm/lvm.conf".text = ''
|
|
|
|
dmeventd/executable = "${cfg.package}/bin/dmeventd"
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
(mkIf cfg.boot.thin.enable {
|
|
|
|
boot.initrd = {
|
|
|
|
kernelModules = [ "dm-snapshot" "dm-thin-pool" ];
|
2010-01-07 16:55:05 +01:00
|
|
|
|
2020-05-25 03:55:32 +02:00
|
|
|
extraUtilsCommands = ''
|
2021-08-05 15:39:18 +02:00
|
|
|
for BIN in ${pkgs.thin-provisioning-tools}/bin/*; do
|
|
|
|
copy_bin_and_libs $BIN
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
extraUtilsCommandsTest = ''
|
|
|
|
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 03:55:32 +02:00
|
|
|
'';
|
|
|
|
};
|
2010-01-07 23:39:35 +01:00
|
|
|
|
2021-08-05 15:39:18 +02: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" ];
|
2020-05-25 03:55:32 +02:00
|
|
|
})
|
|
|
|
(mkIf (cfg.dmeventd.enable || cfg.boot.thin.enable) {
|
|
|
|
boot.initrd.preLVMCommands = ''
|
|
|
|
mkdir -p /etc/lvm
|
|
|
|
cat << EOF >> /etc/lvm/lvm.conf
|
2021-08-05 15:39:18 +02: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 03:55:32 +02:00
|
|
|
${optionalString cfg.dmeventd.enable ''
|
|
|
|
dmeventd/executable = "$(command -v false)"
|
|
|
|
activation/monitoring = 0
|
|
|
|
''}
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
];
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2006-12-24 02:07:28 +01:00
|
|
|
}
|