From ca780f4a186ab27425bd57737fe7b9638c2b27a8 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Thu, 25 Jul 2019 16:36:16 +0300 Subject: [PATCH] swraid service: use upstream units This fixes a serious bug on NixOS with swraid where mdadm arrays weren't properly stopped on shutdown. Rather than fixing the unit by adding `Before=final.target` we completely move to upstream units, which uses systemd shutdown hooks instead. This also drives down maintenance costs for us. --- nixos/modules/tasks/swraid.nix | 44 +++------------------------------- 1 file changed, 3 insertions(+), 41 deletions(-) diff --git a/nixos/modules/tasks/swraid.nix b/nixos/modules/tasks/swraid.nix index 93e03c44c868..7f07684651ca 100644 --- a/nixos/modules/tasks/swraid.nix +++ b/nixos/modules/tasks/swraid.nix @@ -6,51 +6,13 @@ services.udev.packages = [ pkgs.mdadm ]; + systemd.packages = [ pkgs.mdadm ]; + systemd.shutdownPackages = [ pkgs.mdadm ]; + boot.initrd.availableKernelModules = [ "md_mod" "raid0" "raid1" "raid10" "raid456" ]; boot.initrd.extraUdevRulesCommands = '' cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/ ''; - systemd.services.mdadm-shutdown = { - wantedBy = [ "final.target"]; - after = [ "umount.target" ]; - - unitConfig = { - DefaultDependencies = false; - }; - - serviceConfig = { - Type = "oneshot"; - ExecStart = ''${pkgs.mdadm}/bin/mdadm --wait-clean --scan''; - }; - }; - - systemd.services."mdmon@" = { - description = "MD Metadata Monitor on /dev/%I"; - - unitConfig.DefaultDependencies = false; - - serviceConfig = { - Type = "forking"; - Environment = "IMSM_NO_PLATFORM=1"; - ExecStart = ''${pkgs.mdadm}/bin/mdmon --offroot --takeover %I''; - KillMode = "none"; - }; - }; - - systemd.services."mdadm-grow-continue@" = { - description = "Manage MD Reshape on /dev/%I"; - - unitConfig.DefaultDependencies = false; - - serviceConfig = { - ExecStart = ''${pkgs.mdadm}/bin/mdadm --grow --continue /dev/%I''; - StandardInput = "null"; - StandardOutput = "null"; - StandardError = "null"; - KillMode = "none"; - }; - }; - }