nixos/systemd: add defaultPath option

This commit is contained in:
Cathal Mullan
2026-10-11 16:23:01 +01:00
parent 62c4d51c2c
commit b8a8774af0
3 changed files with 22 additions and 10 deletions

View File

@@ -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;

View File

@@ -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.
'';
};

View File

@@ -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