diff --git a/modules/external-storage/default.nix b/modules/external-storage/default.nix index baa2cdf..ec23ff3 100644 --- a/modules/external-storage/default.nix +++ b/modules/external-storage/default.nix @@ -13,6 +13,10 @@ let in { + imports = [ + ./strict-mounts.nix + ]; + options = { services.external-storage = { fileSystems = lib.mkOption { diff --git a/modules/external-storage/filesystem-type.nix b/modules/external-storage/filesystem-type.nix index e35a68f..af401e5 100644 --- a/modules/external-storage/filesystem-type.nix +++ b/modules/external-storage/filesystem-type.nix @@ -26,5 +26,9 @@ with lib; type = types.str; default = "default"; }; + dependentServices = mkOption { + type = with types; listOf str; + default = []; + }; }; } diff --git a/modules/external-storage/strict-mounts.nix b/modules/external-storage/strict-mounts.nix new file mode 100644 index 0000000..b304ac0 --- /dev/null +++ b/modules/external-storage/strict-mounts.nix @@ -0,0 +1,27 @@ +{ config, lib, ... }: + +let + cfg = config.services.external-storage; +in + +with lib; +{ + options.systemd.services = mkOption { + type = with types; attrsOf (submodule ({ config, ... }: { + options.strictMounts = mkOption { + type = with types; listOf path; + default = []; + }; + config = mkIf (config.strictMounts != []) (let + findFilesystemsFor = mount: pipe cfg.fileSystems [ + (filterAttrs (_: fs: hasPrefix "${fs.mountpoint}/" "${mount}/")) + (mapAttrsToList (_: fs: "${fs.unitName}.service")) + ]; + services = flatten (map findFilesystemsFor config.strictMounts); + in { + after = services; + bindsTo = services; + }); + })); + }; +}