l acl: use a simple unit per path

This commit is contained in:
lassulus 2022-01-29 19:14:21 +01:00
parent 6f92ab188e
commit 57341fa82f

View File

@ -1,19 +1,4 @@
{ config, lib, pkgs, ... }: let { config, lib, pkgs, ... }: let
generateACLs = attrs:
lib.mapAttrsToList (path: rules: pkgs.writeDash "acl-${builtins.baseNameOf path}" ''
mkdir -p "${path}"
${generateRules rules path}
'') attrs;
generateRules = rules: path:
lib.concatStrings (
lib.mapAttrsToList (_: rule: ''
setfacl -${lib.optionalString rule.recursive "R"}m ${rule.rule} ${path}
${lib.optionalString rule.default "setfacl -${lib.optionalString rule.recursive "R"}dm ${rule.rule} ${path}"}
${lib.optionalString rule.parents (lib.concatMapStringsSep "\n" (folder: "setfacl -m ${rule.rule} ${folder}") (parents path))}
'') rules
);
parents = dir: parents = dir:
if dir == "/" then if dir == "/" then
[ dir ] [ dir ]
@ -48,17 +33,23 @@ in {
default = {}; default = {};
}; };
config = lib.mkIf (config.lass.acl != {}) { config = lib.mkIf (config.lass.acl != {}) {
systemd.services.set_acl = { systemd.services = lib.mapAttrs' (path: rules: lib.nameValuePair "acl-${lib.replaceChars ["/"] ["_"] path}" {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
path = [ path = [
pkgs.acl pkgs.acl
pkgs.coreutils pkgs.coreutils
]; ];
serviceConfig = { serviceConfig = {
ExecStart = generateACLs config.lass.acl; ExecStart = pkgs.writers.writeDash "acl" (lib.concatStrings (
lib.mapAttrsToList (_: rule: ''
setfacl -${lib.optionalString rule.recursive "R"}m ${rule.rule} ${path}
${lib.optionalString rule.default "setfacl -${lib.optionalString rule.recursive "R"}dm ${rule.rule} ${path}"}
${lib.optionalString rule.parents (lib.concatMapStringsSep "\n" (folder: "setfacl -m ${rule.rule} ${folder}") (parents path))}
'') rules
));
RemainAfterExit = true; RemainAfterExit = true;
Type = "oneshot"; Type = "simple";
};
}; };
}) config.lass.acl;
}; };
} }