2025-02-09 15:31:32 +01:00
|
|
|
{
|
|
|
|
lib,
|
2025-02-09 17:04:15 +01:00
|
|
|
pkgs,
|
|
|
|
config,
|
2025-02-09 15:31:32 +01:00
|
|
|
...
|
|
|
|
}: let
|
2025-02-09 17:04:15 +01:00
|
|
|
inherit (lib.attrsets) mapAttrsToList;
|
|
|
|
inherit (lib.lists) isList;
|
|
|
|
inherit (lib.modules) mkIf;
|
2025-02-09 15:31:32 +01:00
|
|
|
inherit (lib.options) mkOption;
|
|
|
|
inherit (lib.strings) concatStringsSep;
|
2025-02-09 17:04:15 +01:00
|
|
|
inherit (lib.types) attrsOf listOf oneOf int path str;
|
|
|
|
inherit (pkgs) writeShellScript;
|
2025-02-09 15:31:32 +01:00
|
|
|
|
2025-02-18 19:02:00 +01:00
|
|
|
cfg = config.environment;
|
|
|
|
|
2025-02-18 13:19:11 +01:00
|
|
|
toEnv = env:
|
|
|
|
if isList env
|
|
|
|
then concatStringsSep ":" (map toString env)
|
|
|
|
else toString env;
|
2025-02-17 14:12:42 +01:00
|
|
|
|
2025-02-18 13:19:11 +01:00
|
|
|
mkEnvVars = vars: (concatStringsSep "\n"
|
|
|
|
(mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") vars));
|
2025-02-17 14:12:42 +01:00
|
|
|
|
2025-02-18 13:19:11 +01:00
|
|
|
writeEnvScript = attrs:
|
2025-02-18 19:02:00 +01:00
|
|
|
writeShellScript "set-environment"
|
|
|
|
(mkEnvVars attrs);
|
2025-02-09 15:31:32 +01:00
|
|
|
in {
|
2025-02-18 19:02:00 +01:00
|
|
|
options.environment = {
|
|
|
|
setEnvironment = mkOption {
|
|
|
|
type = path;
|
|
|
|
readOnly = true;
|
|
|
|
description = ''
|
|
|
|
A POSIX compliant shell script containing the user session variables needed to bootstrap the session.
|
2025-02-17 14:12:42 +01:00
|
|
|
|
2025-02-18 19:02:00 +01:00
|
|
|
As there is no reliable and agnostic way of setting session variables, Hjem's
|
|
|
|
environment module does nothing by itself. Rather, it provides a POSIX compliant shell script
|
|
|
|
that needs to be sourced where needed.
|
2025-02-09 15:31:32 +01:00
|
|
|
'';
|
|
|
|
};
|
2025-02-18 19:02:00 +01:00
|
|
|
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.
|
|
|
|
If a list of strings is used, they will be concatenated with colon
|
|
|
|
characters.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.sessionVariables != {}) {
|
|
|
|
environment.setEnvironment = writeEnvScript cfg.sessionVariables;
|
2025-02-09 15:31:32 +01:00
|
|
|
};
|
|
|
|
}
|