grimm-nixos-laptop/common/tooling/apparmor/aa-alias-module.nix

38 lines
959 B
Nix
Raw Normal View History

2024-10-25 18:13:30 +02:00
{
config,
lib,
pkgs,
...
}:
let
2024-10-27 13:57:57 +01:00
inherit (lib) getExe mkIf;
2024-10-25 18:13:30 +02:00
aa-alias-manager = pkgs.callPackage ./aa-alias-manager-package.nix { };
2024-10-25 13:47:17 +02:00
alias_dir = "/run/aliases.d";
2024-10-25 18:13:30 +02:00
in
{
2024-10-27 13:57:57 +01:00
config = mkIf config.security.apparmor.enable {
2024-10-25 13:47:17 +02:00
security.apparmor.includes."tunables/alias.d/store" = ''
include if exists "${alias_dir}"
'';
systemd.services.aa-alias-setup = {
2024-10-27 13:57:57 +01:00
after = [ "local-fs.target" ];
2024-10-25 18:13:30 +02:00
before = [ "apparmor.service" ];
requiredBy = [ "apparmor.service" ];
2024-10-27 13:57:57 +01:00
2024-10-25 13:47:17 +02:00
path = [ config.nix.package ]; # respect the users choice to use alternative nix implementations
2024-10-25 18:13:30 +02:00
2024-10-27 13:57:57 +01:00
unitConfig = {
Description = "Initialize alias rules required for AppArmor policies";
DefaultDependencies = "no";
ConditionSecurity = "apparmor";
};
2024-10-25 13:47:17 +02:00
serviceConfig = {
Type = "oneshot";
ExecStart = "${getExe aa-alias-manager} -o ${alias_dir} -p ${./aa-alias-patterns.json}";
};
};
};
}