From 5a699752fdd0fc4efe18b311490a0a275fbaa8b3 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Sat, 19 Jul 2025 21:01:54 +0300 Subject: [PATCH] shells: init --- modules/common/nushell/config.nu | 2 +- modules/common/nushell/default.nix | 58 +++++------------------------- modules/common/shell/aliases.nix | 16 +++++++++ modules/common/shell/carapace.nix | 16 +++++++++ modules/common/shell/default.nix | 21 +++++++++++ modules/common/shell/direnv.nix | 9 +++++ modules/common/shell/vivid.nix | 9 +++++ modules/common/shell/zoxide.nix | 9 +++++ modules/linux/crash.nix | 3 -- modules/linux/restic/default.nix | 2 +- modules/linux/shell/default.nix | 9 +++++ 11 files changed, 99 insertions(+), 55 deletions(-) create mode 100644 modules/common/shell/aliases.nix create mode 100644 modules/common/shell/carapace.nix create mode 100644 modules/common/shell/default.nix create mode 100644 modules/common/shell/direnv.nix create mode 100644 modules/common/shell/vivid.nix create mode 100644 modules/common/shell/zoxide.nix delete mode 100644 modules/linux/crash.nix create mode 100644 modules/linux/shell/default.nix diff --git a/modules/common/nushell/config.nu b/modules/common/nushell/config.nu index 4c9c137..6595198 100644 --- a/modules/common/nushell/config.nu +++ b/modules/common/nushell/config.nu @@ -196,7 +196,7 @@ do --env { } else { $pwd } - + $"($hostname)(ansi cyan)($pwd)(ansi reset)" } diff --git a/modules/common/nushell/default.nix b/modules/common/nushell/default.nix index a3fb279..c890b6f 100644 --- a/modules/common/nushell/default.nix +++ b/modules/common/nushell/default.nix @@ -1,62 +1,20 @@ { config, lib, pkgs, ... }: let - inherit (lib) attrNames attrValues concatStringsSep const enabled filter flatten foldl' getExe head last listToAttrs mapAttrs mapAttrsToList match mkIf nameValuePair optionalAttrs readFile removeAttrs replaceStrings splitString; + inherit (lib) attrNames attrValues concatStringsSep const enabled filter flatten foldl' head last listToAttrs mapAttrs mapAttrsToList match nameValuePair readFile removeAttrs replaceStrings splitString; + + package = pkgs.nushell; in { - environment = optionalAttrs config.isLinux { - sessionVariables.SHELLS = getExe pkgs.nushell; - } // { - shells = mkIf config.isDarwin [ pkgs.nushell ]; - - shellAliases = { - la = "ls --all"; - ll = "ls --long"; - 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) - carapace # For completions. - fish # For completions. - zsh # For completions. - inshellisense # For completions. - ; - }; - }; + shells."0" = package; home-manager.sharedModules = [(homeArgs: let config' = homeArgs.config; in { - programs.carapace = enabled { - enableNushellIntegration = true; - }; - - programs.direnv = enabled { - enableNushellIntegration = true; - - nix-direnv = enabled; - }; - - programs.zoxide = enabled { - enableNushellIntegration = true; - - options = [ "--cmd cd" ]; - }; - programs.nushell = enabled { + inherit package; + configFile.text = readFile ./config.nu; - extraConfig = '' - $env.LS_COLORS = open ${pkgs.runCommand "ls_colors.txt" {} '' - ${getExe pkgs.vivid} generate gruvbox-dark-hard > $out - ''} + extraConfig = /* nu */ '' + $env.LS_COLORS = open ${config.environment.ls-colors} ''; environmentVariables = let diff --git a/modules/common/shell/aliases.nix b/modules/common/shell/aliases.nix new file mode 100644 index 0000000..906ec9d --- /dev/null +++ b/modules/common/shell/aliases.nix @@ -0,0 +1,16 @@ +{ + environment.shellAliases = { + la = "ls --all"; + ll = "ls --long"; + 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"; + }; +} diff --git a/modules/common/shell/carapace.nix b/modules/common/shell/carapace.nix new file mode 100644 index 0000000..426539a --- /dev/null +++ b/modules/common/shell/carapace.nix @@ -0,0 +1,16 @@ +{ lib, pkgs, ... }: let + inherit (lib) attrValues enabled; +in { + environment.systemPackages = attrValues { + inherit (pkgs) + carapace + fish + zsh + inshellisense + ; + }; + + home-manager.sharedModules = [{ + programs.carapace = enabled; + }]; +} diff --git a/modules/common/shell/default.nix b/modules/common/shell/default.nix new file mode 100644 index 0000000..a22401e --- /dev/null +++ b/modules/common/shell/default.nix @@ -0,0 +1,21 @@ +{ config, lib, ... }: let + inherit (lib) attrsToList catAttrs mkConst mkIf mkValue sortOn toInt; +in { + options.shells = mkValue {}; + + options.shellsByPriority = mkConst (config.shells + |> attrsToList + |> sortOn ({ name, ... }: toInt name) + |> catAttrs "value"); + + config = mkIf config.isDarwin { + environment.shells = config.shellsByPriority; + }; + + # More at modules/linux/shell/default.nix. + # + # Can't put that here with an optionalAttributes + # becuase of an infinite recursion error, and can't + # do that with a mkIf because the nix-darwin module + # system doesn't have those attributes. +} diff --git a/modules/common/shell/direnv.nix b/modules/common/shell/direnv.nix new file mode 100644 index 0000000..9808c2d --- /dev/null +++ b/modules/common/shell/direnv.nix @@ -0,0 +1,9 @@ +{ lib, ... }: let + inherit (lib) enabled; +in { + home-manager.sharedModules = [{ + programs.direnv = enabled { + nix-direnv = enabled; + }; + }]; +} diff --git a/modules/common/shell/vivid.nix b/modules/common/shell/vivid.nix new file mode 100644 index 0000000..bee8b3e --- /dev/null +++ b/modules/common/shell/vivid.nix @@ -0,0 +1,9 @@ +{ lib, pkgs, ... }: let + inherit (lib) getExe mkConst; + + lsColors = pkgs.runCommand "ls_colors.txt" {} '' + ${getExe pkgs.vivid} generate gruvbox-dark-hard > $out + ''; +in { + options.environment.ls-colors = mkConst lsColors; +} diff --git a/modules/common/shell/zoxide.nix b/modules/common/shell/zoxide.nix new file mode 100644 index 0000000..235183e --- /dev/null +++ b/modules/common/shell/zoxide.nix @@ -0,0 +1,9 @@ +{ lib, ... }: let + inherit (lib) enabled; +in { + home-manager.sharedModules = [{ + programs.zoxide = enabled { + options = [ "--cmd cd" ]; + }; + }]; +} diff --git a/modules/linux/crash.nix b/modules/linux/crash.nix deleted file mode 100644 index adef320..0000000 --- a/modules/linux/crash.nix +++ /dev/null @@ -1,3 +0,0 @@ -{ pkgs, ... }: { - users.defaultUserShell = pkgs.crash; -} diff --git a/modules/linux/restic/default.nix b/modules/linux/restic/default.nix index 7596bfa..60a7007 100644 --- a/modules/linux/restic/default.nix +++ b/modules/linux/restic/default.nix @@ -1,6 +1,6 @@ { config, lib, ... }: let inherit (lib) genAttrs mkConst mkIf remove; -in{ +in { options.services.restic.hosts = mkConst <| remove config.networking.hostName [ "nine" "best" ]; config.secrets.resticPassword.file = mkIf config.isServer ./password.age; diff --git a/modules/linux/shell/default.nix b/modules/linux/shell/default.nix new file mode 100644 index 0000000..dff21fa --- /dev/null +++ b/modules/linux/shell/default.nix @@ -0,0 +1,9 @@ +{ config, lib, pkgs, ... }: let + inherit (lib) concatStringsSep; +in { + users.defaultUserShell = pkgs.crash; + + environment.sessionVariables.SHELLS = config.shellsByPriority + |> map (drv: "${drv}${drv.shellPath}") + |> concatStringsSep ":"; +}