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

136 lines
4.1 KiB
Nix

{ config, lib, pkgs, ... }: let
inherit (lib) attrValues 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 3";
tree = "eza --tree --git-ignore --group-directories-first";
};
systemPackages = attrValues {
inherit (pkgs)
fish # For completions.
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 = "92aba18381994599850053ba667c25017566b8ee";
hash = "sha256-FKDvkDcxUPDLcjFQzvqsGXeJUm0Dq8TcA4edf5OkdWo=";
};
cargoDeps = self.rustPlatform.fetchCargoVendor {
inherit (self.starship) src;
hash = "sha256-nH1iYjKw/GbYKadoymH3onWBbMzuMUaRCSTNWVE+A9E=";
};
nativeBuildInputs = old.nativeBuildInputs ++ [
pkgs.cmake
pkgs.zlib-ng
];
});
})];
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) {};
homeVariablesExtra = {};
in environmentVariables // homeVariables // homeVariablesExtra;
shellAliases = removeAttrs config.environment.shellAliases [ "ls" "l" ] // {
cdtmp = "cd (mktemp --directory)";
ll = "ls --long";
};
};
})];
}