1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2025-07-27 18:17:44 +00:00

shells: fix a lot of logic and use activation scripts

This commit is contained in:
RGBCube 2025-07-26 00:05:57 +03:00
parent e759456954
commit f673d73cd2
Signed by: RGBCube
SSH key fingerprint: SHA256:CzqbPcfwt+GxFYNnFVCqoN5Itn4YFrshg1TrnACpA5M
5 changed files with 165 additions and 132 deletions

View file

@ -1,16 +1,78 @@
{ config, lib, ... }: let
inherit (lib) attrsToList catAttrs mkConst mkIf mkValue sortOn toInt;
{ config, lib, pkgs, ... }: let
inherit (lib) attrsToList catAttrs concatStringsSep const filter flatten foldl' getAttr getExe head last listToAttrs mapAttrs mapAttrsToList match mkConst mkIf mkValue nameValuePair readFile sortOn splitString toInt unique;
in {
options.shells = mkValue {};
environment.shells = config.home-manager.users
|> mapAttrsToList (const <| getAttr "shellsByPriority")
|> flatten
|> unique;
options.shellsByPriority = mkConst (config.shells
|> attrsToList
|> sortOn ({ name, ... }: toInt name)
|> catAttrs "value");
home-manager.sharedModules = [
config = mkIf config.isDarwin {
environment.shells = config.shellsByPriority;
};
(homeArgs: let
config' = homeArgs.config;
in {
options.shells = mkValue {};
options.shellsByPriority = mkConst (config'.shells
|> attrsToList
|> sortOn ({ name, ... }: toInt name)
|> catAttrs "value");
options.variablesMap = mkConst ({
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);
})
(mkIf config.isDarwin (homeArgs: let
config' = homeArgs.config;
homeSessionVariables = let
homeSessionVariables = config'.home.sessionVariables;
homeSessionVariablesExtra = pkgs.runCommand "home-variables-extra.env" {} ''
bash -ic '
${config'.variablesMap
|> mapAttrsToList (name: value: "export ${name}='${value}'")
|> concatStringsSep "\n"}
alias export=echo
source ${config'.home.sessionVariablesPackage}/etc/profile.d/hm-session-vars.sh
' > $out
''
|> readFile
|> splitString "\n"
|> filter (s: s != "")
|> map (match "([^=]+)=(.*)")
|> map (keyAndValue: nameValuePair (head keyAndValue) (last keyAndValue))
|> foldl' (x: y: x // y) {};
homeSessionSearchVariables = config'.home.sessionSearchVariables
|> mapAttrs (const <| concatStringsSep ":");
in homeSessionVariables
// homeSessionVariablesExtra
// homeSessionSearchVariables;
in {
home.file.".zshrc".text = mkIf config.isDarwin /* zsh */ ''
${homeSessionVariables
|> mapAttrsToList (name: value: "export ${name}='${value}'")
|> concatStringsSep "\n"}
SHELL='${getExe <| head config'.shellsByPriority}' exec "$SHELL"
'';
}))
];
# More at modules/linux/shell/default.nix.
#