From 1312b27c07f0b4c37bd46a07fedaad7d37f96244 Mon Sep 17 00:00:00 2001 From: Winter M Date: Tue, 20 Jan 2026 14:04:10 -0500 Subject: [PATCH] nixos/systemd: allow disabling the path default for services There are times where I want to have services without this default, especially when writing overrides. --- nixos/lib/systemd-lib.nix | 24 +++++++++++++----------- nixos/lib/systemd-unit-options.nix | 8 ++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/nixos/lib/systemd-lib.nix b/nixos/lib/systemd-lib.nix index 9db4c6fb8c47..734ab3f28b14 100644 --- a/nixos/lib/systemd-lib.nix +++ b/nixos/lib/systemd-lib.nix @@ -688,17 +688,19 @@ rec { }; }; - stage2ServiceConfig = { - imports = [ serviceConfig ]; - # Default path for systemd services. Should be quite minimal. - config.path = mkAfter [ - pkgs.coreutils - pkgs.findutils - pkgs.gnugrep - pkgs.gnused - systemd - ]; - }; + stage2ServiceConfig = + { 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 + ]); + }; stage1ServiceConfig = serviceConfig; diff --git a/nixos/lib/systemd-unit-options.nix b/nixos/lib/systemd-unit-options.nix index eff78fef265d..5e85a9c2a1d9 100644 --- a/nixos/lib/systemd-unit-options.nix +++ b/nixos/lib/systemd-unit-options.nix @@ -379,6 +379,14 @@ rec { ''; }; + enableDefaultPath = mkOption { + default = true; + type = types.bool; + description = '' + Whether to append a minimal default {env}`PATH` environment variable to the service, containing common system utilities. + ''; + }; + serviceConfig = mkOption { default = { }; example = {