modules/external-storage: add strictMounts to systemd service options

This commit is contained in:
Max Headroom 2023-08-23 17:02:22 +02:00
parent 0cd0b4f89e
commit 51d6cd005c
3 changed files with 35 additions and 0 deletions

View file

@ -13,6 +13,10 @@ let
in in
{ {
imports = [
./strict-mounts.nix
];
options = { options = {
services.external-storage = { services.external-storage = {
fileSystems = lib.mkOption { fileSystems = lib.mkOption {

View file

@ -26,5 +26,9 @@ with lib;
type = types.str; type = types.str;
default = "default"; default = "default";
}; };
dependentServices = mkOption {
type = with types; listOf str;
default = [];
};
}; };
} }

View file

@ -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;
});
}));
};
}