1
Fork 0
mirror of https://github.com/RGBCube/ncc synced 2026-01-15 01:31:02 +00:00
ncc/modules/common/nushell/default.nix

128 lines
3.9 KiB
Nix

{ config, lib, pkgs, ... }: let
inherit (lib) enabled filter first foldl' getExe last match mkIf nameValuePair optionalAttrs readFile removeAttrs splitString;
in {
environment = optionalAttrs config.isLinux {
sessionVariables.SHELLS = getExe pkgs.nushell;
} // {
shells = mkIf config.isDarwin [ pkgs.nushell ];
shellAliases = {
la = "ls --all";
lla = "ls --long --all";
sl = "ls";
cp = "cp --recursive --verbose --progress";
mk = "mkdir";
mv = "mv --verbose";
rm = "rm --recursive --verbose";
pstree = "pstree -g 2";
tree = "tree -CF --dirsfirst";
};
systemPackages = [
pkgs.fish # For completions.
pkgs.zoxide # For completions and better cd.
];
variables.STARSHIP_LOG = "error";
};
nixpkgs.overlays = [(self: super: {
zoxide = super.zoxide.overrideAttrs (old: {
src = self.fetchFromGitHub {
owner = "Bahex";
repo = "zoxide";
rev = "0450775af9b1430460967ba8fb5aa434f95c4bc4";
hash = "sha256-WhACxJMuhI9HGohcwg+ztZpQCVUZ4uibIQqGfJEEp/Y=";
};
cargoDeps = self.rustPlatform.fetchCargoVendor {
inherit (self.zoxide) src;
hash = "sha256-v3tcQaEXfGyt1j2fShvxxrA9Xc90AWxEzEUT09cQ+is=";
};
});
starship = super.starship.overrideAttrs (old: {
src = self.fetchFromGitHub {
owner = "poliorcetics";
repo = "starship";
rev = "19926e1e0aa25eddf63f93ba270d60eef023338f";
hash = "sha256-mi2O8JzXNLIF0/GuXVyf27JVV7d6zoskIjB29r5fPso=";
};
cargoDeps = self.rustPlatform.fetchCargoVendor {
inherit (self.starship) src;
hash = "sha256-EvslXwa4xGrrWLTqJlj/+iviBibPY0lRKcErNpb1FFo=";
};
});
})];
home-manager.sharedModules = [(homeArgs: let
homeConfig = homeArgs.config;
in {
xdg.configFile = {
"nushell/zoxide.nu".source = pkgs.runCommand "zoxide.nu" {} ''
${getExe pkgs.zoxide} init nushell --cmd cd > $out
'';
"nushell/ls_colors.txt".source = pkgs.runCommand "ls_colors.txt" {} ''
${getExe pkgs.vivid} generate gruvbox-dark-hard > $out
'';
"nushell/starship.nu".source = pkgs.runCommand "starship.nu" {} ''
${getExe pkgs.starship} init nu > $out
'';
};
programs.starship = enabled {
# No because we are doing it at build time instead of the way
# this retarded module does it. Why the hell do you generate
# the config every time the shell is launched?
enableNushellIntegration = false;
settings = {
vcs.disabled = false;
command_timeout = 100;
scan_timeout = 20;
cmd_duration.show_notifications = config.isDesktop;
package.disabled = config.isServer;
character.error_symbol = "";
character.success_symbol = "";
};
};
programs.nushell = enabled {
configFile.text = readFile ./config.nu;
envFile.text = readFile ./environment.nu;
environmentVariables = let
environmentVariables = config.environment.variables;
homeVariables = homeConfig.home.sessionVariables;
homeVariablesExtra = pkgs.runCommand "home-variables-extra.env" {} ''
alias export=echo
# echo foo > $out
# FIXME
eval $(cat ${homeConfig.home.sessionVariablesPackage}/etc/profile.d/hm-session-vars.sh) > $out
''
# |> (aaa: (_: break _) aaa)
|> readFile
|> splitString "\n"
|> filter (s: s != "")
|> map (match "([^=]+)=(.*)")
|> map (keyAndValue: nameValuePair (first keyAndValue) (last keyAndValue))
|> foldl' (x: y: x // y) {};
in environmentVariables // homeVariables // homeVariablesExtra;
shellAliases = removeAttrs config.environment.shellAliases [ "ls" "l" ] // {
cdtmp = "cd (mktemp --directory)";
ll = "ls --long";
};
};
})];
}