Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nixos/modules/system/boot/systemd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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";
Expand Down
65 changes: 55 additions & 10 deletions nixos/modules/tasks/lvm.nix
Original file line number Diff line number Diff line change
@@ -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
'';
})
];

}
35 changes: 32 additions & 3 deletions nixos/tests/installer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand All @@ -238,6 +239,7 @@ let
with subtest("Set grub to boot the second configuration"):
machine.succeed("grub-reboot 1")

${postBootCommands}
machine.shutdown()

# Reboot Machine
Expand All @@ -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
Expand Down Expand Up @@ -335,7 +338,7 @@ let
};

testScript = testScriptFun {
inherit bootLoader createPartitions preBootCommands
inherit bootLoader createPartitions preBootCommands postBootCommands
grubVersion grubDevice grubIdentifier grubUseEfi extraConfig
testSpecialisationConfig;
};
Expand Down Expand Up @@ -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" "";

Expand Down
104 changes: 61 additions & 43 deletions pkgs/os-specific/linux/lvm2/default.nix
Original file line number Diff line number Diff line change
@@ -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 "<removed>"|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 {
Expand All @@ -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 ];
};
}
4 changes: 0 additions & 4 deletions pkgs/os-specific/linux/lvm2/default.upstream

This file was deleted.

34 changes: 0 additions & 34 deletions pkgs/os-specific/linux/systemd/cryptsetup-generator.nix

This file was deleted.

Loading