diff --git a/modules/common/nushell/default.nix b/modules/common/nushell/default.nix index a5229d4..2adc965 100644 --- a/modules/common/nushell/default.nix +++ b/modules/common/nushell/default.nix @@ -1,5 +1,5 @@ { config, lib, pkgs, ... }: let - inherit (lib) attrValues const enabled getExe mapAttrs mkIf optionalAttrs readFile removeAttrs replaceString; + inherit (lib) attrNames attrValues concatStringsSep const enabled flatten getExe listToAttrs mapAttrs mapAttrsToList mkIf optionalAttrs readFile removeAttrs replaceStrings; in { environment = optionalAttrs config.isLinux { sessionVariables.SHELLS = getExe pkgs.nushell; @@ -60,9 +60,29 @@ in { ''; environmentVariables = let + variablesMap = { + HOME = config'.home.homeDirectory; + USER = config'.home.username; + + XDG_CACHE_HOME = config'.xdg.cacheHome; + XDG_CONFIG_HOME = config'.xdg.configHome; + XDG_DATA_HOME = config'.xdg.dataHome; + XDG_STATE_HOME = config'.xdg.stateHome; + } + |> mapAttrsToList (name: value: [ + { name = "\$${name}"; inherit value; } + { name = "\${${name}}"; inherit value; } + ]) + |> flatten + |> listToAttrs; + environmentVariables = config.environment.variables; - homeVariables = config'.home.sessionVariables; + homeVariables = config'.home.sessionVariables; + + homeSearchVariables = config'.home.sessionSearchVariables + |> mapAttrs (const <| concatStringsSep ":"); + # homeVariablesExtra = pkgs.runCommand "home-variables-extra.env" {} '' # alias export=echo # # echo foo > $out @@ -77,8 +97,11 @@ in { # |> map (keyAndValue: nameValuePair (first keyAndValue) (last keyAndValue)) # |> foldl' (x: y: x // y) {}; homeVariablesExtra = {}; - in environmentVariables // homeVariables // homeVariablesExtra - |> mapAttrs (const <| replaceString "$HOME" config'.home.homeDirectory); + in environmentVariables + // homeVariables + // homeSearchVariables + // homeVariablesExtra + |> mapAttrs (const <| replaceStrings (attrNames variablesMap) (attrValues variablesMap)); shellAliases = removeAttrs config.environment.shellAliases [ "ls" "l" ] // { cdtmp = "cd (mktemp --directory)";