From 8248b8c65801e684c2860ff4c0366c104d926e8e Mon Sep 17 00:00:00 2001 From: jiriks74 Date: Fri, 18 Oct 2024 14:14:58 +0200 Subject: [PATCH] feat(nix): Convert to a flake --- README.md | 73 ++++++++++++++++- flake.lock | 78 ++++++++++++++++++ flake.nix | 232 +++++++++++++++++++++++++++++++++++++++++++++++++++++ zsh.nix | 202 ---------------------------------------------- 4 files changed, 382 insertions(+), 203 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100755 zsh.nix diff --git a/README.md b/README.md index 6bae206..7759247 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,74 @@ # zsh-nix -My home-manager zsh config \ No newline at end of file +A [`home-manager`]() flake containing my [`zsh`]() config. + +## Usage + +```nix +{ + # Add this flake to your inputs + inputs = { + zsh-config.url = "/home/jirka/Projects/zsh-nix/"; + ... + } +... + outputs = { + self, + nixpkgs, + home-manager, + zsh-config, # Don't forget to import it + ... + } + ... +# Then add it to your homeConfigurations + homeConfigurations = { + "user@hostname" = home-manager.lib.homeManagerConfiguration { + pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance + extraSpecialArgs = {inherit inputs outputs;}; + modules = [ + ... + zsh-config.home-managerModule + ... + ]; + }; +``` + +# ZSH Configuration Flake + +This flake provides a ZSH configuration with various plugins, +syntax highlighting, enhanced file handling, etc. + +## Overview + +### Notable plugins + +- **`zsh-autosuggestions`**: Provides suggestions as you type based on your command history. +- **`zsh-you-should-use`**: Reminds you to use aliases for commands you frequently type. + It helps you streamline your workflow. +- **`ssh-connect`**: A utility for managing SSH connections and quickly switching between them. +- **`enhancd`**: Improves directory navigation with fuzzy search, similar to `zsh-z`. +- **`zsh-completions`**: Adds missing completions for various tools. +- **`powerlevel10k`**: A highly customizable ZSH theme that gives you a clean + and modern look with useful information in your prompt. +- **`git` plugin**: Provides consistent, intuitive aliases +and extra functions for common Git commands, improving workflow efficiency. + +### Packages + +This flake includes some useful packages: + +- **`nix-zsh-completions`**: ZSH completions for Nix, NixOS, and NixOps. +- **`asciinema`**: Terminal recording tool. + - **`libnotify`**: Provides notifications for terminal events. + - **`websocat`**: Used for streaming asciinema recordings in v2 format. +- **`tldr`**: Community-driven simplified man pages for faster reference. +- **`lsd`**: A next-generation `ls` command with improved features. +- **`bat`**: A `cat` clone with syntax highlighting and Git integration. +- **`eza`**: A modern, maintained replacement for `ls`. +- **`trash-cli`**: Command line interface to the Freedesktop.org trashcan. + +### Other + +- **`ex`**: A shell function to extract various archive formats. + - Supported formats include `.tar.bz2`, `.zip`, `.rar`, `.gz`, and more. + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a538cd2 --- /dev/null +++ b/flake.lock @@ -0,0 +1,78 @@ +{ + "nodes": { + "fast-syntax-highlighting": { + "flake": false, + "locked": { + "lastModified": 1702802089, + "narHash": "sha256-AEeGEx2vyyHVS92Nla7XoqSx3rTpQHYwPMrK1jFH1Mg=", + "owner": "z-shell", + "repo": "F-Sy-H", + "rev": "3dea11a9018061e6e3a77e529b79e5654679d3a0", + "type": "github" + }, + "original": { + "owner": "z-shell", + "repo": "F-Sy-H", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1728888510, + "narHash": "sha256-nsNdSldaAyu6PE3YUA+YQLqUDJh+gRbBooMMekZJwvI=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fast-syntax-highlighting": "fast-syntax-highlighting", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9bfe026 --- /dev/null +++ b/flake.nix @@ -0,0 +1,232 @@ +{ + description = "jiriks74's ZSH configuration"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + ... + } @ inputs: + { + home-managerModule = { config, lib, pkgs, ... }: { + home.packages = with pkgs;[ + nix-zsh-completions + + asciinema # Terminal recording + libnotify # Notifications + websocat # For asciinema v2 streams + + tldr + lsd + bat + eza + trash-cli + fzf # enhancd + fd # enhancd + # rofi # for fd + gnutar # ex + bzip3 # ex + unzip # ex + p7zip # ex + unrar # ex + gzip # ex + ]; + + programs = { + # nix-index = { + # enable = true; + # enableZshIntegration = true; + # }; + # thefuck = { + # enable = true; + # enableZshIntegration = true; + # }; + direnv = { + enable = true; + enableZshIntegration = true; + nix-direnv.enable = true; + }; + + zsh = { + enable = true; + enableCompletion = true; + zplug = { + enable = true; + plugins = [ + { name = "romkatv/powerlevel10k"; tags = [ "as:theme" "depth:1" ]; } # Installations with additional options. For the list of options, please refer to Zplug README. + { name = "z-shell/F-Sy-H"; } # Feature-rich Syntax Highlighting for Zsh + # { name = "zsh-users/zsh-syntax-highlighting"; } + { name = "zsh-users/zsh-completions"; } # Adds some missing completions to zsh + { name = "zsh-users/zsh-autosuggestions"; } # Simple plugin installation + { name = "MichaelAquilina/zsh-you-should-use"; } # Did you forget to use an alias? + { name = "davidde/git"; } # Aliases for git + { name = "babarot/enhancd"; tags = [ "use:init.sh" ]; } # Includes simmilar functionality to zsh-z + { name = "supercrabtree/k"; } # Directory listings for Zsh with git features. + { name = "plugins/command-not-found"; tags = [ "from:oh-my-zsh" ]; } + { name = "gko/ssh-connect"; tags = [ "use:ssh-connect.sh" ]; } # List of most used ssh connections + { name = "agkozak/zsh-z"; } # Jump arount your filesystem with ease + { name = "sineto/web-search"; } + { name = "zsh-users/zaw"; } # Desctiptions for command outputs (afaik)zplug "plugins/git", from:oh-my-zsh + # { name = "plugins/dirhistory"; tags = [ "from:oh-my-zsh" ]; } + ]; + }; + + initExtraFirst = '' + if [[ "''${ZSH_PROFILE}" -eq 1 ]]; then + zmodload zsh/zprof # Profiling. Enable `zprof` at the end of initExtra too. + else + # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. + # Initialization code that may require console input (password prompts, [y/n] + # confirmations, etc.) must go above this block; everything else may go below. + if [[ -r "''${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-''${(%):-%n}.zsh" ]]; then + source "''${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-''${(%):-%n}.zsh" + fi + fi + ''; + + initExtra = '' + # Remove nix from path if we are in a container (distrobox) + if [ -v DISTROBOX_ENTER_PATH ]; then + export PATH=$(echo $PATH | tr ':' '\n' | grep -vE '/nix/|/run/wrappers|\.nix-profile|/etc/profiles/per-user/jirka/bin|/run/current-system/sw/bin' | tr '\n' ':') + export PATH=$(echo $PATH | sed 's/:$//') + fi + + # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. + [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh + + export YSU_MESSAGE_POSITION="after" # you-should-use plugin + export ASCIINEMA_API_URL=https://asciinema.stefka.eu + if [ -v ASCIINEMA_REC ]; then + _zsh_autosuggest_disable + fi + + # Basic auto/tab complete: + autoload -U compinit + zstyle ':completion:*' menu select + zmodload zsh/complist + compinit + _comp_options+=(globdots) # Include hidden files. + + # Custom ZSH Binds + bindkey '^ ' autosuggest-accept + bindkey "^[[H" beginning-of-line + bindkey "^[[F" end-of-line + bindkey "^[[1;5C" forward-word + bindkey "^[[1;5D" backward-word + bindkey "^[[3~" delete-char + + # Extracting + ex () + { + if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xjf $1 ;; + *.tar.gz) tar xzf $1 ;; + *.tar.xz) tar xJf $1 ;; + *.bz2) bunzip3 $1 ;; + *.rar) unrar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xf $1 ;; + *.tbz2) tar xjf $1 ;; + *.tgz) tar xzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1;; + *.7z) 7z x $1 ;; + *) echo "'$1' cannot be extracted via ex()" ;; + esac + else + echo "'$1' is not a valid file" + fi + } + + # Kitty binds + if [ "$TERM" = "xterm-kitty" ]; then + alias ssh="kitty +kitten ssh" + alias icat="kitty +kitten icat" + alias d="kitty +kitten diff" + alias get="kitty +kitten transfer" + alias put="kitty +kitten transfer --direction=upload" + alias kclip="kitty +kitten clipboard" + fi + + # Special aliases that may not work with Nix config + # Command line head / tail shortcuts + alias H="| head"; + alias T="| tail"; + alias G="| grep"; + alias L="| less"; + alias M="| most"; + alias LL="2>&1 | less"; + alias CA="2>&1 | cat -A"; + alias NE="2> /dev/null"; + alias NUL="> /dev/null 2>&1"; + alias P="2>&1| pygmentize -l pytb"; + if [[ "''${ZSH_PROFILE}" -eq 1 ]]; then + zprof + fi + ''; + + shellAliases = { + cat = "${pkgs.bat}/bin/bat -p"; + # update = "sudo nixos-rebuild switch"; + + ls="lsd"; + # ls, the common ones I use a lot shortened for rapid fire usage + l="ls -lFh"; #size,show type,human readable + la="ls -lAFh"; #long list,show almost all,show type,human readable + lr="ls -tRFh"; #sorted by date,recursive,show type,human readable + lt="ls -ltFh"; #long list,sorted by date,show type,human readable + ll="ls -l"; #long list + ldot="ls -ld .*"; + lS="ls -1FSsh"; + lart="ls -1Fcart"; + lrt="ls -1Fcrt"; + + grep="grep --color"; + sgrep="grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS} "; + + t="tail -f"; + + dud="du -d 1 -h"; + duf="du -sh *"; + # fd="find . -type d -name"; + ff="find . -type f -name"; + + h="history"; + hgrep="fc -El 0 | grep"; + help="man"; + p="ps -f"; + sortnr="sort -n -r"; + unexport="unset"; + + # Use trash instead of rm if available + rm="trash"; + cp="cp -i"; + mv="mv -i"; + + cls="clear"; + + sshc="ssh-connect"; + }; + + history = { + # ignoreAllDups = true; + path = "${config.xdg.cacheHome}/zhistory"; + save = 10000; + size = 10000; + # share = true; + }; + }; + }; + + home.file = { + # ".zprofile".source = ./zprofile; + }; + }; + }; +} diff --git a/zsh.nix b/zsh.nix deleted file mode 100755 index 9664190..0000000 --- a/zsh.nix +++ /dev/null @@ -1,202 +0,0 @@ -{ config, pkgs, lib, ... }: -{ - programs.thefuck = { - enable = true; - enableZshIntegration = true; - }; - - programs.direnv = { - enable = true; - enableZshIntegration = true; # see note on other shells below - nix-direnv.enable = true; - }; - programs.zsh = { - enable = true; - - zplug = { - enable = true; - plugins = [ - { name = "zsh-users/zsh-autosuggestions"; } # Simple plugin installation - { name = "romkatv/powerlevel10k"; tags = [ as:theme depth:1 ]; } # Installations with additional options. For the list of options, please refer to Zplug README. - { name = "zsh-users/zsh-syntax-highlighting"; } - { name = "MichaelAquilina/zsh-you-should-use"; } # Did you forget to use an alias? - { name = "gko/ssh-connect"; tags = [ use:ssh-connect.sh ]; } # List of most used ssh connections - { name = "sineto/web-search"; } - { name = "plugins/dirhistory"; tags = [ from:oh-my-zsh ]; } - { name = "plugins/command-not-found"; tags = [ from:oh-my-zsh ]; } - { name = "davidde/git"; } # Aliases for git - { name = "agkozak/zsh-z"; } # Jump arount your filesystem with ease - { name = "babarot/enhancd"; tags = [ use:init.sh ]; } # Includes simmilar functionality to zsh-z - { name = "zsh-users/zsh-completions"; } # Adds some missing completions to zsh - { name = "zsh-users/zaw"; } # Desctiptions for command outputs (afaik)zplug "plugins/git", from:oh-my-zsh - { name = "supercrabtree/k"; } # Directory listings for Zsh with git features. - ]; - }; - - initExtra = '' - # Remove nix from path if we are in a container (distrobox) - if [ -v DISTROBOX_ENTER_PATH ]; then - export PATH=$(echo $PATH | tr ':' '\n' | grep -vE '/nix/|/run/wrappers|\.nix-profile|/etc/profiles/per-user/jirka/bin|/run/current-system/sw/bin' | tr '\n' ':') - export PATH=$(echo $PATH | sed 's/:$//') - fi - - # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. - [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh - # case $(tty) in - # (/dev/tty[1-9]) PS1='console version';; - # (*) PS1='not console version';; - # esac - - # if [[ -n $DISPLAY != "" ]]; then - # if (( $\{+DISPLAY} )); then - # [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh - # else - # # [[ ! -f ~/.p10k-tty.zsh ]] || source ~/.p10k-tty.zsh - # source ~/.p10k-tty.zsh - # fi - - export YSU_MESSAGE_POSITION="after" - - eval $(thefuck --alias) - export ASCIINEMA_API_URL=https://asciinema.stefka.eu - if [ -v ASCIINEMA_REC ]; then - _zsh_autosuggest_disable - fi - export YSU_MESSAGE_POSITION="after" # you-should-use plugin - - # Basic auto/tab complete: - autoload -U compinit - zstyle ':completion:*' menu select - zmodload zsh/complist - compinit - _comp_options+=(globdots) # Include hidden files. - - # Custom ZSH Binds - bindkey '^ ' autosuggest-accept - bindkey "^[[H" beginning-of-line - bindkey "^[[F" end-of-line - bindkey "^[[1;5C" forward-word - bindkey "^[[1;5D" backward-word - bindkey "^[[3~" delete-char - - # Extracting - ex () - { - if [ -f $1 ] ; then - case $1 in - *.tar.bz2) tar xjf $1 ;; - *.tar.gz) tar xzf $1 ;; - *.tar.xz) tar xJf $1 ;; - *.bz2) bunzip2 $1 ;; - *.rar) unrar x $1 ;; - *.gz) gunzip $1 ;; - *.tar) tar xf $1 ;; - *.tbz2) tar xjf $1 ;; - *.tgz) tar xzf $1 ;; - *.zip) unzip $1 ;; - *.Z) uncompress $1;; - *.7z) 7z x $1 ;; - *) echo "'$1' cannot be extracted via ex()" ;; - esac - else - echo "'$1' is not a valid file" - fi - } - - # Kitty binds - if [ "$TERM" = "xterm-kitty" ]; then - alias ssh="kitty +kitten ssh" - alias icat="kitty +kitten icat" - alias d="kitty +kitten diff" - alias get="kitty +kitten transfer" - alias put="kitty +kitten transfer --direction=upload" - alias kclip="kitty +kitten clipboard" - fi - - # Special aliases that may not work with Nix config - # Command line head / tail shortcuts - alias H="| head"; - alias T="| tail"; - alias G="| grep"; - alias L="| less"; - alias M="| most"; - alias LL="2>&1 | less"; - alias CA="2>&1 | cat -A"; - alias NE="2> /dev/null"; - alias NUL="> /dev/null 2>&1"; - alias P="2>&1| pygmentize -l pytb"; - ''; - - shellAliases = { - update = "sudo nixos-rebuild switch"; - - ls="lsd"; - # ls, the common ones I use a lot shortened for rapid fire usage - l="ls -lFh"; #size,show type,human readable - la="ls -lAFh"; #long list,show almost all,show type,human readable - lr="ls -tRFh"; #sorted by date,recursive,show type,human readable - lt="ls -ltFh"; #long list,sorted by date,show type,human readable - ll="ls -l"; #long list - ldot="ls -ld .*"; - lS="ls -1FSsh"; - lart="ls -1Fcart"; - lrt="ls -1Fcrt"; - - grep="grep --color"; - sgrep="grep -R -n -H -C 5 --exclude-dir={.git,.svn,CVS} "; - - t="tail -f"; - - dud="du -d 1 -h"; - duf="du -sh *"; - # fd="find . -type d -name"; - ff="find . -type f -name"; - - h="history"; - hgrep="fc -El 0 | grep"; - help="man"; - p="ps -f"; - sortnr="sort -n -r"; - unexport="unset"; - - # Use trash instead of rm if available - rm="trash"; - cp="cp -i"; - mv="mv -i"; - - cls="clear"; - - sshc="ssh-connect"; - }; - - history = { - # ignoreAllDups = true; - path = "${config.xdg.cacheHome}/zhistory"; - save = 10000; - size = 10000; - # share = true; - }; - - # histSize = 10000; - # histFile = "${config.xdg.cacheHome}/zhistory"; - }; - - home.packages = with pkgs; [ - asciinema # Terminal recording - libnotify # Notifications - websocat # For asciinema v2 streams - - tldr - lsd - eza - trash-cli - fzf # enhancd - fd # enhancd - # rofi # for fd - gnutar # ex - bzip2 # ex - unzip # ex - p7zip # ex - gzip # ex - ]; -}