29027fd1e1
Using pkgs.lib on the spine of module evaluation is problematic because the pkgs argument depends on the result of module evaluation. To prevent an infinite recursion, pkgs and some of the modules are evaluated twice, which is inefficient. Using ‘with lib’ prevents this problem.
70 lines
1.6 KiB
Nix
70 lines
1.6 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
cfg = config.security.apparmor;
|
|
in
|
|
|
|
with lib;
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
security.apparmor = {
|
|
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
description = ''
|
|
Enable AppArmor application security system. Enable only if
|
|
you want to further improve AppArmor.
|
|
'';
|
|
};
|
|
|
|
profiles = mkOption {
|
|
type = types.listOf types.path;
|
|
default = [];
|
|
description = ''
|
|
List of file names of AppArmor profiles.
|
|
'';
|
|
};
|
|
|
|
};
|
|
};
|
|
|
|
|
|
###### implementation
|
|
|
|
config = mkIf (cfg.enable) {
|
|
|
|
assertions = [ { assertion = config.boot.kernelPackages.kernel.features ? apparmor
|
|
&& config.boot.kernelPackages.kernel.features.apparmor;
|
|
message = "AppArmor is enabled, but the kernel doesn't have AppArmor support"; }
|
|
];
|
|
|
|
environment.systemPackages = [ pkgs.apparmor ];
|
|
|
|
systemd.services.apparmor = {
|
|
#wantedBy = [ "basic.target" ];
|
|
wantedBy = [ "local-fs.target" ];
|
|
path = [ pkgs.apparmor ];
|
|
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
RemainAfterExit = "yes";
|
|
ExecStart = concatMapStrings (profile:
|
|
''${pkgs.apparmor}/sbin/apparmor_parser -rKv -I ${pkgs.apparmor}/etc/apparmor.d/ "${profile}" ; ''
|
|
) cfg.profiles;
|
|
ExecStop = concatMapStrings (profile:
|
|
''${pkgs.apparmor}/sbin/apparmor_parser -Rv -I ${pkgs.apparmor}/etc/apparmor.d/ "${profile}" ; ''
|
|
) cfg.profiles;
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|