diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index 14caa5d360d5..777c1ea74d88 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -317,7 +317,9 @@ let '' [Service] ${let env = cfg.globalEnvironment // def.environment; - in concatMapStrings (n: "Environment=\"${n}=${getAttr n env}\"\n") (attrNames env)} + in concatMapStrings (n: + let s = "Environment=\"${n}=${getAttr n env}\"\n"; + in if stringLength s >= 2048 then throw "The value of the environment variable ‘${n}’ in systemd service ‘${name}.service’ is too long." else s) (attrNames env)} ${if def.reloadIfChanged then '' X-ReloadIfChanged=true '' else if !def.restartIfChanged then ''