From 61137e106f5741bd5d1b096377786771f5b148a3 Mon Sep 17 00:00:00 2001 From: Swarsel Date: Mon, 16 Dec 2024 21:04:42 +0100 Subject: [PATCH] feat: improve NixOS core functions --- SwarselSystems.org | 239 +++++++++++++------------- profiles/common/home/packages.nix | 1 - profiles/common/home/zsh.nix | 14 +- profiles/common/nixos/nvd-rebuild.nix | 2 +- 4 files changed, 127 insertions(+), 129 deletions(-) diff --git a/SwarselSystems.org b/SwarselSystems.org index 30158d8..2c0d638 100644 --- a/SwarselSystems.org +++ b/SwarselSystems.org @@ -4890,7 +4890,7 @@ This snipped is added to the activation script that is run after every rebuild a system.activationScripts.diff = { supportsDryActivation = true; text = '' - ${pkgs.nvd}/bin/nvd --nix-bin-dir=${pkgs.nix}/bin diff \ + ${pkgs.nvd}/bin/nvd --color=always --nix-bin-dir=${pkgs.nix}/bin diff \ /run/current-system "$systemConfig" ''; }; @@ -7362,7 +7362,6 @@ This holds packages that I can use as provided, or with small modifications (as nmap lsof nvd - nh nix-output-monitor hyprpicker # color picker findutils @@ -8190,125 +8189,125 @@ zsh is the most convenient shell for me and it happens to be super neat to confi Here we set some aliases (some of them should be shellApplications instead) as well as some zsh plugins like =fzf-tab=. #+begin_src nix :tangle profiles/common/home/zsh.nix -{ config, pkgs, lib, ... }: -{ - programs.zsh = { - enable = true; - shellAliases = lib.recursiveUpdate - { - hg = "history | grep"; - hmswitch = "home-manager --flake ${config.swarselsystems.flakePath}#$(whoami)@$(hostname) switch"; - nswitch = "sudo nixos-rebuild --flake ${config.swarselsystems.flakePath}#$(hostname) switch"; - nboot = "sudo nixos-rebuild --flake ${config.swarselsystems.flakePath}#$(hostname) boot"; - magit = "emacsclient -nc -e \"(magit-status)\""; - config = "git --git-dir=$HOME/.cfg/ --work-tree=$HOME"; - g = "git"; - c = "git --git-dir=$HOME/.dotfiles/.git --work-tree=$HOME/.dotfiles/"; - passpush = "cd ~/.local/share/password-store; git add .; git commit -m 'pass file changes'; git push; cd -;"; - passpull = "cd ~/.local/share/password-store; git pull; cd -;"; - hotspot = "nmcli connection up local; nmcli device wifi hotspot;"; - cd = "z"; - cd-orig = "cd"; - cat-orig = "cat"; - cdr = "cd \"$( (find /home/swarsel/Documents/GitHub -maxdepth 1 && echo /home/swarsel/.dotfiles) | fzf )\""; - nix-ldd = "LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH ldd"; - fs-diff = "sudo mount -o subvol=/ /dev/mapper/cryptroot /mnt ; fs-diff"; - lt = "ls -lath"; - oldshell = "nix shell github:nixos/nixpkgs/\"$1\" \"$2\""; - } - config.swarselsystems.shellAliases; - autosuggestion.enable = true; - enableCompletion = true; - syntaxHighlighting.enable = true; - autocd = false; - cdpath = [ - "~/.dotfiles" - # "~/Documents/GitHub" - ]; - defaultKeymap = "emacs"; - dirHashes = { - dl = "$HOME/Downloads"; - gh = "$HOME/Documents/GitHub"; + { config, pkgs, lib, ... }: + { + programs.zsh = { + enable = true; + shellAliases = lib.recursiveUpdate + { + hg = "history | grep"; + hmswitch = "home-manager --flake ${config.swarselsystems.flakePath}#$(whoami)@$(hostname) switch |& nom"; + nswitch = "sudo nixos-rebuild --flake ${config.swarselsystems.flakePath}#$(hostname) --show-trace --log-format internal-json -v switch |& nom --json"; + nboot = "sudo nixos-rebuild --flake ${config.swarselsystems.flakePath}#$(hostname) --show-trace --log-format internal-json -v boot |& nom --json"; + magit = "emacsclient -nc -e \"(magit-status)\""; + config = "git --git-dir=$HOME/.cfg/ --work-tree=$HOME"; + g = "git"; + c = "git --git-dir=$FLAKE/.git --work-tree=$FLAKE/"; + passpush = "cd ~/.local/share/password-store; git add .; git commit -m 'pass file changes'; git push; cd -;"; + passpull = "cd ~/.local/share/password-store; git pull; cd -;"; + hotspot = "nmcli connection up local; nmcli device wifi hotspot;"; + cd = "z"; + cd-orig = "cd"; + cat-orig = "cat"; + cdr = "cd \"$( (find $DOCUMENT_DIR_WORK $DOCUMENT_DIR_PRIV -maxdepth 1 && echo $FLAKE) | fzf )\""; + nix-ldd = "LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH ldd"; + fs-diff = "sudo mount -o subvol=/ /dev/mapper/cryptroot /mnt ; fs-diff"; + lt = "eza -las modified --total-size"; + boot-diff = "nix store diff-closures /run/*-system"; + } + config.swarselsystems.shellAliases; + autosuggestion.enable = true; + enableCompletion = true; + syntaxHighlighting.enable = true; + autocd = false; + cdpath = [ + "~/.dotfiles" + # "~/Documents/GitHub" + ]; + defaultKeymap = "emacs"; + dirHashes = { + dl = "$HOME/Downloads"; + gh = "$HOME/Documents/GitHub"; + }; + history = { + expireDuplicatesFirst = true; + path = "$HOME/.histfile"; + save = 10000; + size = 10000; + }; + historySubstringSearch.enable = true; + plugins = [ + { + name = "fzf-tab"; + src = pkgs.zsh-fzf-tab; + } + ]; + initExtra = '' + bindkey "^[[1;5D" backward-word + bindkey "^[[1;5C" forward-word + + my-backward-delete-word() { + # Copy the global WORDCHARS variable to a local variable. That way any + # modifications are scoped to this function only + local WORDCHARS=$WORDCHARS + # Use bash string manipulation to remove `:` so our delete will stop at it + WORDCHARS="''${WORDCHARS//:}" + # Use bash string manipulation to remove `/` so our delete will stop at it + WORDCHARS="''${WORDCHARS//\/}" + # Use bash string manipulation to remove `.` so our delete will stop at it + WORDCHARS="''${WORDCHARS//.}" + # zle will run an existing widget. + zle backward-delete-word + } + zle -N my-backward-delete-word + bindkey '^H' my-backward-delete-word + + # This will be our `ctrl+alt+w` command + my-backward-delete-whole-word() { + # Copy the global WORDCHARS variable to a local variable. That way any + # modifications are scoped to this function only + local WORDCHARS=$WORDCHARS + # Use bash string manipulation to add `:` to WORDCHARS if it's not present + # already. + [[ ! $WORDCHARS == *":"* ]] && WORDCHARS="$WORDCHARS"":" + # zle will run that widget. + zle backward-delete-word + } + # `zle -N` will create a new widget that we can use on the command line + zle -N my-backward-delete-whole-word + # bind this new widget to `ctrl+alt+w` + bindkey '^W' my-backward-delete-whole-word + + vterm_printf() { + if [ -n "$TMUX" ] && ([ "''${TERM%%-*}" = "tmux" ] || [ "''${TERM%%-*}" = "screen" ]); then + # Tell tmux to pass the escape sequences through + printf "\ePtmux;\e\e]%s\007\e\\" "$1" + elif [ "''${TERM%%-*}" = "screen" ]; then + # GNU screen (screen, screen-256color, screen-256color-bce) + printf "\eP\e]%s\007\e\\" "$1" + else + printf "\e]%s\e\\" "$1" + fi + } + vterm_prompt_end() { + vterm_printf "51;A$(whoami)@$(hostname):$(pwd)" + } + setopt PROMPT_SUBST + PROMPT=$PROMPT'%{$(vterm_prompt_end)%}' + + vterm_cmd() { + local vterm_elisp + vterm_elisp="" + while [ $# -gt 0 ]; do + vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")" + shift + done + vterm_printf "51;E$vterm_elisp" + } + + ''; }; - history = { - expireDuplicatesFirst = true; - path = "$HOME/.histfile"; - save = 10000; - size = 10000; - }; - historySubstringSearch.enable = true; - plugins = [ - { - name = "fzf-tab"; - src = pkgs.zsh-fzf-tab; - } - ]; - initExtra = '' - bindkey "^[[1;5D" backward-word - bindkey "^[[1;5C" forward-word - - my-backward-delete-word() { - # Copy the global WORDCHARS variable to a local variable. That way any - # modifications are scoped to this function only - local WORDCHARS=$WORDCHARS - # Use bash string manipulation to remove `:` so our delete will stop at it - WORDCHARS="''${WORDCHARS//:}" - # Use bash string manipulation to remove `/` so our delete will stop at it - WORDCHARS="''${WORDCHARS//\/}" - # Use bash string manipulation to remove `.` so our delete will stop at it - WORDCHARS="''${WORDCHARS//.}" - # zle will run an existing widget. - zle backward-delete-word - } - zle -N my-backward-delete-word - bindkey '^H' my-backward-delete-word - - # This will be our `ctrl+alt+w` command - my-backward-delete-whole-word() { - # Copy the global WORDCHARS variable to a local variable. That way any - # modifications are scoped to this function only - local WORDCHARS=$WORDCHARS - # Use bash string manipulation to add `:` to WORDCHARS if it's not present - # already. - [[ ! $WORDCHARS == *":"* ]] && WORDCHARS="$WORDCHARS"":" - # zle will run that widget. - zle backward-delete-word - } - # `zle -N` will create a new widget that we can use on the command line - zle -N my-backward-delete-whole-word - # bind this new widget to `ctrl+alt+w` - bindkey '^W' my-backward-delete-whole-word - - vterm_printf() { - if [ -n "$TMUX" ] && ([ "''${TERM%%-*}" = "tmux" ] || [ "''${TERM%%-*}" = "screen" ]); then - # Tell tmux to pass the escape sequences through - printf "\ePtmux;\e\e]%s\007\e\\" "$1" - elif [ "''${TERM%%-*}" = "screen" ]; then - # GNU screen (screen, screen-256color, screen-256color-bce) - printf "\eP\e]%s\007\e\\" "$1" - else - printf "\e]%s\e\\" "$1" - fi - } - vterm_prompt_end() { - vterm_printf "51;A$(whoami)@$(hostname):$(pwd)" - } - setopt PROMPT_SUBST - PROMPT=$PROMPT'%{$(vterm_prompt_end)%}' - - vterm_cmd() { - local vterm_elisp - vterm_elisp="" - while [ $# -gt 0 ]; do - vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")" - shift - done - vterm_printf "51;E$vterm_elisp" - } - - ''; - }; -} + } #+end_src **** zellij diff --git a/profiles/common/home/packages.nix b/profiles/common/home/packages.nix index 6946fb2..1bf1cc8 100644 --- a/profiles/common/home/packages.nix +++ b/profiles/common/home/packages.nix @@ -26,7 +26,6 @@ nmap lsof nvd - nh nix-output-monitor hyprpicker # color picker findutils diff --git a/profiles/common/home/zsh.nix b/profiles/common/home/zsh.nix index 7e342e0..62903cb 100644 --- a/profiles/common/home/zsh.nix +++ b/profiles/common/home/zsh.nix @@ -5,24 +5,24 @@ shellAliases = lib.recursiveUpdate { hg = "history | grep"; - hmswitch = "home-manager --flake ${config.swarselsystems.flakePath}#$(whoami)@$(hostname) switch"; - nswitch = "sudo nixos-rebuild --flake ${config.swarselsystems.flakePath}#$(hostname) switch"; - nboot = "sudo nixos-rebuild --flake ${config.swarselsystems.flakePath}#$(hostname) boot"; + hmswitch = "home-manager --flake ${config.swarselsystems.flakePath}#$(whoami)@$(hostname) switch |& nom"; + nswitch = "sudo nixos-rebuild --flake ${config.swarselsystems.flakePath}#$(hostname) --show-trace --log-format internal-json -v switch |& nom --json"; + nboot = "sudo nixos-rebuild --flake ${config.swarselsystems.flakePath}#$(hostname) --show-trace --log-format internal-json -v boot |& nom --json"; magit = "emacsclient -nc -e \"(magit-status)\""; config = "git --git-dir=$HOME/.cfg/ --work-tree=$HOME"; g = "git"; - c = "git --git-dir=$HOME/.dotfiles/.git --work-tree=$HOME/.dotfiles/"; + c = "git --git-dir=$FLAKE/.git --work-tree=$FLAKE/"; passpush = "cd ~/.local/share/password-store; git add .; git commit -m 'pass file changes'; git push; cd -;"; passpull = "cd ~/.local/share/password-store; git pull; cd -;"; hotspot = "nmcli connection up local; nmcli device wifi hotspot;"; cd = "z"; cd-orig = "cd"; cat-orig = "cat"; - cdr = "cd \"$( (find /home/swarsel/Documents/GitHub -maxdepth 1 && echo /home/swarsel/.dotfiles) | fzf )\""; + cdr = "cd \"$( (find $DOCUMENT_DIR_WORK $DOCUMENT_DIR_PRIV -maxdepth 1 && echo $FLAKE) | fzf )\""; nix-ldd = "LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH ldd"; fs-diff = "sudo mount -o subvol=/ /dev/mapper/cryptroot /mnt ; fs-diff"; - lt = "ls -lath"; - oldshell = "nix shell github:nixos/nixpkgs/\"$1\" \"$2\""; + lt = "eza -las modified --total-size"; + boot-diff = "nix store diff-closures /run/*-system"; } config.swarselsystems.shellAliases; autosuggestion.enable = true; diff --git a/profiles/common/nixos/nvd-rebuild.nix b/profiles/common/nixos/nvd-rebuild.nix index b6d9ba2..e8e0938 100644 --- a/profiles/common/nixos/nvd-rebuild.nix +++ b/profiles/common/nixos/nvd-rebuild.nix @@ -3,7 +3,7 @@ system.activationScripts.diff = { supportsDryActivation = true; text = '' - ${pkgs.nvd}/bin/nvd --nix-bin-dir=${pkgs.nix}/bin diff \ + ${pkgs.nvd}/bin/nvd --color=always --nix-bin-dir=${pkgs.nix}/bin diff \ /run/current-system "$systemConfig" ''; };