diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix index cc70216fccbd..b84a304574ec 100644 --- a/nixos/lib/systemd-lib.nix +++ b/nixos/lib/systemd-lib.nix @@ -58,7 +58,6 @@ let cfg = config.systemd; lndir = "${pkgs.buildPackages.lndir}/bin/lndir"; - systemd = cfg.package; in rec { @@ -697,14 +696,7 @@ rec { { config, ... }: { imports = [ serviceConfig ]; - # Default path for systemd services. Should be quite minimal. - config.path = mkIf config.enableDefaultPath (mkAfter [ - pkgs.coreutils - pkgs.findutils - pkgs.gnugrep - pkgs.gnused - systemd - ]); + config.path = mkIf config.enableDefaultPath (mkAfter cfg.defaultPath); }; stage1ServiceConfig = serviceConfig; diff --git a/nixos/lib/systemd-unit-options.nix b/nixos/lib/systemd-unit-options.nix index 86bb255a84c3..1a3098ccade5 100644 --- a/nixos/lib/systemd-unit-options.nix +++ b/nixos/lib/systemd-unit-options.nix @@ -379,7 +379,7 @@ rec { default = true; type = types.bool; description = '' - Whether to append a minimal default {env}`PATH` environment variable to the service, containing common system utilities. + Whether to append {option}`systemd.defaultPath` to the service's {env}`PATH` environment variable. ''; }; diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index a2078f1ce456..7088d9cf43a4 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -425,6 +425,17 @@ in ''; }; + defaultPath = mkOption { + type = types.listOf types.package; + default = [ ]; + description = '' + Packages appended to the {env}`PATH` environment variable of all + system and user services. + + Individual services can opt out by setting `enableDefaultPath = false`. + ''; + }; + globalEnvironment = mkOption { type = with types; @@ -733,6 +744,15 @@ in // listToAttrs (map (withName mountToUnit) cfg.mounts) // listToAttrs (map (withName automountToUnit) cfg.automounts); + # Default path for systemd services. Should be quite minimal. + systemd.defaultPath = [ + pkgs.coreutils + pkgs.findutils + pkgs.gnugrep + pkgs.gnused + cfg.package + ]; + # Environment of PID 1 systemd.managerEnvironment = { # Doesn't contain systemd itself - everything works so it seems to use the compiled-in value for its tools