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

View file

@ -12,6 +12,8 @@
inherit (lib.types) attrsOf listOf oneOf int path str;
inherit (pkgs) writeShellScript;
cfg = config.environment;
toEnv = env:
if isList env
then concatStringsSep ":" (map toString env)
@ -21,20 +23,22 @@
(mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") vars));
writeEnvScript = 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.
export __ETC_PROFILE_DONE=1
# Session variables
''
+ mkEnvVars attrs
);
writeShellScript "set-environment"
(mkEnvVars attrs);
in {
options.environment.sessionVariables = mkOption {
options.environment = {
setEnvironment = mkOption {
type = path;
readOnly = true;
description = ''
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 = {
@ -47,13 +51,9 @@ in {
characters.
'';
};
config = mkIf (config.environment.sessionVariables != {}) {
files = {
".profile".text = ''
. ${writeEnvScript config.environment.sessionVariables}
'';
".config/uwsm/env".text = mkEnvVars config.environment.sessionVariables;
};
config = mkIf (cfg.sessionVariables != {}) {
environment.setEnvironment = writeEnvScript cfg.sessionVariables;
};
}