hjem/environment: update to provide environment script

This commit is contained in:
Anthony Rodriguez 2025-02-18 19:02:00 +01:00
parent a3a3aa8231
commit 0e72c5f67d
Signed by: nezia
SSH key fingerprint: SHA256:R/ue1eTzTHUoo77lJD/3fSUsyL4AwvcHImU5BAZai+8
2 changed files with 33 additions and 30 deletions

View file

@ -11,6 +11,7 @@
inherit (config.local.systemVars) username; inherit (config.local.systemVars) username;
styleCfg = config.local.style; styleCfg = config.local.style;
gnomeControlCenter = pkgs.gnome-control-center.overrideAttrs (old: { gnomeControlCenter = pkgs.gnome-control-center.overrideAttrs (old: {
postInstall = postInstall =
old.postInstall old.postInstall
@ -155,6 +156,8 @@ in {
} }
// import ./binds.nix lib; // import ./binds.nix lib;
}; };
".config/uwsm/env-hyprland".source = config.hjem.users.${username}.environment.setEnvironment;
}; };
environment.sessionVariables = mkMerge [ environment.sessionVariables = mkMerge [

View file

@ -12,6 +12,8 @@
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: toEnv = env:
if isList env if isList env
then concatStringsSep ":" (map toString env) then concatStringsSep ":" (map toString env)
@ -21,39 +23,37 @@
(mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") vars)); (mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") vars));
writeEnvScript = attrs: writeEnvScript = attrs:
writeShellScript "load-env" writeShellScript "set-environment"
( (mkEnvVars attrs);
''
# 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.
export __ETC_PROFILE_DONE=1
# Session variables
''
+ mkEnvVars attrs
);
in { in {
options.environment.sessionVariables = mkOption { options.environment = {
type = attrsOf (oneOf [(listOf (oneOf [int str path])) int str path]); setEnvironment = mkOption {
default = {}; type = path;
example = { readOnly = true;
EDITOR = "nvim"; description = ''
VISUAL = "nvim"; A POSIX compliant shell script containing the user session variables needed to bootstrap the session.
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.
'';
};
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.
'';
}; };
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 (config.environment.sessionVariables != {}) { config = mkIf (cfg.sessionVariables != {}) {
files = { environment.setEnvironment = writeEnvScript cfg.sessionVariables;
".profile".text = ''
. ${writeEnvScript config.environment.sessionVariables}
'';
".config/uwsm/env".text = mkEnvVars config.environment.sessionVariables;
};
}; };
} }