transmission: move apparmor profile to Nixpkgs

Changed files
+56 -46
nixos
modules
services
pkgs
applications
networking
p2p
transmission
+29 -46
nixos/modules/services/torrent/transmission.nix
···
];
security.apparmor.policies."bin.transmission-daemon".profile = ''
-
include <tunables/global>
-
${pkgs.transmission}/bin/transmission-daemon {
-
include <abstractions/base>
-
include <abstractions/nameservice>
-
include <abstractions/ssl_certs>
-
include "${pkgs.apparmorRulesFromClosure
-
{ name = "transmission-daemon"; }
-
[ pkgs.transmission ]}"
-
include <local/bin.transmission-daemon>
+
include "${pkgs.transmission.apparmor}/bin.transmission-daemon"
+
'';
+
security.apparmor.includes."local/bin.transmission-daemon" = ''
+
r ${config.systemd.services.transmission.environment.CURL_CA_BUNDLE},
-
r @{PROC}/sys/kernel/random/uuid,
-
r @{PROC}/sys/vm/overcommit_memory,
-
r @{PROC}/@{pid}/environ,
-
r @{PROC}/@{pid}/mounts,
-
rwk /tmp/tr_session_id_*,
-
r /run/systemd/resolve/stub-resolv.conf,
+
owner rw ${cfg.home}/${settingsDir}/**,
+
rw ${cfg.settings.download-dir}/**,
+
${optionalString cfg.settings.incomplete-dir-enabled ''
+
rw ${cfg.settings.incomplete-dir}/**,
+
''}
+
${optionalString cfg.settings.watch-dir-enabled ''
+
rw ${cfg.settings.watch-dir}/**,
+
''}
+
profile dirs {
+
rw ${cfg.settings.download-dir}/**,
+
${optionalString cfg.settings.incomplete-dir-enabled ''
+
rw ${cfg.settings.incomplete-dir}/**,
+
''}
+
${optionalString cfg.settings.watch-dir-enabled ''
+
rw ${cfg.settings.watch-dir}/**,
+
''}
+
}
-
r ${pkgs.openssl.out}/etc/**,
-
r ${config.systemd.services.transmission.environment.CURL_CA_BUNDLE},
-
-
owner rw ${cfg.home}/${settingsDir}/**,
-
rw ${cfg.settings.download-dir}/**,
-
${optionalString cfg.settings.incomplete-dir-enabled ''
-
rw ${cfg.settings.incomplete-dir}/**,
-
''}
-
${optionalString cfg.settings.watch-dir-enabled ''
-
rw ${cfg.settings.watch-dir}/**,
-
''}
-
profile dirs {
-
rw ${cfg.settings.download-dir}/**,
-
${optionalString cfg.settings.incomplete-dir-enabled ''
-
rw ${cfg.settings.incomplete-dir}/**,
-
''}
-
${optionalString cfg.settings.watch-dir-enabled ''
-
rw ${cfg.settings.watch-dir}/**,
-
''}
-
}
-
-
${optionalString (cfg.settings.script-torrent-done-enabled &&
-
cfg.settings.script-torrent-done-filename != "") ''
-
# Stack transmission_directories profile on top of
-
# any existing profile for script-torrent-done-filename
-
# FIXME: to be tested as I'm not sure it works well with NoNewPrivileges=
-
# https://gitlab.com/apparmor/apparmor/-/wikis/AppArmorStacking#seccomp-and-no_new_privs
-
px ${cfg.settings.script-torrent-done-filename} -> &@{dirs},
-
''}
-
}
+
${optionalString (cfg.settings.script-torrent-done-enabled &&
+
cfg.settings.script-torrent-done-filename != "") ''
+
# Stack transmission_directories profile on top of
+
# any existing profile for script-torrent-done-filename
+
# FIXME: to be tested as I'm not sure it works well with NoNewPrivileges=
+
# https://gitlab.com/apparmor/apparmor/-/wikis/AppArmorStacking#seccomp-and-no_new_privs
+
px ${cfg.settings.script-torrent-done-filename} -> &@{dirs},
+
''}
'';
-
security.apparmor.includes."local/bin.transmission-daemon" = "";
};
meta.maintainers = with lib.maintainers; [ julm ];
+27
pkgs/applications/networking/p2p/transmission/default.nix
···
, enableDaemon ? true
, enableCli ? true
, installLib ? false
+
, apparmorRulesFromClosure
}:
let
···
sha256 = "0ccg0km54f700x9p0jsnncnwvfnxfnxf7kcm7pcx1cj0vw78924z";
fetchSubmodules = true;
};
+
+
outputs = [ "out" "apparmor" ];
cmakeFlags =
let
···
;
NIX_LDFLAGS = lib.optionalString stdenv.isDarwin "-framework CoreFoundation";
+
+
postInstall = ''
+
install -D -m 644 /dev/stdin $apparmor/bin.transmission-daemon <<EOF
+
include <tunables/global>
+
$out/bin/transmission-daemon {
+
include <abstractions/base>
+
include <abstractions/nameservice>
+
include <abstractions/ssl_certs>
+
include "${apparmorRulesFromClosure { name = "transmission-daemon"; } ([
+
curl libevent openssl pcre zlib
+
] ++ lib.optionals enableSystemd [ systemd ]
+
++ lib.optionals stdenv.isLinux [ inotify-tools ]
+
)}"
+
r @{PROC}/sys/kernel/random/uuid,
+
r @{PROC}/sys/vm/overcommit_memory,
+
r @{PROC}/@{pid}/environ,
+
r @{PROC}/@{pid}/mounts,
+
rwk /tmp/tr_session_id_*,
+
r /run/systemd/resolve/stub-resolv.conf,
+
+
include <local/bin.transmission-daemon>
+
}
+
EOF
+
'';
meta = {
description = "A fast, easy and free BitTorrent client";