nixpkgs/nixos/modules/security
aszlig 7286be7e81 nixos/systemd-confinement: Allow shipped unit file
In issue #157787 @martined wrote:

  Trying to use confinement on packages providing their systemd units
  with systemd.packages, for example mpd, fails with the following
  error:

  system-units> ln: failed to create symbolic link
  '/nix/store/...-system-units/mpd.service': File exists

  This is because systemd-confinement and mpd both provide a mpd.service
  file through systemd.packages. (mpd got updated that way recently to
  use upstream's service file)

To address this, we now place the unit file containing the bind-mounted
paths of the Nix closure into a drop-in directory instead of using the
name of a unit file directly.

This does come with the implication that the options set in the drop-in
directory won't apply if the main unit file is missing. In practice
however this should not happen for two reasons:

  * The systemd-confinement module already sets additional options via
    systemd.services and thus we should get a main unit file
  * In the unlikely event that we don't get a main unit file regardless
    of the previous point, the unit would be a no-op even if the options
    of the drop-in directory would apply

Another thing to consider is the order in which those options are
merged, since systemd loads the files from the drop-in directory in
alphabetical order. So given that we have confinement.conf and
overrides.conf, the confinement options are loaded before the NixOS
overrides.

Since we're only setting the BindReadOnlyPaths option, the order isn't
that important since all those paths are merged anyway and we still
don't lose the ability to reset the option since overrides.conf comes
afterwards.

Fixes: https://github.com/NixOS/nixpkgs/issues/157787
Signed-off-by: aszlig <aszlig@nix.build>
2022-03-02 11:42:44 -08:00
..
acme nixos/acme: ensure web servers using certs can access them 2022-01-08 15:05:34 -05:00
apparmor apparmor: Fix cups-client typo 2021-08-23 00:50:15 -07:00
wrappers treewide: remove obsolete kernel version checks 2022-02-19 21:09:19 +00:00
apparmor.nix nixos/security/apparmor: utillinux -> util-linux 2021-05-17 17:14:08 +02:00
audit.nix
auditd.nix
ca.nix nixos/ca: use cacert package build for options and p11-kit output 2021-10-08 01:21:57 +00:00
chromium-suid-sandbox.nix nixos: explicitely set security.wrappers ownership 2021-09-13 13:48:13 +02:00
dhparams.nix treewide: set defaultText for options using simple path defaults 2021-12-09 01:12:13 +01:00
doas.nix nixos/terminfo: inherit TERMINFO* env vars also for doas 2021-11-08 14:05:24 -08:00
duosec.nix nixos: explicitely set security.wrappers ownership 2021-09-13 13:48:13 +02:00
google_oslogin.nix google-compute-config: update config 2022-02-05 23:33:10 +03:00
lock-kernel-modules.nix nixos/lock-kernel-modules: reorder before/after 2021-09-19 12:06:00 +02:00
misc.nix nixos/nix-daemon: use structural settings 2022-01-26 21:04:50 -05:00
oath.nix
pam_mount.nix nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00
pam_usb.nix nixos: explicitely set security.wrappers ownership 2021-09-13 13:48:13 +02:00
pam.nix google-compute-config: update config 2022-02-05 23:33:10 +03:00
polkit.nix nixos: explicitely set security.wrappers ownership 2021-09-13 13:48:13 +02:00
rngd.nix nixos/rngd: Remove module entirely, leave an explaination 2021-02-21 01:32:50 +01:00
rtkit.nix nixos: define the primary group of users where needed 2021-09-12 14:59:30 +02:00
sudo.nix nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00
systemd-confinement.nix nixos/systemd-confinement: Allow shipped unit file 2022-03-02 11:42:44 -08:00
tpm2.nix nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00