From 55a3c1bce2645f229e494496bb4356fba67113bb Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Mon, 17 Feb 2025 14:12:42 +0100 Subject: [PATCH] hjem/environment: source env file only once --- .../modules/hjem/collection/environment.nix | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/shared/modules/hjem/collection/environment.nix b/shared/modules/hjem/collection/environment.nix index 1e8f5cd..d53df14 100644 --- a/shared/modules/hjem/collection/environment.nix +++ b/shared/modules/hjem/collection/environment.nix @@ -23,8 +23,20 @@ in attrs: writeShellScript "load-env" - (concatStringsSep "\n" - (mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") 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 + '' + + (concatStringsSep "\n" + (mapAttrsToList (name: value: "export ${name}=\"${toEnv value}\"") attrs)) + ); in { options.environment = { sessionVariables = mkOption { @@ -36,10 +48,9 @@ in { }; description = '' A set of environment variables used in the user environment. - These variables will be set as systemd user environment - variables, using `~/.profile`. The value of each - variable can be either a string or a list of strings. The - latter is concatenated, interspersed with colon + These variables will be set using {file}`~/.profile`. + + If a list of strings is used, they will be concatenated with colon characters. ''; };