systemd: add support for session variables
Via environment.d(5).
This commit is contained in:
parent
6ebf14143a
commit
1fdb16866b
|
@ -12,7 +12,8 @@ let
|
||||||
|| cfg.sockets != {}
|
|| cfg.sockets != {}
|
||||||
|| cfg.targets != {}
|
|| cfg.targets != {}
|
||||||
|| cfg.timers != {}
|
|| cfg.timers != {}
|
||||||
|| cfg.paths != {};
|
|| cfg.paths != {}
|
||||||
|
|| cfg.sessionVariables != {};
|
||||||
|
|
||||||
toSystemdIni = generators.toINI {
|
toSystemdIni = generators.toINI {
|
||||||
mkKeyValue = key: value:
|
mkKeyValue = key: value:
|
||||||
|
@ -85,6 +86,13 @@ let
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
sessionVariables = mkIf (cfg.sessionVariables != {}) {
|
||||||
|
"environment.d/10-home-manager.conf".text =
|
||||||
|
concatStringsSep "\n" (
|
||||||
|
mapAttrsToList (n: v: "${n}=${toString v}") cfg.sessionVariables
|
||||||
|
) + "\n";
|
||||||
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -156,6 +164,20 @@ in
|
||||||
start is considered successful.
|
start is considered successful.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sessionVariables = mkOption {
|
||||||
|
default = {};
|
||||||
|
type = with types; attrsOf (either int str);
|
||||||
|
example = { EDITOR = "vim"; };
|
||||||
|
description = ''
|
||||||
|
Environment variables that will be set for the user session.
|
||||||
|
The variable values must be as described in
|
||||||
|
<citerefentry>
|
||||||
|
<refentrytitle>environment.d</refentrytitle>
|
||||||
|
<manvolnum>5</manvolnum>
|
||||||
|
</citerefentry>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -168,7 +190,7 @@ in
|
||||||
let
|
let
|
||||||
names = concatStringsSep ", " (
|
names = concatStringsSep ", " (
|
||||||
attrNames (
|
attrNames (
|
||||||
cfg.services // cfg.sockets // cfg.targets // cfg.timers // cfg.paths
|
cfg.services // cfg.sockets // cfg.targets // cfg.timers // cfg.paths // cfg.sessionVariables
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
|
@ -180,8 +202,8 @@ in
|
||||||
# If we run under a Linux system we assume that systemd is
|
# If we run under a Linux system we assume that systemd is
|
||||||
# available, in particular we assume that systemctl is in PATH.
|
# available, in particular we assume that systemctl is in PATH.
|
||||||
(mkIf pkgs.stdenv.isLinux {
|
(mkIf pkgs.stdenv.isLinux {
|
||||||
xdg.configFile =
|
xdg.configFile = mkMerge [
|
||||||
listToAttrs (
|
(listToAttrs (
|
||||||
(buildServices "service" cfg.services)
|
(buildServices "service" cfg.services)
|
||||||
++
|
++
|
||||||
(buildServices "socket" cfg.sockets)
|
(buildServices "socket" cfg.sockets)
|
||||||
|
@ -191,7 +213,10 @@ in
|
||||||
(buildServices "timer" cfg.timers)
|
(buildServices "timer" cfg.timers)
|
||||||
++
|
++
|
||||||
(buildServices "path" cfg.paths)
|
(buildServices "path" cfg.paths)
|
||||||
);
|
))
|
||||||
|
|
||||||
|
sessionVariables
|
||||||
|
];
|
||||||
|
|
||||||
# Run systemd service reload if user is logged in. If we're
|
# Run systemd service reload if user is logged in. If we're
|
||||||
# running this from the NixOS module then XDG_RUNTIME_DIR is not
|
# running this from the NixOS module then XDG_RUNTIME_DIR is not
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
systemd-services = ./services.nix;
|
systemd-services = ./services.nix;
|
||||||
|
systemd-session-variables = ./session-variables.nix;
|
||||||
systemd-timers = ./timers.nix;
|
systemd-timers = ./timers.nix;
|
||||||
}
|
}
|
||||||
|
|
2
tests/modules/systemd/session-variables-expected.conf
Normal file
2
tests/modules/systemd/session-variables-expected.conf
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
V_int=1
|
||||||
|
V_str=2
|
18
tests/modules/systemd/session-variables.nix
Normal file
18
tests/modules/systemd/session-variables.nix
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
systemd.user.sessionVariables = {
|
||||||
|
V_int = 1;
|
||||||
|
V_str = "2";
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
local envFile=home-files/.config/environment.d/10-home-manager.conf
|
||||||
|
assertFileExists $envFile
|
||||||
|
assertFileContent $envFile ${./session-variables-expected.conf}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue