···
inherit (builtins) attrNames hasAttr isAttrs;
inherit (config.environment) etc;
6
+
# Utility to generate an AppArmor rule
7
+
# only when the given path exists in config.environment.etc
7
-
let go = {path ? null, mode ? "r", trail ? ""}:
9
+
let go = { path ? null, mode ? "r", trail ? "" }:
lib.optionalString (hasAttr path etc)
"${mode} ${config.environment.etc.${path}.source}${trail},";
12
-
else go {path=arg;};
14
+
else go { path = arg; };
# FIXME: most of the etcRule calls below have been
···
"abstractions/audio" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/audio"
32
-
${etcRule "asound.conf"}
33
-
${etcRule "esound/esd.conf"}
34
-
${etcRule "libao.conf"}
35
-
${etcRule {path="pulse"; trail="/";}}
36
-
${etcRule {path="pulse"; trail="/**";}}
37
-
${etcRule {path="sound"; trail="/";}}
38
-
${etcRule {path="sound"; trail="/**";}}
39
-
${etcRule {path="alsa/conf.d"; trail="/";}}
40
-
${etcRule {path="alsa/conf.d"; trail="/*";}}
41
-
${etcRule "openal/alsoft.conf"}
42
-
${etcRule "wildmidi/wildmidi.conf"}
34
+
'' + lib.concatMapStringsSep "\n" etcRule [
38
+
{ path = "pulse"; trail = "/"; }
39
+
{ path = "pulse"; trail = "/**"; }
40
+
{ path = "sound"; trail = "/"; }
41
+
{ path = "sound"; trail = "/**"; }
42
+
{ path = "alsa/conf.d"; trail = "/"; }
43
+
{ path = "alsa/conf.d"; trail = "/*"; }
44
+
"openal/alsoft.conf"
45
+
"wildmidi/wildmidi.conf"
"abstractions/authentication" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/authentication"
# Defined in security.pam
include <abstractions/pam>
48
-
${etcRule "nologin"}
49
-
${etcRule "securetty"}
50
-
${etcRule {path="security"; trail="/*";}}
52
-
${etcRule "gshadow"}
53
-
${etcRule "pwdb.conf"}
54
-
${etcRule "default/passwd"}
55
-
${etcRule "login.defs"}
51
+
'' + lib.concatMapStringsSep "\n" etcRule [
54
+
{ path = "security"; trail = "/*"; }
58
-
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/base"
59
-
r ${pkgs.stdenv.cc.libc}/share/locale/**,
60
-
r ${pkgs.stdenv.cc.libc}/share/locale.alias,
61
-
${lib.optionalString (pkgs.glibcLocales != null) "r ${pkgs.glibcLocales}/lib/locale/locale-archive,"}
62
-
${etcRule "localtime"}
63
-
r ${pkgs.tzdata}/share/zoneinfo/**,
64
-
r ${pkgs.stdenv.cc.libc}/share/i18n/**,
62
+
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/base"
63
+
r ${pkgs.stdenv.cc.libc}/share/locale/**,
64
+
r ${pkgs.stdenv.cc.libc}/share/locale.alias,
65
+
${lib.optionalString (pkgs.glibcLocales != null) "r ${pkgs.glibcLocales}/lib/locale/locale-archive,"}
66
+
${etcRule "localtime"}
67
+
r ${pkgs.tzdata}/share/zoneinfo/**,
68
+
r ${pkgs.stdenv.cc.libc}/share/i18n/**,
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/bash"
68
-
# system-wide bash configuration
69
-
${etcRule "profile.dos"}
70
-
${etcRule "profile"}
71
-
${etcRule "profile.d"}
72
-
${etcRule {path="profile.d"; trail="/*";}}
74
-
${etcRule "bash.bashrc"}
75
-
${etcRule "bash.bashrc.local"}
76
-
${etcRule "bash_completion"}
77
-
${etcRule "bash_completion.d"}
78
-
${etcRule {path="bash_completion.d"; trail="/*";}}
79
-
# bash relies on system-wide readline configuration
80
-
${etcRule "inputrc"}
# bash inspects filesystems at startup
# and /etc/mtab is linked to /proc/mounts
85
-
# run out of /etc/bash.bashrc
86
-
${etcRule "DIR_COLORS"}
77
+
# system-wide bash configuration
78
+
'' + lib.concatMapStringsSep "\n" etcRule [
82
+
{ path = "profile.d"; trail = "/*"; }
88
+
{ path = "bash_completion.d"; trail = "/*"; }
89
+
# bash relies on system-wide readline configuration
91
+
# run out of /etc/bash.bashrc
94
+
"abstractions/consoles" = ''
95
+
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/consoles"
"abstractions/cups-client" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/cpus-client"
${etcRule "cups/cups-client.conf"}
92
-
"abstractions/consoles" = ''
93
-
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/consoles"
"abstractions/dbus-session-strict" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/dbus-session-strict"
"abstractions/dconf" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/dconf"
101
-
${etcRule {path="dconf"; trail="/**";}}
107
+
${etcRule { path = "dconf"; trail = "/**"; }}
"abstractions/dri-common" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/dri-common"
···
# those are therefore added there to this "abstractions/fonts".
"abstractions/fonts" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/fonts"
112
-
${etcRule {path="fonts"; trail="/**";}}
118
+
${etcRule { path = "fonts"; trail = "/**"; }}
"abstractions/gnome" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/gnome"
116
-
${etcRule {path="gnome"; trail="/gtkrc*";}}
117
-
${etcRule {path="gtk"; trail="/*";}}
118
-
${etcRule {path="gtk-2.0"; trail="/*";}}
119
-
${etcRule {path="gtk-3.0"; trail="/*";}}
120
-
${etcRule "orbitrc"}
include <abstractions/fonts>
122
-
${etcRule {path="pango"; trail="/*";}}
123
-
${etcRule {path="/etc/gnome-vfs-2.0"; trail="/modules/";}}
124
-
${etcRule {path="/etc/gnome-vfs-2.0"; trail="/modules/*";}}
125
-
${etcRule "papersize"}
126
-
${etcRule {path="cups"; trail="/lpoptions";}}
127
-
${etcRule {path="gnome"; trail="/defaults.list";}}
128
-
${etcRule {path="xdg"; trail="/{,*-}mimeapps.list";}}
129
-
${etcRule "xdg/mimeapps.list"}
123
+
'' + lib.concatMapStringsSep "\n" etcRule [
124
+
{ path = "gnome"; trail = "/gtkrc*"; }
125
+
{ path = "gtk"; trail = "/*"; }
126
+
{ path = "gtk-2.0"; trail = "/*"; }
127
+
{ path = "gtk-3.0"; trail = "/*"; }
129
+
{ path = "pango"; trail = "/*"; }
130
+
{ path = "/etc/gnome-vfs-2.0"; trail = "/modules/"; }
131
+
{ path = "/etc/gnome-vfs-2.0"; trail = "/modules/*"; }
133
+
{ path = "cups"; trail = "/lpoptions"; }
134
+
{ path = "gnome"; trail = "/defaults.list"; }
135
+
{ path = "xdg"; trail = "/{,*-}mimeapps.list"; }
136
+
"xdg/mimeapps.list"
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/kde"
133
-
${etcRule {path="qt3"; trail="/kstylerc";}}
134
-
${etcRule {path="qt3"; trail="/qt_plugins_3.3rc";}}
135
-
${etcRule {path="qt3"; trail="/qtrc";}}
137
-
${etcRule {path="kde3"; trail="/*";}}
138
-
${etcRule "kde4rc"}
139
-
${etcRule {path="xdg"; trail="/kdeglobals";}}
140
-
${etcRule {path="xdg"; trail="/Trolltech.conf";}}
140
+
'' + lib.concatMapStringsSep "\n" etcRule [
141
+
{ path = "qt3"; trail = "/kstylerc"; }
142
+
{ path = "qt3"; trail = "/qt_plugins_3.3rc"; }
143
+
{ path = "qt3"; trail = "/qtrc"; }
145
+
{ path = "kde3"; trail = "/*"; }
147
+
{ path = "xdg"; trail = "/kdeglobals"; }
148
+
{ path = "xdg"; trail = "/Trolltech.conf"; }
"abstractions/kerberosclient" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/kerberosclient"
144
-
${etcRule {path="krb5.keytab"; mode="rk";}}
145
-
${etcRule "krb5.conf"}
146
-
${etcRule "krb5.conf.d"}
147
-
${etcRule {path="krb5.conf.d"; trail="/*";}}
152
+
'' + lib.concatMapStringsSep "\n" etcRule [
153
+
{ path = "krb5.keytab"; mode="rk"; }
156
+
{ path = "krb5.conf.d"; trail = "/*"; }
# config files found via strings on libs
150
-
${etcRule "krb.conf"}
151
-
${etcRule "krb.realms"}
152
-
${etcRule "srvtab"}
"abstractions/ldapclient" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/ldapclient"
156
-
${etcRule "ldap.conf"}
157
-
${etcRule "ldap.secret"}
158
-
${etcRule {path="openldap"; trail="/*";}}
159
-
${etcRule {path="openldap"; trail="/cacerts/*";}}
160
-
${etcRule {path="sasl2"; trail="/*";}}
165
+
'' + lib.concatMapStringsSep "\n" etcRule [
168
+
{ path = "openldap"; trail = "/*"; }
169
+
{ path = "openldap"; trail = "/cacerts/*"; }
170
+
{ path = "sasl2"; trail = "/*"; }
"abstractions/likewise" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/likewise"
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/mdns"
167
-
${etcRule "nss_mdns.conf"}
177
+
${etcRule "nss_mdns.conf"}
"abstractions/nameservice" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/nameservice"
···
# looking up users by name or id, groups by name or id, hosts by name
# or IP, etc. These operations may be performed through files, dns,
# NIS, NIS+, LDAP, hesiod, wins, etc. Allow them all here.
177
-
${etcRule "host.conf"}
179
-
${etcRule "nsswitch.conf"}
180
-
${etcRule "gai.conf"}
181
-
${etcRule "passwd"}
182
-
${etcRule "protocols"}
186
+
mr ${getLib pkgs.nss}/lib/libnss_*.so*,
187
+
mr ${getLib pkgs.nss}/lib64/libnss_*.so*,
188
+
'' + lib.concatMapStringsSep "\n" etcRule [
184
-
# libtirpc (used for NIS/YP login) needs this
185
-
${etcRule "netconfig"}
187
-
${etcRule "resolv.conf"}
197
+
# libtirpc (used for NIS/YP login) needs this
189
-
${etcRule {path="samba"; trail="/lmhosts";}}
190
-
${etcRule "services"}
192
-
${etcRule "default/nss"}
202
+
{ path = "samba"; trail = "/lmhosts"; }
194
-
# libnl-3-200 via libnss-gw-name
195
-
${etcRule {path="libnl"; trail="/classid";}}
196
-
${etcRule {path="libnl-3"; trail="/classid";}}
198
-
mr ${getLib pkgs.nss}/lib/libnss_*.so*,
199
-
mr ${getLib pkgs.nss}/lib64/libnss_*.so*,
207
+
# libnl-3-200 via libnss-gw-name
208
+
{ path = "libnl"; trail = "/classid"; }
209
+
{ path = "libnl-3"; trail = "/classid"; }
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/nis"
···
"abstractions/opencl-common" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/opencl-common"
210
-
${etcRule {path="OpenCL"; trail="/**";}}
220
+
${etcRule { path = "OpenCL"; trail = "/**"; }}
"abstractions/opencl-mesa" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/opencl-mesa"
···
"abstractions/openssl" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/openssl"
218
-
${etcRule {path="ssl"; trail="/openssl.cnf";}}
228
+
${etcRule { path = "ssl"; trail = "/openssl.cnf"; }}
"abstractions/p11-kit" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/p11-kit"
222
-
${etcRule {path="pkcs11"; trail="/";}}
223
-
${etcRule {path="pkcs11"; trail="/pkcs11.conf";}}
224
-
${etcRule {path="pkcs11"; trail="/modules/";}}
225
-
${etcRule {path="pkcs11"; trail="/modules/*";}}
232
+
'' + lib.concatMapStringsSep "\n" etcRule [
233
+
{ path = "pkcs11"; trail = "/"; }
234
+
{ path = "pkcs11"; trail = "/pkcs11.conf"; }
235
+
{ path = "pkcs11"; trail = "/modules/"; }
236
+
{ path = "pkcs11"; trail = "/modules/*"; }
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/perl"
229
-
${etcRule {path="perl"; trail="/**";}}
240
+
${etcRule { path = "perl"; trail = "/**"; }}
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/php"
233
-
${etcRule {path="php"; trail="/**/";}}
234
-
${etcRule {path="php5"; trail="/**/";}}
235
-
${etcRule {path="php7"; trail="/**/";}}
236
-
${etcRule {path="php"; trail="/**.ini";}}
237
-
${etcRule {path="php5"; trail="/**.ini";}}
238
-
${etcRule {path="php7"; trail="/**.ini";}}
244
+
'' + lib.concatMapStringsSep "\n" etcRule [
245
+
{ path = "php"; trail = "/**/"; }
246
+
{ path = "php5"; trail = "/**/"; }
247
+
{ path = "php7"; trail = "/**/"; }
248
+
{ path = "php"; trail = "/**.ini"; }
249
+
{ path = "php5"; trail = "/**.ini"; }
250
+
{ path = "php7"; trail = "/**.ini"; }
"abstractions/postfix-common" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/postfix-common"
242
-
${etcRule "mailname"}
243
-
${etcRule {path="postfix"; trail="/*.cf";}}
244
-
${etcRule "postfix/main.cf"}
245
-
${etcRule "postfix/master.cf"}
254
+
'' + lib.concatMapStringsSep "\n" etcRule [
256
+
{ path = "postfix"; trail = "/*.cf"; }
258
+
"postfix/master.cf"
"abstractions/python" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/python"
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/qt5"
252
-
${etcRule {path="xdg"; trail="/QtProject/qtlogging.ini";}}
253
-
${etcRule {path="xdg/QtProject"; trail="/qtlogging.ini";}}
254
-
${etcRule "xdg/QtProject/qtlogging.ini"}
265
+
'' + lib.concatMapStringsSep "\n" etcRule [
266
+
{ path = "xdg"; trail = "/QtProject/qtlogging.ini"; }
267
+
{ path = "xdg/QtProject"; trail = "/qtlogging.ini"; }
268
+
"xdg/QtProject/qtlogging.ini"
"abstractions/samba" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/samba"
258
-
${etcRule {path="samba"; trail="/*";}}
272
+
${etcRule { path = "samba"; trail = "/*"; }}
"abstractions/ssl_certs" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/ssl_certs"
262
-
${etcRule "ssl/certs/ca-certificates.crt"}
263
-
${etcRule "ssl/certs/ca-bundle.crt"}
264
-
${etcRule "pki/tls/certs/ca-bundle.crt"}
266
-
${etcRule {path="ssl/trust"; trail="/";}}
267
-
${etcRule {path="ssl/trust"; trail="/*";}}
268
-
${etcRule {path="ssl/trust/anchors"; trail="/";}}
269
-
${etcRule {path="ssl/trust/anchors"; trail="/**";}}
270
-
${etcRule {path="pki/trust"; trail="/";}}
271
-
${etcRule {path="pki/trust"; trail="/*";}}
272
-
${etcRule {path="pki/trust/anchors"; trail="/";}}
273
-
${etcRule {path="pki/trust/anchors"; trail="/**";}}
275
-
# security.acme NixOS module
277
+
# For the NixOS module: security.acme
r /var/lib/acme/*/cert.pem,
r /var/lib/acme/*/chain.pem,
r /var/lib/acme/*/fullchain.pem,
282
+
'' + lib.concatMapStringsSep "\n" etcRule [
283
+
"ssl/certs/ca-certificates.crt"
284
+
"ssl/certs/ca-bundle.crt"
285
+
"pki/tls/certs/ca-bundle.crt"
287
+
{ path = "ssl/trust"; trail = "/"; }
288
+
{ path = "ssl/trust"; trail = "/*"; }
289
+
{ path = "ssl/trust/anchors"; trail = "/"; }
290
+
{ path = "ssl/trust/anchors"; trail = "/**"; }
291
+
{ path = "pki/trust"; trail = "/"; }
292
+
{ path = "pki/trust"; trail = "/*"; }
293
+
{ path = "pki/trust/anchors"; trail = "/"; }
294
+
{ path = "pki/trust/anchors"; trail = "/**"; }
"abstractions/ssl_keys" = ''
# security.acme NixOS module
r /var/lib/acme/*/full.pem,
···
"abstractions/vulkan" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/vulkan"
287
-
${etcRule {path="vulkan/icd.d"; trail="/";}}
288
-
${etcRule {path="vulkan/icd.d"; trail="/*.json";}}
303
+
${etcRule { path = "vulkan/icd.d"; trail = "/"; }}
304
+
${etcRule { path = "vulkan/icd.d"; trail = "/*.json"; }}
"abstractions/winbind" = ''
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/winbind"
292
-
${etcRule {path="samba"; trail="/smb.conf";}}
293
-
${etcRule {path="samba"; trail="/dhcp.conf";}}
308
+
${etcRule { path = "samba"; trail = "/smb.conf"; }}
309
+
${etcRule { path = "samba"; trail = "/dhcp.conf"; }}
include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/X"
297
-
${etcRule {path="X11/cursors"; trail="/";}}
298
-
${etcRule {path="X11/cursors"; trail="/**";}}
313
+
${etcRule { path = "X11/cursors"; trail = "/"; }}
314
+
${etcRule { path = "X11/cursors"; trail = "/**"; }}