From 036b9094211e223dce4de233c0063a6fcd47deb8 Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Tue, 30 Nov 2021 21:39:11 +0100 Subject: [PATCH 1/3] drbd: 8.4.4 -> 9.19.1, ocf-resource-agents: init at 4.10.0 --- pkgs/os-specific/linux/drbd/default.nix | 133 ++++++++++++++---- .../linux/drbd/fix-glibc-compilation.patch | 24 ---- pkgs/os-specific/linux/drbd/pass-force.patch | 15 -- .../linux/ocf-resource-agents/default.nix | 56 ++++++++ pkgs/top-level/all-packages.nix | 2 + 5 files changed, 164 insertions(+), 66 deletions(-) delete mode 100644 pkgs/os-specific/linux/drbd/fix-glibc-compilation.patch delete mode 100644 pkgs/os-specific/linux/drbd/pass-force.patch create mode 100644 pkgs/os-specific/linux/ocf-resource-agents/default.nix diff --git a/pkgs/os-specific/linux/drbd/default.nix b/pkgs/os-specific/linux/drbd/default.nix index 85be205749ac..0c5acd0ac064 100644 --- a/pkgs/os-specific/linux/drbd/default.nix +++ b/pkgs/os-specific/linux/drbd/default.nix @@ -1,49 +1,128 @@ -{ lib, stdenv, fetchurl, flex, systemd, perl }: +{ lib +, stdenv +, docbook_xml_dtd_44 +, docbook_xml_dtd_45 +, docbook_xsl +, asciidoctor +, fetchurl +, flex +, kmod +, libxslt +, nixosTests +, perl +, systemd + +# drbd-utils are compiled twice, once with forOCF = true to extract +# its OCF definitions for use in the ocf-resource-agents derivation, +# then again with forOCF = false, where the ocf-resource-agents is +# provided as the OCF_ROOT. +, forOCF ? false +, ocf-resource-agents +}: stdenv.mkDerivation rec { pname = "drbd"; - version = "8.4.4"; + version = "9.19.1"; src = fetchurl { - url = "http://oss.linbit.com/drbd/8.4/drbd-${version}.tar.gz"; - sha256 = "1w4889h1ak7gy9w33kd4fgjlfpgmp6hzfya16p1pkc13bjf22mm0"; + url = "https://pkg.linbit.com/downloads/drbd/utils/${pname}-utils-${version}.tar.gz"; + sha256 = "1l99kcrb0j85wxxmrdihpx9bk1a4sdi7wlp5m1x5l24k8ck1m5cf"; }; - patches = [ ./pass-force.patch ./fix-glibc-compilation.patch ]; + nativeBuildInputs = [ + flex + libxslt + docbook_xsl + asciidoctor + ]; - nativeBuildInputs = [ flex ]; - buildInputs = [ perl ]; + buildInputs = [ + perl + # perlPackages.Po4a used by ja documentation + ]; configureFlags = [ - "--without-distro" - "--without-pacemaker" + "--libdir=${placeholder "out"}/lib" + "--sbindir=${placeholder "out"}/bin" "--localstatedir=/var" "--sysconfdir=/etc" + "--without-distro" ]; - preConfigure = - '' - export PATH=${systemd}/sbin:$PATH - substituteInPlace user/Makefile.in \ - --replace /sbin '$(sbindir)' - substituteInPlace user/legacy/Makefile.in \ - --replace '$(DESTDIR)/lib/drbd' '$(DESTDIR)$(LIBDIR)' - substituteInPlace user/drbdadm_usage_cnt.c --replace /lib/drbd $out/lib/drbd - substituteInPlace scripts/drbd.rules --replace /usr/sbin/drbdadm $out/sbin/drbdadm - ''; - - makeFlags = [ "SHELL=${stdenv.shell}" ]; + makeFlags = [ + "SOURCE_DATE_EPOCH=1" + "WANT_DRBD_REPRODUCIBLE_BUILD=1" + ] ++ lib.optional (!forOCF) "OCF_ROOT=${ocf-resource-agents}/usr/lib/ocf}"; installFlags = [ - "localstatedir=$(TMPDIR)/var" - "sysconfdir=$(out)/etc" - "INITDIR=$(out)/etc/init.d" + "prefix=" + "DESTDIR=${placeholder "out"}" + "localstatedir=/var" + "DRBD_LIB_DIR=/var/lib" + "INITDIR=/etc/init.d" + "udevrulesdir=/etc/udev/rules.d" + "sysconfdir=/etc" + "sbindir=/bin" + "datadir=" + "LIBDIR=/lib/drbd" + "mandir=/share/man" ]; + postPatch = '' + patchShebangs . + substituteInPlace user/v84/drbdadm_usage_cnt.c \ + --replace '"/lib/drbd");' \ + '"${placeholder "out"}/lib/drbd");' + substituteInPlace user/v9/drbdsetup_linux.c \ + --replace 'ret = system("/sbin/modprobe drbd");' \ + 'ret = system("${kmod}/bin/modprobe drbd");' + substituteInPlace user/v84/drbdsetup.c \ + --replace 'system("/sbin/modprobe drbd")' \ + 'system("${kmod}/bin/modprobe drbd")' + substituteInPlace documentation/ra2refentry.xsl \ + --replace "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" \ + "${docbook_xml_dtd_44}/xml/dtd/docbook/docbookx.dtd" + function patch_docbook45() { + substituteInPlace $1 \ + --replace "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" \ + "${docbook_xml_dtd_45}/xml/dtd/docbook/docbookx.dtd" + } + patch_docbook45 documentation/v9/drbd.conf.xml.in + patch_docbook45 documentation/v9/drbdsetup.xml.in + patch_docbook45 documentation/v84/drbdsetup.xml + patch_docbook45 documentation/v84/drbd.conf.xml + # The ja documentation is disabled because: + # make[1]: Entering directory '/build/drbd-utils-9.16.0/documentation/ja/v84' + # /nix/store/wyx2nn2pjcn50lc95c6qgsgm606rn0x2-perl5.32.1-po4a-0.62/bin/po4a-translate -f docbook -M utf-8 -L utf-8 -keep 0 -m ../../v84/drbdsetup.xml -p drbdsetup.xml.po -l drbdsetup.xml + # Use of uninitialized value $args[1] in sprintf at /nix/store/wyx2nn2pjcn50lc95c6qgsgm606rn0x2-perl5.32.1-po4a-0.62/lib/perl5/site_perl/Locale/Po4a/Common.pm line 134. + # Invalid po file drbdsetup.xml.po: + substituteInPlace Makefile.in \ + --replace 'DOC_DIRS := documentation/v9 documentation/ja/v9' \ + 'DOC_DIRS := documentation/v9' \ + --replace 'DOC_DIRS += documentation/v84 documentation/ja/v84' \ + 'DOC_DIRS += documentation/v84' \ + --replace '$(MAKE) -C documentation/ja/v9 doc' \ + "" \ + --replace '$(MAKE) -C documentation/ja/v84 doc' \ + "" + substituteInPlace user/v9/drbdtool_common.c \ + --replace 'add_component_to_path("/lib/drbd");' \ + 'add_component_to_path("${placeholder "out"}/lib/drbd");' + ''; + + preConfigure = '' + export PATH=${systemd}/sbin:$PATH + ''; + + enableParallelBuilding = true; + + passthru.tests.drbd = nixosTests.drbd; + meta = with lib; { - homepage = "http://www.drbd.org/"; - description = "Distributed Replicated Block Device, a distributed storage system for Linux"; - license = licenses.gpl2; + homepage = "https://linbit.com/drbd/"; + description = "Distributed Replicated Block Device, a distributed storage system for Linux (userspace utilities)"; + license = licenses.gpl2Plus; platforms = platforms.linux; + maintainers = with maintainers; [ ryantm astro ]; }; } diff --git a/pkgs/os-specific/linux/drbd/fix-glibc-compilation.patch b/pkgs/os-specific/linux/drbd/fix-glibc-compilation.patch deleted file mode 100644 index 621a2dd995db..000000000000 --- a/pkgs/os-specific/linux/drbd/fix-glibc-compilation.patch +++ /dev/null @@ -1,24 +0,0 @@ -diff --git a/user/drbdadm_adjust.c b/user/drbdadm_adjust.c -index cb23270..3a751ca 100644 ---- a/user/drbdadm_adjust.c -+++ b/user/drbdadm_adjust.c -@@ -29,6 +29,7 @@ - #include - #include - #include -+#include - #include - #include - -diff --git a/user/legacy/drbdadm_adjust.c b/user/legacy/drbdadm_adjust.c -index c79163c..6990ffb 100644 ---- a/user/legacy/drbdadm_adjust.c -+++ b/user/legacy/drbdadm_adjust.c -@@ -27,6 +27,7 @@ - #include - #include - #include -+#include - #include - #include - diff --git a/pkgs/os-specific/linux/drbd/pass-force.patch b/pkgs/os-specific/linux/drbd/pass-force.patch deleted file mode 100644 index 8f0201100f72..000000000000 --- a/pkgs/os-specific/linux/drbd/pass-force.patch +++ /dev/null @@ -1,15 +0,0 @@ -Propagate the --force flag in the legacy drbdadm to drbdsetup. -Otherwise "drbdadm primary --force" won't work as expected (the kernel -will say "State change failed: Need access to UpToDate data"). - -diff -ru -x '*~' drbd-8.4.0-orig/user/legacy/drbdadm_main.c drbd-8.4.0/user/legacy/drbdadm_main.c ---- drbd-8.4.0-orig/user/legacy/drbdadm_main.c 2011-07-07 06:55:39.000000000 -0400 -+++ drbd-8.4.0/user/legacy/drbdadm_main.c 2011-11-02 14:51:04.000000000 -0400 -@@ -1547,6 +1547,7 @@ - for (i = 0; i < soi; i++) { - argv[NA(argc)] = setup_opts[i]; - } -+ if (force) argv[NA(argc)] = "--force"; - argv[NA(argc)] = 0; - - setenv("DRBD_RESOURCE", res->name, 1); diff --git a/pkgs/os-specific/linux/ocf-resource-agents/default.nix b/pkgs/os-specific/linux/ocf-resource-agents/default.nix new file mode 100644 index 000000000000..9c9557c7be85 --- /dev/null +++ b/pkgs/os-specific/linux/ocf-resource-agents/default.nix @@ -0,0 +1,56 @@ +{ stdenv +, lib +, runCommand +, lndir +, fetchFromGitHub +, autoreconfHook +, pkg-config +, python3 +, glib +, drbd +}: + +let + drbdForOCF = drbd.override { + forOCF = true; + }; + + resource-agentsForOCF = stdenv.mkDerivation rec { + pname = "resource-agents"; + version = "4.10.0"; + + src = fetchFromGitHub { + owner = "ClusterLabs"; + repo = pname; + rev = "v${version}"; + sha256 = "0haryi3yrszdfpqnkfnppxj1yiy6ipah6m80snvayc7v0ss0wnir"; + }; + + nativeBuildInputs = [ + autoreconfHook + pkg-config + ]; + + buildInputs = [ + glib + python3 + ]; + + meta = with lib; { + homepage = "https://github.com/ClusterLabs/resource-agents"; + description = "Combined repository of OCF agents from the RHCS and Linux-HA projects"; + license = licenses.gpl2Plus; + platforms = platforms.linux; + maintainers = with maintainers; [ ryantm astro ]; + }; + }; + +in + +# This combines together OCF definitions from other derivations. +# https://github.com/ClusterLabs/resource-agents/blob/master/doc/dev-guides/ra-dev-guide.asc +runCommand "ocf-resource-agents" {} '' + mkdir -p $out/usr/lib/ocf + ${lndir}/bin/lndir -silent "${resource-agentsForOCF}/lib/ocf/" $out/usr/lib/ocf + ${lndir}/bin/lndir -silent "${drbdForOCF}/usr/lib/ocf/" $out/usr/lib/ocf +'' diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d4d5042e5750..87debac70dd3 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -22428,6 +22428,8 @@ with pkgs; system76-firmware = callPackage ../os-specific/linux/firmware/system76-firmware { }; + ocf-resource-agents = callPackage ../os-specific/linux/ocf-resource-agents { }; + open-vm-tools = callPackage ../applications/virtualization/open-vm-tools { }; open-vm-tools-headless = open-vm-tools.override { withX = false; }; From aa37441c3ee910ae071156cb8914f767c8403baf Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Tue, 30 Nov 2021 21:40:35 +0100 Subject: [PATCH 2/3] nixos/drbd: fix - fix environment.etc."drbd.conf" - don't generate an ExecStart script for just one command --- nixos/modules/services/network-filesystems/drbd.nix | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/network-filesystems/drbd.nix b/nixos/modules/services/network-filesystems/drbd.nix index 916e7eaaaa94..c730e0b34e90 100644 --- a/nixos/modules/services/network-filesystems/drbd.nix +++ b/nixos/modules/services/network-filesystems/drbd.nix @@ -47,19 +47,17 @@ let cfg = config.services.drbd; in options drbd usermode_helper=/run/current-system/sw/bin/drbdadm ''; - environment.etc.drbd.conf = + environment.etc."drbd.conf" = { source = pkgs.writeText "drbd.conf" cfg.config; }; systemd.services.drbd = { after = [ "systemd-udev.settle.service" "network.target" ]; wants = [ "systemd-udev.settle.service" ]; wantedBy = [ "multi-user.target" ]; - script = '' - ${pkgs.drbd}/sbin/drbdadm up all - ''; - serviceConfig.ExecStop = '' - ${pkgs.drbd}/sbin/drbdadm down all - ''; + serviceConfig = { + ExecStart = "${pkgs.drbd}/sbin/drbdadm up all"; + ExecStop = "${pkgs.drbd}/sbin/drbdadm down all"; + }; }; }; } From 7f4e071274424c3e37847fc26bd7e4343ce9522c Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Tue, 30 Nov 2021 21:42:29 +0100 Subject: [PATCH 3/3] nixos/tests/drbd: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/drbd.nix | 87 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 nixos/tests/drbd.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index e2b9c868bc85..9dda33ac925e 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -111,6 +111,7 @@ in dokuwiki = handleTest ./dokuwiki.nix {}; domination = handleTest ./domination.nix {}; dovecot = handleTest ./dovecot.nix {}; + drbd = handleTest ./drbd.nix {}; ec2-config = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-config or {}; ec2-nixops = (handleTestOn ["x86_64-linux"] ./ec2.nix {}).boot-ec2-nixops or {}; ecryptfs = handleTest ./ecryptfs.nix {}; diff --git a/nixos/tests/drbd.nix b/nixos/tests/drbd.nix new file mode 100644 index 000000000000..bede7206d706 --- /dev/null +++ b/nixos/tests/drbd.nix @@ -0,0 +1,87 @@ +import ./make-test-python.nix ( + { pkgs, lib, ... }: + let + drbdPort = 7789; + + drbdConfig = + { nodes, ... }: + { + virtualisation.emptyDiskImages = [ 1 ]; + networking.firewall.allowedTCPPorts = [ drbdPort ]; + + services.drbd = { + enable = true; + config = '' + global { + usage-count yes; + } + + common { + net { + protocol C; + ping-int 1; + } + } + + resource r0 { + volume 0 { + device /dev/drbd0; + disk /dev/vdb; + meta-disk internal; + } + + on drbd1 { + address ${nodes.drbd1.config.networking.primaryIPAddress}:${toString drbdPort}; + } + + on drbd2 { + address ${nodes.drbd2.config.networking.primaryIPAddress}:${toString drbdPort}; + } + } + ''; + }; + }; + in + { + name = "drbd"; + meta = with pkgs.lib.maintainers; { + maintainers = [ ryantm astro ]; + }; + + nodes.drbd1 = drbdConfig; + nodes.drbd2 = drbdConfig; + + testScript = { nodes }: '' + drbd1.start() + drbd2.start() + + drbd1.wait_for_unit("network.target") + drbd2.wait_for_unit("network.target") + + drbd1.succeed( + "drbdadm create-md r0", + "drbdadm up r0", + "drbdadm primary r0 --force", + ) + + drbd2.succeed("drbdadm create-md r0", "drbdadm up r0") + + drbd1.succeed( + "mkfs.ext4 /dev/drbd0", + "mkdir -p /mnt/drbd", + "mount /dev/drbd0 /mnt/drbd", + "touch /mnt/drbd/hello", + "umount /mnt/drbd", + "drbdadm secondary r0", + ) + drbd1.sleep(1) + + drbd2.succeed( + "drbdadm primary r0", + "mkdir -p /mnt/drbd", + "mount /dev/drbd0 /mnt/drbd", + "ls /mnt/drbd/hello", + ) + ''; + } +)