From 2d2b7513d90384cb3426ed790992ae70c5bb1c16 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 5 May 2020 16:56:13 +0200 Subject: [PATCH 01/17] lvm2: remove unused default.upstream file --- pkgs/os-specific/linux/lvm2/default.upstream | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 pkgs/os-specific/linux/lvm2/default.upstream diff --git a/pkgs/os-specific/linux/lvm2/default.upstream b/pkgs/os-specific/linux/lvm2/default.upstream deleted file mode 100644 index 1e5aaf5ab5c..00000000000 --- a/pkgs/os-specific/linux/lvm2/default.upstream +++ /dev/null @@ -1,4 +0,0 @@ -url ftp://sources.redhat.com/pub/lvm2/ -version_link '[.]tgz$' -version '.*[^0-9.][^.]*[.]([0-9.]+)[.].*' '\1' -do_overwrite () { do_overwrite_just_version; } From 5e1eb7bd59d347c8955679945f342673005f82b8 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 19 Aug 2019 02:06:10 +0200 Subject: [PATCH 02/17] lvm2: cleanups, make udev optional - use installTargets again ("install", and "install_systemd_{generators,units,configuration}" when udev is not null) - The call to the blkid binary in lvm2's 13-dm-disk.rules file disappeared (so we don't need to patch in blkid anymore). lvm seems to rely on udev's internal blkid functionality. - Call /run/current-system/systemd/bin/udevadm instead of ${systemd}/bin/udevadm in the lvm activation generator. This is not necessary to break the dependency cycle (as we don't use that file when building without udev), but a good idea anyways - We want to trigger the udevadm of the current system, not the one that lvm was built with. --- pkgs/os-specific/linux/lvm2/default.nix | 71 +++++++++++++------------ pkgs/top-level/all-packages.nix | 4 +- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index 8db4be94e4e..ee1d95bf0bd 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -1,13 +1,20 @@ -{ stdenv, fetchgit, fetchpatch, pkgconfig, systemd, udev, utillinux, libuuid +{ stdenv +, fetchgit +, fetchpatch +, pkgconfig +, utillinux +, libuuid , thin-provisioning-tools, libaio -, enable_dmeventd ? false }: +, enable_dmeventd ? false +, udev ? null +}: let version = "2.03.01"; in -stdenv.mkDerivation { - pname = "lvm2"; +{ + pname = "lvm2" + stdenv.lib.optionalString enable_dmeventd "with-dmeventd"; inherit version; src = fetchgit { @@ -16,33 +23,32 @@ stdenv.mkDerivation { sha256 = "0jlaswf1srdxiqpgpp97j950ddjds8z0kr4pbwmal2za2blrgvbl"; }; + nativeBuildInputs = [ pkgconfig ]; + buildInputs = [ udev libuuid thin-provisioning-tools libaio ]; + configureFlags = [ "--disable-readline" - "--enable-udev_rules" - "--enable-udev_sync" "--enable-pkgconfig" "--enable-cmdlib" ] ++ stdenv.lib.optional enable_dmeventd " --enable-dmeventd" ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "ac_cv_func_malloc_0_nonnull=yes" "ac_cv_func_realloc_0_nonnull=yes" + ] ++ + stdenv.lib.optionals (udev != null) [ + "--enable-udev_rules" + "--enable-udev_sync" ]; - nativeBuildInputs = [ pkgconfig ]; - buildInputs = [ udev libuuid thin-provisioning-tools libaio ]; + preConfigure = '' + sed -i /DEFAULT_SYS_DIR/d Makefile.in + sed -i /DEFAULT_PROFILE_DIR/d conf/Makefile.in + substituteInPlace scripts/lvm2_activation_generator_systemd_red_hat.c \ + --replace /usr/bin/udevadm /run/current-system/systemd/bin/udevadm - preConfigure = - '' - sed -i /DEFAULT_SYS_DIR/d Makefile.in - sed -i /DEFAULT_PROFILE_DIR/d conf/Makefile.in - '' + stdenv.lib.optionalString (systemd != null) '' - substituteInPlace scripts/lvm2_activation_generator_systemd_red_hat.c \ - --replace /usr/bin/udevadm ${systemd}/bin/udevadm - ''; - - # https://github.com/NixOS/nixpkgs/pull/52597 - # gcc: error: ../../device_mapper/libdevice-mapper.a: No such file or directory - enableParallelBuilding = false; + substituteInPlace make.tmpl.in --replace "@systemdsystemunitdir@" "$out/lib/systemd/system" + substituteInPlace libdm/make.tmpl.in --replace "@systemdsystemunitdir@" "$out/lib/systemd/system" + ''; patches = stdenv.lib.optionals stdenv.hostPlatform.isMusl [ (fetchpatch { @@ -64,30 +70,25 @@ stdenv.mkDerivation { doCheck = false; # requires root + makeFlags = stdenv.lib.optionals (udev != null) [ + "SYSTEMD_GENERATOR_DIR=$(out)/lib/systemd/system-generators" + ]; + # To prevent make install from failing. installFlags = [ "OWNER=" "GROUP=" "confdir=$(out)/etc" ]; # Install systemd stuff. - #installTargets = "install install_systemd_generators install_systemd_units install_tmpfiles_configuration"; - - postInstall = - '' - substituteInPlace $out/lib/udev/rules.d/13-dm-disk.rules \ - --replace $out/sbin/blkid ${utillinux}/sbin/blkid - '' + stdenv.lib.optionalString (systemd != null) '' - # Systemd stuff - mkdir -p $out/etc/systemd/system $out/lib/systemd/system-generators - cp scripts/blk_availability_systemd_red_hat.service $out/etc/systemd/system - cp scripts/lvm2_activation_generator_systemd_red_hat $out/lib/systemd/system-generators - ''; + installTargets = [ "install" ] ++ stdenv.lib.optionals (udev != null) [ + "install_systemd_generators" + "install_systemd_units" + "install_tmpfiles_configuration" + ]; meta = with stdenv.lib; { homepage = "http://sourceware.org/lvm2/"; description = "Tools to support Logical Volume Management (LVM) on Linux"; platforms = platforms.linux; license = with licenses; [ gpl2 bsd2 lgpl21 ]; - maintainers = with maintainers; [raskin]; - inherit version; - downloadPage = "ftp://sources.redhat.com/pub/lvm2/"; + maintainers = with maintainers; [ raskin ]; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 4f007ffaba9..5bcff8c58c2 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -16817,9 +16817,7 @@ in directvnc = callPackage ../os-specific/linux/directvnc { }; - dmraid = callPackage ../os-specific/linux/dmraid { - lvm2 = lvm2.override {enable_dmeventd = true;}; - }; + dmraid = callPackage ../os-specific/linux/dmraid { }; drbd = callPackage ../os-specific/linux/drbd { }; From 33030f1bd2d8b451eec5fabd2208a1381bf7d2d4 Mon Sep 17 00:00:00 2001 From: ajs124 Date: Fri, 22 May 2020 01:59:29 +0200 Subject: [PATCH 03/17] lvm2: add myself as maintainer --- pkgs/os-specific/linux/lvm2/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index ee1d95bf0bd..a068de6a81d 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -89,6 +89,6 @@ in description = "Tools to support Logical Volume Management (LVM) on Linux"; platforms = platforms.linux; license = with licenses; [ gpl2 bsd2 lgpl21 ]; - maintainers = with maintainers; [ raskin ]; + maintainers = with maintainers; [ raskin ajs124 ]; }; } From fbe70272514d3d9ab8bb251666939b98d10ac852 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 30 Apr 2020 16:45:17 +0200 Subject: [PATCH 04/17] lvm2: fetch sources from http instead of git Otherwise, we end up in a dependency cycle: systemd -> cryptsetup -> lvm -> fetchgit -> git -> openssh -> libfido2 -> hidapi -> libusb -> udev=systemd --- pkgs/os-specific/linux/lvm2/default.nix | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index a068de6a81d..9dae5158e1f 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -1,6 +1,6 @@ { stdenv -, fetchgit , fetchpatch +, fetchurl , pkgconfig , utillinux , libuuid @@ -17,10 +17,9 @@ in pname = "lvm2" + stdenv.lib.optionalString enable_dmeventd "with-dmeventd"; inherit version; - src = fetchgit { - url = "git://sourceware.org/git/lvm2.git"; - rev = "v${builtins.replaceStrings [ "." ] [ "_" ] version}"; - sha256 = "0jlaswf1srdxiqpgpp97j950ddjds8z0kr4pbwmal2za2blrgvbl"; + src = fetchurl { + url = "https://mirrors.kernel.org/sourceware/lvm2/LVM2.${version}.tgz"; + sha256 = "02sk6p8w3f6fpm1mrsisqfc0jnah4pzimyhm0f7c0phrfjq5hkj2"; }; nativeBuildInputs = [ pkgconfig ]; From 3ca74a976ac0880d06d2a9546aa6a8c77ecc216e Mon Sep 17 00:00:00 2001 From: ajs124 Date: Mon, 25 May 2020 03:37:44 +0200 Subject: [PATCH 05/17] lvm2: 2.03.01 -> 2.03.09 --- pkgs/os-specific/linux/lvm2/default.nix | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index 9dae5158e1f..bb06b10c23b 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -9,17 +9,13 @@ , udev ? null }: -let - version = "2.03.01"; -in - -{ +stdenv.mkDerivation rec { pname = "lvm2" + stdenv.lib.optionalString enable_dmeventd "with-dmeventd"; - inherit version; + version = "2.03.09"; src = fetchurl { url = "https://mirrors.kernel.org/sourceware/lvm2/LVM2.${version}.tgz"; - sha256 = "02sk6p8w3f6fpm1mrsisqfc0jnah4pzimyhm0f7c0phrfjq5hkj2"; + sha256 = "0xdr9qbqw6kja267wmx6ajnfv1nhw056gpxx9v2qmfh3bj6qnfn0"; }; nativeBuildInputs = [ pkgconfig ]; From 198d1e6f5cb3eaca9f09ca05c28edc0bb1a1ace1 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 24 May 2020 02:22:51 +0200 Subject: [PATCH 06/17] lvm2: make --enable-cmdlib optional This seems to be mostly used to simplify LV management tasks from a web interface (https://www.redhat.com/archives/linux-lvm/2008-September/msg00029.html), and is as fat as the `lvm` binary itself --- pkgs/os-specific/linux/lvm2/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index bb06b10c23b..0e5a349da02 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -5,10 +5,14 @@ , utillinux , libuuid , thin-provisioning-tools, libaio +, enable_cmdlib ? false , enable_dmeventd ? false , udev ? null }: +# configure: error: --enable-dmeventd requires --enable-cmdlib to be used as well +assert enable_dmeventd -> enable_cmdlib; + stdenv.mkDerivation rec { pname = "lvm2" + stdenv.lib.optionalString enable_dmeventd "with-dmeventd"; version = "2.03.09"; @@ -24,8 +28,8 @@ stdenv.mkDerivation rec { configureFlags = [ "--disable-readline" "--enable-pkgconfig" - "--enable-cmdlib" ] ++ stdenv.lib.optional enable_dmeventd " --enable-dmeventd" + ++ stdenv.lib.optional enable_cmdlib "--enable-cmdlib" ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "ac_cv_func_malloc_0_nonnull=yes" "ac_cv_func_realloc_0_nonnull=yes" From df67459b89d69b9edde653efa6cb8d702179be0b Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 24 May 2020 02:25:18 +0200 Subject: [PATCH 07/17] lvm2: don't embed ./configure line in lvm2 binary --- pkgs/os-specific/linux/lvm2/default.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index 0e5a349da02..6d62d770e4d 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -49,6 +49,11 @@ stdenv.mkDerivation rec { substituteInPlace libdm/make.tmpl.in --replace "@systemdsystemunitdir@" "$out/lib/systemd/system" ''; + postConfigure = '' + sed -i 's|^#define LVM_CONFIGURE_LINE.*$|#define LVM_CONFIGURE_LINE ""|g' ./include/configure.h + ''; + + patches = stdenv.lib.optionals stdenv.hostPlatform.isMusl [ (fetchpatch { name = "fix-stdio-usage.patch"; From d3a991d41028c5d2a5af2796c0bb542836457822 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 24 May 2020 02:27:51 +0200 Subject: [PATCH 08/17] lvm2: add multiple output support --- nixos/modules/system/boot/stage-1.nix | 6 +++--- pkgs/os-specific/linux/lvm2/default.nix | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index d551466f52e..63005b26f6f 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -111,8 +111,8 @@ let copy_bin_and_libs ${pkgs.utillinux}/sbin/blkid # Copy dmsetup and lvm. - copy_bin_and_libs ${pkgs.lvm2}/sbin/dmsetup - copy_bin_and_libs ${pkgs.lvm2}/sbin/lvm + copy_bin_and_libs ${getBin pkgs.lvm2}/bin/dmsetup + copy_bin_and_libs ${getBin pkgs.lvm2}/bin/lvm # Add RAID mdadm tool. copy_bin_and_libs ${pkgs.mdadm}/sbin/mdadm @@ -235,7 +235,7 @@ let --replace cdrom_id ${extraUtils}/bin/cdrom_id \ --replace ${pkgs.coreutils}/bin/basename ${extraUtils}/bin/basename \ --replace ${pkgs.utillinux}/bin/blkid ${extraUtils}/bin/blkid \ - --replace ${pkgs.lvm2}/sbin ${extraUtils}/bin \ + --replace ${getBin pkgs.lvm2}/bin ${extraUtils}/bin \ --replace ${pkgs.mdadm}/sbin ${extraUtils}/sbin \ --replace ${pkgs.bash}/bin/sh ${extraUtils}/bin/sh \ --replace ${udev} ${extraUtils} diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index 6d62d770e4d..5dffe04fe72 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -28,6 +28,9 @@ stdenv.mkDerivation rec { configureFlags = [ "--disable-readline" "--enable-pkgconfig" + "--bindir=${placeholder "bin"}/bin" + "--sbindir=${placeholder "bin"}/bin" + "--libdir=${placeholder "lib"}/lib" ] ++ stdenv.lib.optional enable_dmeventd " --enable-dmeventd" ++ stdenv.lib.optional enable_cmdlib "--enable-cmdlib" ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ @@ -88,6 +91,12 @@ stdenv.mkDerivation rec { "install_tmpfiles_configuration" ]; + postInstall = '' + moveToOutput lib/libdevmapper.so $lib + ''; + + outputs = [ "out" "bin" "lib" "dev" "man" ]; + meta = with stdenv.lib; { homepage = "http://sourceware.org/lvm2/"; description = "Tools to support Logical Volume Management (LVM) on Linux"; From e6a6846d4fc0af05efa5bafc878ca710514798f6 Mon Sep 17 00:00:00 2001 From: ajs124 Date: Thu, 21 May 2020 22:03:50 +0200 Subject: [PATCH 09/17] lvm2: fix paths to use /run instead of /var/run. This shuts up some warnings. --- pkgs/os-specific/linux/lvm2/default.nix | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index 5dffe04fe72..93091e04557 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -31,8 +31,14 @@ stdenv.mkDerivation rec { "--bindir=${placeholder "bin"}/bin" "--sbindir=${placeholder "bin"}/bin" "--libdir=${placeholder "lib"}/lib" - ] ++ stdenv.lib.optional enable_dmeventd " --enable-dmeventd" - ++ stdenv.lib.optional enable_cmdlib "--enable-cmdlib" + "--with-default-locking-dir=/run/lock/lvm" + "--with-default-run-dir=/run/lvm" + "--with-systemdsystemunitdir=${placeholder "out"}/lib/systemd/system" + ] ++ stdenv.lib.optionals enable_dmeventd [ + "--enable-dmeventd" + "--with-dmeventd-pidfile=/run/dmeventd/pid" + "--with-default-dm-run-dir=/run/dmeventd" + ] ++ stdenv.lib.optional enable_cmdlib "--enable-cmdlib" ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "ac_cv_func_malloc_0_nonnull=yes" "ac_cv_func_realloc_0_nonnull=yes" From b8129312bd6d0849e108c4821eecf9f53f72c2f3 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 12 Jul 2020 18:09:08 +0200 Subject: [PATCH 10/17] lvm2: fix location to systemd-run invocation --- pkgs/os-specific/linux/lvm2/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index 93091e04557..fbde55b75ee 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -53,6 +53,9 @@ stdenv.mkDerivation rec { sed -i /DEFAULT_PROFILE_DIR/d conf/Makefile.in substituteInPlace scripts/lvm2_activation_generator_systemd_red_hat.c \ --replace /usr/bin/udevadm /run/current-system/systemd/bin/udevadm + # https://github.com/lvmteam/lvm2/issues/36 + substituteInPlace udev/69-dm-lvm-metad.rules.in \ + --replace "(BINDIR)/systemd-run" /run/current-system/systemd/bin/systemd-run substituteInPlace make.tmpl.in --replace "@systemdsystemunitdir@" "$out/lib/systemd/system" substituteInPlace libdm/make.tmpl.in --replace "@systemdsystemunitdir@" "$out/lib/systemd/system" From 9f8390701363a767cb409a2931402a4effb972c7 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 12 Jul 2020 11:29:38 +0200 Subject: [PATCH 11/17] lvm2: only split bin and lib out from out if cmdlib isn't enabled --- pkgs/os-specific/linux/lvm2/default.nix | 27 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index fbde55b75ee..35624f421fa 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -28,18 +28,19 @@ stdenv.mkDerivation rec { configureFlags = [ "--disable-readline" "--enable-pkgconfig" - "--bindir=${placeholder "bin"}/bin" - "--sbindir=${placeholder "bin"}/bin" - "--libdir=${placeholder "lib"}/lib" "--with-default-locking-dir=/run/lock/lvm" "--with-default-run-dir=/run/lvm" "--with-systemdsystemunitdir=${placeholder "out"}/lib/systemd/system" - ] ++ stdenv.lib.optionals enable_dmeventd [ + ] ++ stdenv.lib.optionals (!enable_cmdlib) [ + "--bindir=${placeholder "bin"}/bin" + "--sbindir=${placeholder "bin"}/bin" + "--libdir=${placeholder "lib"}/lib" + ] ++ stdenv.lib.optional enable_cmdlib "--enable-cmdlib" + ++ stdenv.lib.optionals enable_dmeventd [ "--enable-dmeventd" "--with-dmeventd-pidfile=/run/dmeventd/pid" "--with-default-dm-run-dir=/run/dmeventd" - ] ++ stdenv.lib.optional enable_cmdlib "--enable-cmdlib" - ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + ] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "ac_cv_func_malloc_0_nonnull=yes" "ac_cv_func_realloc_0_nonnull=yes" ] ++ @@ -100,12 +101,20 @@ stdenv.mkDerivation rec { "install_tmpfiles_configuration" ]; - postInstall = '' + # only split bin and lib out from out if cmdlib isn't enabled + outputs = [ + "out" + "dev" + "man" + ] ++ stdenv.lib.optionals (enable_cmdlib != true) [ + "bin" + "lib" + ]; + + postInstall = stdenv.lib.optionalString (enable_cmdlib != true) '' moveToOutput lib/libdevmapper.so $lib ''; - outputs = [ "out" "bin" "lib" "dev" "man" ]; - meta = with stdenv.lib; { homepage = "http://sourceware.org/lvm2/"; description = "Tools to support Logical Volume Management (LVM) on Linux"; From 1a1e7237de905ecbc990d17af8ff87a667aa312c Mon Sep 17 00:00:00 2001 From: ajs124 Date: Mon, 25 May 2020 03:55:32 +0200 Subject: [PATCH 12/17] nixos/tasks/lvm: add dmeventd and lvmthin support Introduce a pkgs.lvm2_dmeventd that contains dmeventd support, and enable if services.lvm.dmeventd.enable is true. --- nixos/modules/tasks/lvm.nix | 75 ++++++++++++++++++++++++++++----- pkgs/top-level/all-packages.nix | 6 ++- 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/nixos/modules/tasks/lvm.nix b/nixos/modules/tasks/lvm.nix index d56a8a2f63a..b8f7a01e44e 100644 --- a/nixos/modules/tasks/lvm.nix +++ b/nixos/modules/tasks/lvm.nix @@ -1,17 +1,70 @@ { config, lib, pkgs, ... }: with lib; - -{ - - ###### implementation - - config = mkIf (!config.boot.isContainer) { - - environment.systemPackages = [ pkgs.lvm2 ]; - - services.udev.packages = [ pkgs.lvm2 ]; - +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"; }; + config = mkMerge [ + (mkIf (!config.boot.isContainer) { + environment.etc."tmpfiles.d/lvm2.conf".source = "${cfg.package}/lib/tmpfiles.d/lvm2.conf"; + environment.systemPackages = [ cfg.package ]; + systemd.packages = [ cfg.package ]; + + # 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" ]; + + 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" ]; + + extraUtilsCommands = '' + copy_bin_and_libs ${pkgs.thin-provisioning-tools}/bin/pdata_tools + copy_bin_and_libs ${pkgs.thin-provisioning-tools}/bin/thin_check + ''; + }; + + environment.etc."lvm/lvm.conf".text = '' + global/thin_check_executable = "${pkgs.thin-provisioning-tools}/bin/thin_check" + ''; + }) + (mkIf (cfg.dmeventd.enable || cfg.boot.thin.enable) { + boot.initrd.preLVMCommands = '' + mkdir -p /etc/lvm + cat << EOF >> /etc/lvm/lvm.conf + ${optionalString cfg.boot.thin.enable '' + global/thin_check_executable = "$(command -v thin_check)" + ''} + ${optionalString cfg.dmeventd.enable '' + dmeventd/executable = "$(command -v false)" + activation/monitoring = 0 + ''} + EOF + ''; + }) + ]; + } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5bcff8c58c2..b6d506a8e7d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -16817,7 +16817,7 @@ in directvnc = callPackage ../os-specific/linux/directvnc { }; - dmraid = callPackage ../os-specific/linux/dmraid { }; + dmraid = callPackage ../os-specific/linux/dmraid { lvm2 = lvm2_dmeventd; }; drbd = callPackage ../os-specific/linux/drbd { }; @@ -17520,6 +17520,10 @@ in lsscsi = callPackage ../os-specific/linux/lsscsi { }; lvm2 = callPackage ../os-specific/linux/lvm2 { }; + lvm2_dmeventd = callPackage ../os-specific/linux/lvm2 { + enable_dmeventd = true; + enable_cmdlib = true; + }; mbpfan = callPackage ../os-specific/linux/mbpfan { }; From e55ef86ebda5f21c17315be2950c1de5670ddc08 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 13 May 2019 18:18:27 +0200 Subject: [PATCH 13/17] systemd_with_lvm2: remove This is already handled by the lvm module, which now properly adds the lvm systemd generators. Initially introduced in c0fd88748a66c9ca38092fdbf7e97f765c8e411d. --- pkgs/top-level/aliases.nix | 1 + pkgs/top-level/all-packages.nix | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index 6cd260467f4..690c785a346 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -557,6 +557,7 @@ mapAliases ({ surf-webkit2 = surf; # added 2017-04-02 sup = throw "deprecated in 2019-09-10: abandoned by upstream"; system_config_printer = system-config-printer; # added 2016-01-03 + systemd_with_lvm2 = throw "obsolete, enabled by default via the lvm module"; # added 2020-07-12 systool = sysfsutils; # added 2018-04-25 tahoelafs = tahoe-lafs; # added 2018-03-26 tangogps = foxtrotgps; # added 2020-01-26 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b6d506a8e7d..33437f2ccea 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17842,14 +17842,6 @@ in # standalone cryptsetup generator for systemd systemd-cryptsetup-generator = callPackage ../os-specific/linux/systemd/cryptsetup-generator.nix { }; - # In nixos, you can set systemd.package = pkgs.systemd_with_lvm2 to get - # LVM2 working in systemd. - systemd_with_lvm2 = pkgs.appendToName "with-lvm2" (pkgs.lib.overrideDerivation pkgs.systemd (p: { - postInstall = p.postInstall + '' - cp "${pkgs.lvm2}/lib/systemd/system-generators/"* $out/lib/systemd/system-generators - ''; - })); - systemd-wait = callPackage ../os-specific/linux/systemd-wait { }; sysvinit = callPackage ../os-specific/linux/sysvinit { }; From d056f6e86d39f803eacc8b70501cead76d58c069 Mon Sep 17 00:00:00 2001 From: ajs124 Date: Mon, 25 May 2020 04:05:55 +0200 Subject: [PATCH 14/17] nixos/test/installer: add postBootCommands --- nixos/tests/installer.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix index eef9abebf9f..158a19925c2 100644 --- a/nixos/tests/installer.nix +++ b/nixos/tests/installer.nix @@ -64,7 +64,7 @@ let # a test script fragment `createPartitions', which must create # partitions and filesystems. testScriptFun = { bootLoader, createPartitions, grubVersion, grubDevice, grubUseEfi - , grubIdentifier, preBootCommands, extraConfig + , grubIdentifier, preBootCommands, postBootCommands, extraConfig , testSpecialisationConfig }: let iface = if grubVersion == 1 then "ide" else "virtio"; @@ -216,6 +216,7 @@ let machine = create_machine_named("boot-after-rebuild-switch") ${preBootCommands} machine.wait_for_unit("network.target") + ${postBootCommands} machine.shutdown() # Tests for validating clone configuration entries in grub menu @@ -238,6 +239,7 @@ let with subtest("Set grub to boot the second configuration"): machine.succeed("grub-reboot 1") + ${postBootCommands} machine.shutdown() # Reboot Machine @@ -252,12 +254,13 @@ let with subtest("We should find a file named /etc/gitconfig"): machine.succeed("test -e /etc/gitconfig") + ${postBootCommands} machine.shutdown() ''; makeInstallerTest = name: - { createPartitions, preBootCommands ? "", extraConfig ? "" + { createPartitions, preBootCommands ? "", postBootCommands ? "", extraConfig ? "" , extraInstallerConfig ? {} , bootLoader ? "grub" # either "grub" or "systemd-boot" , grubVersion ? 2, grubDevice ? "/dev/vda", grubIdentifier ? "uuid", grubUseEfi ? false @@ -335,7 +338,7 @@ let }; testScript = testScriptFun { - inherit bootLoader createPartitions preBootCommands + inherit bootLoader createPartitions preBootCommands postBootCommands grubVersion grubDevice grubIdentifier grubUseEfi extraConfig testSpecialisationConfig; }; From 53a34361afe7b58db95c77cd99f268fd933e4053 Mon Sep 17 00:00:00 2001 From: ajs124 Date: Sun, 31 May 2020 23:31:11 +0200 Subject: [PATCH 15/17] nixos/tests/installer: lvm: test lvm2-pvscan@ units Also, add some sleep statements in between, which seems to at least feel like it causes > WARNING: Device /dev/vda* not initialized in udev database even after waiting 10000000 microseconds. To occur less frequently. This eventually still succeeds after some amount of waiting, I suspect some racyness in the way lvm's udev-triggered scripts trigger other units. --- nixos/tests/installer.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix index 158a19925c2..22132073142 100644 --- a/nixos/tests/installer.nix +++ b/nixos/tests/installer.nix @@ -555,16 +555,26 @@ in { + " mkpart primary 2048M -1s" # PV2 + " set 2 lvm on", "udevadm settle", + "sleep 1", "pvcreate /dev/vda1 /dev/vda2", + "sleep 1", "vgcreate MyVolGroup /dev/vda1 /dev/vda2", + "sleep 1", "lvcreate --size 1G --name swap MyVolGroup", + "sleep 1", "lvcreate --size 2G --name nixos MyVolGroup", + "sleep 1", "mkswap -f /dev/MyVolGroup/swap -L swap", "swapon -L swap", "mkfs.xfs -L nixos /dev/MyVolGroup/nixos", "mount LABEL=nixos /mnt", ) ''; + postBootCommands = '' + assert "loaded active" in machine.succeed( + "systemctl list-units 'lvm2-pvscan@*' -ql --no-legend | tee /dev/stderr" + ) + ''; }; # Boot off an encrypted root partition with the default LUKS header format From 12d32eefede3f5b5becbb87c6c69bfe1d82cd79d Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 14 Jul 2020 11:19:43 +0200 Subject: [PATCH 16/17] lvm2: rename enable_{cmdlib,dmeventd} to enable{Cmdlib,Dmeventd} Make this more consistent with how these flags look like in the rest of nixpkgs. --- pkgs/os-specific/linux/lvm2/default.nix | 18 +++++++++--------- pkgs/top-level/all-packages.nix | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index 35624f421fa..a6db883cc2c 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -5,16 +5,16 @@ , utillinux , libuuid , thin-provisioning-tools, libaio -, enable_cmdlib ? false -, enable_dmeventd ? false +, enableCmdlib ? false +, enableDmeventd ? false , udev ? null }: # configure: error: --enable-dmeventd requires --enable-cmdlib to be used as well -assert enable_dmeventd -> enable_cmdlib; +assert enableDmeventd -> enableCmdlib; stdenv.mkDerivation rec { - pname = "lvm2" + stdenv.lib.optionalString enable_dmeventd "with-dmeventd"; + pname = "lvm2" + stdenv.lib.optionalString enableDmeventd "with-dmeventd"; version = "2.03.09"; src = fetchurl { @@ -31,12 +31,12 @@ stdenv.mkDerivation rec { "--with-default-locking-dir=/run/lock/lvm" "--with-default-run-dir=/run/lvm" "--with-systemdsystemunitdir=${placeholder "out"}/lib/systemd/system" - ] ++ stdenv.lib.optionals (!enable_cmdlib) [ + ] ++ stdenv.lib.optionals (!enableCmdlib) [ "--bindir=${placeholder "bin"}/bin" "--sbindir=${placeholder "bin"}/bin" "--libdir=${placeholder "lib"}/lib" - ] ++ stdenv.lib.optional enable_cmdlib "--enable-cmdlib" - ++ stdenv.lib.optionals enable_dmeventd [ + ] ++ stdenv.lib.optional enableCmdlib "--enable-cmdlib" + ++ stdenv.lib.optionals enableDmeventd [ "--enable-dmeventd" "--with-dmeventd-pidfile=/run/dmeventd/pid" "--with-default-dm-run-dir=/run/dmeventd" @@ -106,12 +106,12 @@ stdenv.mkDerivation rec { "out" "dev" "man" - ] ++ stdenv.lib.optionals (enable_cmdlib != true) [ + ] ++ stdenv.lib.optionals (enableCmdlib != true) [ "bin" "lib" ]; - postInstall = stdenv.lib.optionalString (enable_cmdlib != true) '' + postInstall = stdenv.lib.optionalString (enableCmdlib != true) '' moveToOutput lib/libdevmapper.so $lib ''; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 33437f2ccea..29d6ef654e5 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17521,8 +17521,8 @@ in lvm2 = callPackage ../os-specific/linux/lvm2 { }; lvm2_dmeventd = callPackage ../os-specific/linux/lvm2 { - enable_dmeventd = true; - enable_cmdlib = true; + enableDmeventd = true; + enableCmdlib = true; }; mbpfan = callPackage ../os-specific/linux/mbpfan { }; From 9583669422381779ad10eeb75a60bfa310bf03b4 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 14 Jul 2020 12:56:26 +0200 Subject: [PATCH 17/17] lvm2: passthru tests --- pkgs/os-specific/linux/lvm2/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index a6db883cc2c..8bfdb37360d 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -8,6 +8,7 @@ , enableCmdlib ? false , enableDmeventd ? false , udev ? null +, nixosTests }: # configure: error: --enable-dmeventd requires --enable-cmdlib to be used as well @@ -115,6 +116,8 @@ stdenv.mkDerivation rec { moveToOutput lib/libdevmapper.so $lib ''; + passthru.tests.installer = nixosTests.installer.lvm; + meta = with stdenv.lib; { homepage = "http://sourceware.org/lvm2/"; description = "Tools to support Logical Volume Management (LVM) on Linux";