2012-07-16 23:47:41 +00:00
|
|
|
{pkgs, config, ...}:
|
2013-05-13 13:13:06 +00:00
|
|
|
|
2012-07-16 23:47:41 +00:00
|
|
|
let
|
|
|
|
cfg = config.security.apparmor;
|
|
|
|
in
|
2013-05-13 13:13:06 +00:00
|
|
|
|
2012-07-16 23:47:41 +00:00
|
|
|
with pkgs.lib;
|
2013-05-13 13:13:06 +00:00
|
|
|
|
2012-07-16 23:47:41 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
security.apparmor = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2013-05-13 13:13:06 +00:00
|
|
|
Enable AppArmor application security system. Enable only if
|
|
|
|
you want to further improve AppArmor.
|
2012-07-16 23:47:41 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
profiles = mkOption {
|
|
|
|
default = [];
|
2013-05-13 13:13:06 +00:00
|
|
|
merge = mergeListOption;
|
2012-07-16 23:47:41 +00:00
|
|
|
description = ''
|
2013-05-13 13:13:06 +00:00
|
|
|
List of file names of AppArmor profiles.
|
|
|
|
'';
|
2012-07-16 23:47:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf (cfg.enable) {
|
|
|
|
|
2013-05-10 13:07:56 +00: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 05:40:45 +00:00
|
|
|
environment.systemPackages = [ pkgs.apparmor ];
|
|
|
|
|
|
|
|
systemd.services.apparmor = {
|
|
|
|
#wantedBy = [ "basic.target" ];
|
|
|
|
wantedBy = [ "local-fs.target" ];
|
|
|
|
path = [ pkgs.apparmor ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
2013-05-13 13:13:06 +00:00
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = "yes";
|
2013-05-28 16:15:16 +00:00
|
|
|
ExecStart = concatMapStrings (profile:
|
|
|
|
''${pkgs.apparmor}/sbin/apparmor_parser -rKv -I ${pkgs.apparmor}/etc/apparmor.d/ "${profile}" ; ''
|
|
|
|
) cfg.profiles;
|
|
|
|
ExecStop = concatMapStrings (profile:
|
2013-05-28 17:49:52 +00:00
|
|
|
''${pkgs.apparmor}/sbin/apparmor_parser -Rv -I ${pkgs.apparmor}/etc/apparmor.d/ "${profile}" ; ''
|
2013-05-28 16:15:16 +00:00
|
|
|
) cfg.profiles;
|
2012-07-16 23:47:41 +00:00
|
|
|
};
|
|
|
|
|
2013-05-11 05:40:45 +00:00
|
|
|
};
|
|
|
|
|
2012-07-16 23:47:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|