diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index 58e2f9d3bfce3..6cbab49582638 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -25,7 +25,7 @@ let "nss-lookup.target" "nss-user-lookup.target" "time-sync.target" - #"cryptsetup.target" + "cryptsetup.target" "sigpwr.target" "timers.target" "paths.target" @@ -919,6 +919,7 @@ in "tmpfiles.d/home.conf".source = "${systemd}/example/tmpfiles.d/home.conf"; "tmpfiles.d/journal-nocow.conf".source = "${systemd}/example/tmpfiles.d/journal-nocow.conf"; + "tmpfiles.d/lvm2.conf".source = "${pkgs.lvm2}/lib/tmpfiles.d/lvm2.conf"; "tmpfiles.d/portables.conf".source = "${systemd}/example/tmpfiles.d/portables.conf"; "tmpfiles.d/static-nodes-permissions.conf".source = "${systemd}/example/tmpfiles.d/static-nodes-permissions.conf"; "tmpfiles.d/systemd.conf".source = "${systemd}/example/tmpfiles.d/systemd.conf"; diff --git a/nixos/modules/tasks/lvm.nix b/nixos/modules/tasks/lvm.nix index d56a8a2f63a8d..3d25aabc8ac21 100644 --- a/nixos/modules/tasks/lvm.nix +++ b/nixos/modules/tasks/lvm.nix @@ -1,17 +1,62 @@ { config, lib, pkgs, ... }: with lib; +let + cfg = config.services.lvm; +in { + + options.services.lvm = { + dmeventd = { + enable = mkEnableOption "the LVM dmevent daemon"; + }; + boot.thin = { + enable = mkEnableOption "support for booting from ThinLVs"; + }; + }; -{ - - ###### implementation - - config = mkIf (!config.boot.isContainer) { - - environment.systemPackages = [ pkgs.lvm2 ]; - - services.udev.packages = [ pkgs.lvm2 ]; - }; + config = mkMerge [ + (mkIf (!config.boot.isContainer) { + environment.systemPackages = [ pkgs.lvm2 ]; + services.udev.packages = [ pkgs.lvm2 ]; + systemd.packages = [ pkgs.lvm2 ]; + }) + (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 = "${pkgs.lvm2}/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.thin.enable '' + global/thin_check_executable = "$(which thin_check) + ''} + ${optionalString cfg.dmeventd.enable '' + dmeventd/executable = "$(which false)" + activation/monitoring = 0 + ''} + EOF + ''; + }) + ]; } diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix index 8d1bfa96d03d6..9768c273198b5 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; }; @@ -564,6 +567,32 @@ in { ''; }; + lvmSystemdGenerator = makeInstallerTest "lvmSystemdGenerator" { + createPartitions = '' + machine.succeed( + "flock /dev/vda parted --script /dev/vda -- mklabel msdos" + + " mkpart primary 1M 2048M" # PV1 + + " set 1 lvm on" + + " mkpart primary 2048M -1s" # PV2 + + " set 2 lvm on", + "udevadm settle", + "pvcreate /dev/vda1 /dev/vda2", + "vgcreate MyVolGroup /dev/vda1 /dev/vda2", + "lvcreate --size 1G --name swap MyVolGroup", + "lvcreate --size 2G --name nixos MyVolGroup", + "mkswap -f /dev/MyVolGroup/swap -L swap", + "swapon -L swap", + "mkfs.xfs -L nixos /dev/MyVolGroup/nixos", + "mount LABEL=nixos /mnt", + ) + ''; + postBootCommands = '' + machine.succeed("systemctl status lvm2-pvscan@8:1.service") + machine.succeed("systemctl status lvm2-monitor.service") + ''; + }; + + # Boot off an encrypted root partition with the default LUKS header format luksroot = makeLuksRootTest "luksroot-format1" ""; diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix index c7925bae55813..8b6cb754077c3 100644 --- a/pkgs/os-specific/linux/lvm2/default.nix +++ b/pkgs/os-specific/linux/lvm2/default.nix @@ -1,48 +1,65 @@ -{ stdenv, fetchgit, fetchpatch, pkgconfig, systemd, udev, utillinux, libuuid +{ stdenv +, fetchpatch +, fetchurl +, pkgconfig +, utillinux +, libuuid , thin-provisioning-tools, libaio -, enable_dmeventd ? false }: +, enable_cmdlib ? false +, enable_dmeventd ? false +, udev ? null +}: -let - version = "2.03.01"; -in +# configure: error: --enable-dmeventd requires --enable-cmdlib to be used as well +assert enable_dmeventd -> enable_cmdlib; -stdenv.mkDerivation { +stdenv.mkDerivation rec { pname = "lvm2"; - inherit version; + version = "2.03.09"; - 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 = "0xdr9qbqw6kja267wmx6ajnfv1nhw056gpxx9v2qmfh3bj6qnfn0"; }; + 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" + "--bindir=${placeholder "bin"}/bin" + "--sbindir=${placeholder "bin"}/bin" + "--libdir=${placeholder "lib"}/lib" + "--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" + ] ++ + 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 + + substituteInPlace make.tmpl.in --replace "@systemdsystemunitdir@" "$out/lib/systemd/system" + substituteInPlace libdm/make.tmpl.in --replace "@systemdsystemunitdir@" "$out/lib/systemd/system" + ''; - 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 - ''; + postConfigure = '' + sed -i 's|^#define LVM_CONFIGURE_LINE.*$|#define LVM_CONFIGURE_LINE ""|g' ./include/configure.h + ''; - # https://github.com/NixOS/nixpkgs/pull/52597 - # gcc: error: ../../device_mapper/libdevice-mapper.a: No such file or directory - enableParallelBuilding = false; patches = stdenv.lib.optionals stdenv.hostPlatform.isMusl [ (fetchpatch { @@ -64,30 +81,31 @@ 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" + ]; + + 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"; 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 ajs124 ]; }; } diff --git a/pkgs/os-specific/linux/lvm2/default.upstream b/pkgs/os-specific/linux/lvm2/default.upstream deleted file mode 100644 index 1e5aaf5ab5cff..0000000000000 --- 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; } diff --git a/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix b/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix deleted file mode 100644 index 3fd8ff07f425a..0000000000000 --- a/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ systemd, cryptsetup }: - -systemd.overrideAttrs (p: { - version = p.version; - name = "systemd-cryptsetup-generator-${p.version}"; - - buildInputs = p.buildInputs ++ [ cryptsetup ]; - outputs = [ "out" ]; - - buildPhase = '' - ninja systemd-cryptsetup systemd-cryptsetup-generator - ''; - - # As ninja install is not used here, the rpath needs to be manually fixed. - # Otherwise the resulting binary doesn't properly link against systemd-shared.so - postFixup = '' - for prog in `find $out -type f -executable`; do - (patchelf --print-needed $prog | grep 'libsystemd-shared-.*\.so' > /dev/null) && ( - patchelf --set-rpath `patchelf --print-rpath $prog`:"$out/lib/systemd" $prog - ) || true - done - # test it's OK - "$out"/lib/systemd/systemd-cryptsetup - ''; - - installPhase = '' - mkdir -p $out/lib/systemd/ - cp systemd-cryptsetup $out/lib/systemd/systemd-cryptsetup - cp src/shared/*.so $out/lib/systemd/ - - mkdir -p $out/lib/systemd/system-generators/ - cp systemd-cryptsetup-generator $out/lib/systemd/system-generators/systemd-cryptsetup-generator - ''; -}) diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix index 00a545ed3f54f..5dd722c9897d2 100644 --- a/pkgs/os-specific/linux/systemd/default.nix +++ b/pkgs/os-specific/linux/systemd/default.nix @@ -1,5 +1,5 @@ -{ stdenv, lib, fetchFromGitHub, fetchpatch, pkgconfig, intltool, gperf, libcap -, curl, kmod, gnupg, gnutar, xz, pam, acl, libuuid, m4, utillinux, libffi +{ stdenv, lib, fetchFromGitHub, pkgconfig, intltool, gperf, libcap +, curl, kmod, gnupg, gnutar, xz, pam, acl, libuuid, m4, e2fsprogs, utillinux, libffi , glib, kbd, libxslt, coreutils, libgcrypt, libgpgerror, libidn2, libapparmor , audit, lz4, bzip2, libmicrohttpd, pcre2 , linuxHeaders ? stdenv.cc.libc.linuxHeaders @@ -9,6 +9,7 @@ , patchelf , substituteAll , getent +, cryptsetup, lvm2 , buildPackages , perl , withSelinux ? false, libselinux @@ -30,6 +31,7 @@ let gnupg-minimal = gnupg.override { zlib = null; bzip2 = null; }; + in stdenv.mkDerivation { version = "245.5"; pname = "systemd"; @@ -82,7 +84,7 @@ in stdenv.mkDerivation { ]; buildInputs = [ linuxHeaders libcap curl.dev kmod xz pam acl - /* cryptsetup */ libuuid glib libgcrypt libgpgerror libidn2 + cryptsetup libuuid glib libgcrypt libgpgerror libidn2 libmicrohttpd pcre2 ] ++ stdenv.lib.optional withKexectools kexectools ++ stdenv.lib.optional withLibseccomp libseccomp ++ @@ -168,12 +170,28 @@ in stdenv.mkDerivation { export LC_ALL="en_US.UTF-8"; # FIXME: patch this in systemd properly (and send upstream). # already fixed in f00929ad622c978f8ad83590a15a765b4beecac9: (u)mount - for i in src/remount-fs/remount-fs.c src/core/mount.c src/core/swap.c src/fsck/fsck.c units/emergency.service.in units/rescue.service.in src/journal/cat.c src/shutdown/shutdown.c src/nspawn/nspawn.c src/shared/generator.c units/systemd-logind.service.in units/systemd-nspawn@.service.in; do + for i in \ + src/core/mount.c \ + src/core/swap.c \ + src/cryptsetup/cryptsetup-generator.c \ + src/fsck/fsck.c \ + src/journal/cat.c \ + src/nspawn/nspawn.c \ + src/remount-fs/remount-fs.c \ + src/shared/generator.c \ + src/shutdown/shutdown.c \ + units/emergency.service.in \ + units/rescue.service.in \ + units/systemd-logind.service.in \ + units/systemd-nspawn@.service.in; \ + do test -e $i substituteInPlace $i \ --replace /usr/bin/getent ${getent}/bin/getent \ + --replace /sbin/mkswap ${lib.getBin utillinux}/sbin/mkswap \ --replace /sbin/swapon ${lib.getBin utillinux}/sbin/swapon \ --replace /sbin/swapoff ${lib.getBin utillinux}/sbin/swapoff \ + --replace /sbin/mke2fs ${lib.getBin e2fsprogs}/sbin/mke2fs \ --replace /sbin/fsck ${lib.getBin utillinux}/sbin/fsck \ --replace /bin/echo ${coreutils}/bin/echo \ --replace /bin/cat ${coreutils}/bin/cat \ diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index 4837995d11a74..49afad9b2f0ef 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -540,6 +540,8 @@ 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-cryptsetup-generator = throw "systemd-cryptsetup-generator is now included in the systemd package"; # added 2020-05-05 + systemd_with_lvm2 = throw "please set systemd.packages = [ pkgs.lvm2 ]; instead of using systemd_with_lvm2"; # added 2019-05-05 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 2a8583ea0a682..d67ab9adb9305 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -16364,7 +16364,11 @@ in criu = callPackage ../os-specific/linux/criu { }; - cryptsetup = callPackage ../os-specific/linux/cryptsetup { }; + cryptsetup = callPackage ../os-specific/linux/cryptsetup { + # cryptsetup only really needs the devmapper component of cryptsetup + # but itself is used as a library in systemd (=udev) + lvm2 = lvm2.override { udev = null; }; + }; cramfsswap = callPackage ../os-specific/linux/cramfsswap { }; @@ -16390,7 +16394,10 @@ in directvnc = callPackage ../os-specific/linux/directvnc { }; dmraid = callPackage ../os-specific/linux/dmraid { - lvm2 = lvm2.override {enable_dmeventd = true;}; + lvm2 = lvm2.override { + enable_cmdlib = true; + enable_dmeventd = true; + }; }; drbd = callPackage ../os-specific/linux/drbd { }; @@ -17396,17 +17403,6 @@ in }; udev = systemd; # TODO: move to aliases.nix - # 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 { };