share.nix
1 { lib 2 , config 3 , ... 4 }: 5 6 7 let 8 inherit (config) symbols; 9 inherit (config.lib) mkCmdGroup; 10 in 11 { 12 perSystem = { pkgs, config, ... }: 13 let 14 NixCallCmdGroup = mkCmdGroup "NixCall" [ 15 { 16 name = "up"; 17 help = "Update nix flake"; 18 command = "nix flake update"; 19 } 20 { 21 name = "upp"; 22 help = "Update specific input"; 23 command = "nix flake update $1"; 24 } 25 { 26 name = "repl"; 27 help = "Start nix repl with nixpkgs"; 28 command = "nix repl -f flake:nixpkgs"; 29 } 30 { 31 name = "gc"; 32 help = "Garbage collect all unused nix store entries"; 33 command = '' 34 if [ "$EUID" -ne 0 ] 35 then echo -e "\e[33mwarnning: run as root\e[0m" >&2 36 sudo -H nix store gc --debug 37 sudo -H nix-collect-garbage --delete-old 38 fi 39 40 nix store gc --debug 41 nix-collect-garbage --delete-old 42 ''; 43 } 44 { 45 # name = "nfmt"; 46 # help = "Format the current flake"; 47 # command = "nix fmt"; 48 package = config.treefmt.build.wrapper; 49 } 50 { 51 name = "rebuild"; 52 help = "Rebuild system to contain a specified system configuration output"; 53 command = builtins.readFile ../../scripts/rebuild.zuo; 54 } 55 ]; 56 MiscCmdGroup = mkCmdGroup "Misc" [ 57 { 58 name = "dr"; 59 help = "Direnv reload"; 60 command = "direnv reload"; 61 } 62 { 63 name = "gitgc"; 64 help = "Garbage collect git store"; 65 command = '' 66 git reflog expire --expire-unreachable=now --all 67 git gc --prune=now 68 ''; 69 } 70 { 71 name = "lspath"; 72 help = "list $PATH line by line"; 73 command = "printenv PATH | tr ':' '\n'"; 74 } 75 { 76 name = "batype"; 77 help = "Bat content of command"; 78 command = '' 79 bat $(type -P $1) "''${@:2}" 80 ''; 81 } 82 { 83 name = "machines"; 84 help = "List all of machines"; 85 command = 86 let 87 inherit (symbols) machines people; 88 89 mapper = name: opt: '' 90 echo -n "- ${name} " 91 92 if (ssh -o ConnectTimeout=5 -o ConnectionAttempts=2 -q -p ${toString opt.port} "${people.myself}@${opt.host}" "exit") 93 then 94 echo -e "\t\e[0;32m✅ running\e[0m" 95 else 96 echo -e "\t\e[0;31m❌ down\e[0m" 97 fi 98 ''; 99 in 100 lib.concatLines (lib.mapAttrsToList mapper machines); 101 } 102 ]; 103 in 104 { 105 devshells.default = { 106 commands = NixCallCmdGroup ++ MiscCmdGroup; 107 packages = with pkgs; [ sops ]; 108 }; 109 }; 110 }