2012-07-17 00:47:41 +01:00
|
|
|
{pkgs, config, ...}:
|
|
|
|
let
|
|
|
|
cfg = config.security.apparmor;
|
|
|
|
in
|
|
|
|
with pkgs.lib;
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
security.apparmor = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2013-05-10 12:57:48 +01:00
|
|
|
Enable AppArmor application security system. Enable only if you want to further improve
|
|
|
|
AppArmor.
|
2012-07-17 00:47:41 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
profiles = mkOption {
|
|
|
|
default = [];
|
|
|
|
merge = mergeListOption;
|
|
|
|
description = ''
|
|
|
|
List of file names of AppArmor profiles.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf (cfg.enable) {
|
|
|
|
|
2013-05-10 14:07:56 +01:00
|
|
|
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"; }
|
|
|
|
];
|
|
|
|
|
2013-05-11 06:40:45 +01:00
|
|
|
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 "${profile}"
|
2012-07-17 00:47:41 +01:00
|
|
|
'') cfg.profiles;
|
|
|
|
};
|
|
|
|
|
2013-05-11 06:40:45 +01:00
|
|
|
};
|
|
|
|
|
2012-07-17 00:47:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|