I decided to go with the simpler solution of using `~/.profile`, as that is the only option that will ensure that the environment will be set correctly. If you launch a more barebones compositor such as Hyprland from your tty, since it won't be launched by systemd it will not inherit the environment.
51 lines
1.3 KiB
Nix
51 lines
1.3 KiB
Nix
{
|
|
lib,
|
|
pkgs,
|
|
config,
|
|
...
|
|
}: let
|
|
inherit (lib.attrsets) mapAttrsToList;
|
|
inherit (lib.lists) isList;
|
|
inherit (lib.modules) mkIf;
|
|
inherit (lib.options) mkOption;
|
|
inherit (lib.strings) concatStringsSep;
|
|
inherit (lib.types) attrsOf listOf oneOf int path str;
|
|
|
|
inherit (pkgs) writeShellScript;
|
|
|
|
cfg = config.environment;
|
|
|
|
writeEnvScript = let
|
|
toEnv = env:
|
|
if isList env
|
|
then concatStringsSep ":" (map toString env)
|
|
else toString env;
|
|
in
|
|
attrs:
|
|
writeShellScript "load-env"
|
|
(concatStringsSep "\n"
|
|
(mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") attrs));
|
|
in {
|
|
options.environment = {
|
|
sessionVariables = mkOption {
|
|
type = attrsOf (oneOf [(listOf (oneOf [int str path])) int str path]);
|
|
default = {};
|
|
example = {
|
|
EDITOR = "nvim";
|
|
VISUAL = "nvim";
|
|
};
|
|
description = ''
|
|
A set of environment variables used in the user environment.
|
|
These variables will be set as systemd user environment
|
|
variables, using `~/.profile`. The value of each
|
|
variable can be either a string or a list of strings. The
|
|
latter is concatenated, interspersed with colon
|
|
characters.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config.files.".profile".text = mkIf (cfg.sessionVariables != {}) ''
|
|
. ${writeEnvScript cfg.sessionVariables}
|
|
'';
|
|
}
|