hjem/environment: add uwsm support

This commit is contained in:
Anthony Rodriguez 2025-02-18 13:19:11 +01:00
parent 5a0e7a92f4
commit cefaa9a11a
Signed by: nezia
SSH key fingerprint: SHA256:R/ue1eTzTHUoo77lJD/3fSUsyL4AwvcHImU5BAZai+8

View file

@ -10,36 +10,31 @@
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.strings) concatStringsSep; inherit (lib.strings) concatStringsSep;
inherit (lib.types) attrsOf listOf oneOf int path str; inherit (lib.types) attrsOf listOf oneOf int path str;
inherit (pkgs) writeShellScript; inherit (pkgs) writeShellScript;
cfg = config.environment;
writeEnvScript = let
toEnv = env: toEnv = env:
if isList env if isList env
then concatStringsSep ":" (map toString env) then concatStringsSep ":" (map toString env)
else toString env; else toString env;
in
attrs: mkEnvVars = vars: (concatStringsSep "\n"
(mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") vars));
writeEnvScript = attrs:
writeShellScript "load-env" writeShellScript "load-env"
( (
'' ''
# Only execute this file once per shell. # Only execute this file once per shell.
if [ -n "$__ETC_PROFILE_SOURCED" ]; then return; fi if [ -n "$__ETC_PROFILE_SOURCED" ]; then return; fi
__ETC_PROFILE_SOURCED=1 __ETC_PROFILE_SOURCED=1
# Prevent this file from being sourced by interactive non-login child shells. # Prevent this file from being sourced by interactive non-login child shells.
export __ETC_PROFILE_DONE=1 export __ETC_PROFILE_DONE=1
# Session variables # Session variables
'' ''
+ (concatStringsSep "\n" + mkEnvVars attrs
(mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") attrs))
); );
in { in {
options.environment = { options.environment.sessionVariables = mkOption {
sessionVariables = mkOption {
type = attrsOf (oneOf [(listOf (oneOf [int str path])) int str path]); type = attrsOf (oneOf [(listOf (oneOf [int str path])) int str path]);
default = {}; default = {};
example = { example = {
@ -48,15 +43,17 @@ in {
}; };
description = '' description = ''
A set of environment variables used in the user environment. A set of environment variables used in the user environment.
These variables will be set using {file}`~/.profile`.
If a list of strings is used, they will be concatenated with colon If a list of strings is used, they will be concatenated with colon
characters. characters.
''; '';
}; };
};
config.files.".profile".text = mkIf (cfg.sessionVariables != {}) '' config = mkIf (config.environment.sessionVariables != {}) {
. ${writeEnvScript cfg.sessionVariables} files = {
".profile".text = ''
. ${writeEnvScript config.environment.sessionVariables}
''; '';
".config/uwsm/env".text = mkEnvVars config.environment.sessionVariables;
};
};
} }