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,53 +10,50 @@
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; toEnv = env:
if isList env
then concatStringsSep ":" (map toString env)
else toString env;
writeEnvScript = let mkEnvVars = vars: (concatStringsSep "\n"
toEnv = env: (mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") vars));
if isList env
then concatStringsSep ":" (map toString env)
else toString env;
in
attrs:
writeShellScript "load-env"
(
''
# Only execute this file once per shell.
if [ -n "$__ETC_PROFILE_SOURCED" ]; then return; fi
__ETC_PROFILE_SOURCED=1
# Prevent this file from being sourced by interactive non-login child shells. writeEnvScript = attrs:
export __ETC_PROFILE_DONE=1 writeShellScript "load-env"
(
# Session variables ''
'' # Only execute this file once per shell.
+ (concatStringsSep "\n" if [ -n "$__ETC_PROFILE_SOURCED" ]; then return; fi
(mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") attrs)) __ETC_PROFILE_SOURCED=1
); # Prevent this file from being sourced by interactive non-login child shells.
export __ETC_PROFILE_DONE=1
# Session variables
''
+ mkEnvVars 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 = { EDITOR = "nvim";
EDITOR = "nvim"; VISUAL = "nvim";
VISUAL = "nvim";
};
description = ''
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
characters.
'';
}; };
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.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;
};
};
} }