Flake for my NixOS devices
1{...}: {
2 config,
3 pkgs,
4 lib,
5 ...
6}: {
7 options.cow.nushell = {
8 enable = lib.mkEnableOption "Nushell + Customizations";
9 commandNotFound = lib.mkEnableOption "Custom Nix Command Not Found for Nushell";
10 completers = {
11 carapace =
12 (lib.mkEnableOption "Carapace Completer In Nushell")
13 // {
14 default = true;
15 };
16 };
17 };
18
19 config = let
20 conf = config.cow.nushell;
21 in
22 lib.mkIf conf.enable {
23 cow.imperm.keep = [".local/share/zoxide"];
24 cow.imperm.keepFiles = [".config/nushell/history.txt"];
25
26 programs = {
27 zoxide.enable = true;
28 command-not-found.enable = !conf.commandNotFound;
29 nushell = let
30 carapaceComplete = builtins.replaceStrings ["__carapace__"] ["${pkgs.carapace}/bin/carapace"] (
31 lib.fileContents ../res/nushellCompletions/carapace.nu
32 );
33 cnf = lib.fileContents ../res/command_not_found.nu;
34 nu_config = let
35 doCompletions = builtins.any (x: x) (builtins.attrValues conf.completers);
36 in ''
37 {
38 show_banner: false,
39 completions: {
40 external: {
41 enable: ${builtins.toJSON doCompletions}
42 completer: ${
43 if doCompletions
44 then carapaceComplete
45 else ''{|spans| []}''
46 }
47 },
48 },
49 hooks: {
50 ${lib.optionalString conf.commandNotFound ''
51 command_not_found: ${cnf}
52 ''}
53 }
54 }
55 '';
56 init-starship = pkgs.runCommand "starship-init" {} ''
57 ${pkgs.starship}/bin/starship init nu > $out
58 '';
59 in {
60 enable = true;
61 configFile.text = ''
62 $env.config = ${nu_config}
63
64 # Utility Cmds
65
66 ## Dev Shell
67 def --wrapped dev [...rest] { nix develop -c env SHELL=nu ...$rest }
68 def --wrapped devsh [ ...rest ] { dev nu ...$rest }
69 def --wrapped dvim [...rest] { dev vim ...$rest }
70 def --wrapped djust [...rest] { dev just ...$rest }
71
72 ## Wezterm
73 ${lib.optionalString config.cow.gdi.enable ''
74 def --wrapped nt [...rest] { wezterm start --cwd $env.PWD -- ...$rest }
75 ''}
76
77 ${lib.optionalString config.cow.starship.enable ''
78 source ${init-starship}
79 ''}
80 '';
81 shellAliases = {
82 "cd" = "z";
83 "py" = "python";
84 "🥺" = "sudo";
85 };
86 };
87 };
88 };
89}