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 ${lib.optionalString config.cow.starship.enable ''
65 source ${init-starship}
66 ''}
67 '';
68 shellAliases = {
69 "cd" = "z";
70 "py" = "python";
71 "🥺" = "sudo";
72 };
73 };
74 };
75 };
76}