modules/external-storage: add strictMounts to systemd service options
This commit is contained in:
parent
0cd0b4f89e
commit
51d6cd005c
3 changed files with 35 additions and 0 deletions
|
@ -13,6 +13,10 @@ let
|
|||
in
|
||||
|
||||
{
|
||||
imports = [
|
||||
./strict-mounts.nix
|
||||
];
|
||||
|
||||
options = {
|
||||
services.external-storage = {
|
||||
fileSystems = lib.mkOption {
|
||||
|
|
|
@ -26,5 +26,9 @@ with lib;
|
|||
type = types.str;
|
||||
default = "default";
|
||||
};
|
||||
dependentServices = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
27
modules/external-storage/strict-mounts.nix
Normal file
27
modules/external-storage/strict-mounts.nix
Normal 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;
|
||||
});
|
||||
}));
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue