2024-10-15 21:35:53 +02:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (lib) mkIf mergeAttrsList last path;
|
|
|
|
|
|
|
|
cfg = config.security.apparmor_d;
|
|
|
|
apparmor-d = pkgs.callPackage ./apparmor-d-package.nix {};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.security.apparmor_d = with lib; let
|
|
|
|
profile = types.submodule ({ config, ... }: {
|
|
|
|
options = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "whether to enable this profile";
|
|
|
|
};
|
|
|
|
|
|
|
|
enforce = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = "whether to enforce this profile";
|
|
|
|
};
|
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.nonEmptyStr;
|
2024-10-15 23:31:58 +02:00
|
|
|
description = "name of the apparmor profile within apparmor.d";
|
2024-10-15 21:35:53 +02:00
|
|
|
example = "vesktop";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
in {
|
|
|
|
enable = mkEnableOption "enable apparmor.d support";
|
|
|
|
|
|
|
|
profiles = mkOption {
|
|
|
|
type = types.listOf (types.either types.nonEmptyStr profile);
|
|
|
|
default = [];
|
|
|
|
description = "set of apparmor profiles to include from apparmor.d";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
options.test = lib.mkOption { default = null; };
|
|
|
|
|
|
|
|
config = mkIf (cfg.enable) {
|
|
|
|
security.apparmor.packages = [ apparmor-d ];
|
2024-10-15 23:31:58 +02:00
|
|
|
security.apparmor.policies = mergeAttrsList (map (p: if (builtins.isString p) then {
|
|
|
|
"${p}" = {
|
2024-10-15 21:35:53 +02:00
|
|
|
enable = true;
|
|
|
|
enforce = true;
|
|
|
|
profile = ''
|
2024-10-15 23:31:58 +02:00
|
|
|
include "${apparmor-d}/etc/apparmor.d/${p}"
|
2024-10-15 21:35:53 +02:00
|
|
|
'';
|
|
|
|
};
|
2024-10-15 23:31:58 +02:00
|
|
|
} else {
|
2024-10-15 21:35:53 +02:00
|
|
|
${p.name} = {
|
|
|
|
inherit (p) enable enforce;
|
|
|
|
profile = ''
|
2024-10-15 23:31:58 +02:00
|
|
|
include "${apparmor-d}/etc/apparmor.d/${p.name}"
|
2024-10-15 21:35:53 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}) cfg.profiles );
|
2024-10-15 23:31:58 +02:00
|
|
|
|
|
|
|
environment.systemPackages = [ apparmor-d ];
|
2024-10-15 21:35:53 +02:00
|
|
|
};
|
|
|
|
}
|