diff options
Diffstat (limited to 'nix-conf/home/includes')
-rw-r--r-- | nix-conf/home/includes/clojure.nix | 33 | ||||
-rw-r--r-- | nix-conf/home/includes/common.nix | 218 | ||||
-rw-r--r-- | nix-conf/home/includes/darwin.nix | 111 | ||||
-rw-r--r-- | nix-conf/home/includes/dev-common.nix | 71 | ||||
-rw-r--r-- | nix-conf/home/includes/irssi.nix | 18 | ||||
-rw-r--r-- | nix-conf/home/includes/linux-dev.nix | 19 | ||||
-rw-r--r-- | nix-conf/home/includes/linux-server.nix | 10 | ||||
-rw-r--r-- | nix-conf/home/includes/scripts/hm-changes-report.nix | 3 | ||||
-rw-r--r-- | nix-conf/home/includes/scripts/system-changes-report.nix | 1 | ||||
-rw-r--r-- | nix-conf/home/includes/secrets.yaml | 21 | ||||
-rw-r--r-- | nix-conf/home/includes/zsh.nix | 418 |
11 files changed, 619 insertions, 304 deletions
diff --git a/nix-conf/home/includes/clojure.nix b/nix-conf/home/includes/clojure.nix index 3681e8b..3915ab3 100644 --- a/nix-conf/home/includes/clojure.nix +++ b/nix-conf/home/includes/clojure.nix @@ -1,18 +1,25 @@ -{ config, pkgs, lib, isDarwin, isLinux, ... }: +{ + config, + pkgs, + lib, + ... +}: let inherit (lib) optionals; in { - home.packages = with pkgs; [ - babashka - clj-kondo - clojure - clojure-lsp - jet - maven - neil - ] - ++ optionals stdenv.isDarwin [ (leiningen.override { jdk = jdk8; }) ] - ++ optionals stdenv.isLinux [ leiningen ]; + home.packages = + with pkgs; + [ + babashka + clj-kondo + clojure-lsp + emacs-lsp-booster + jet + maven + neil + ] + # TODO these are here because of the custom versions in otm.nix + # but there should be a better way + ++ optionals stdenv.isLinux [ leiningen clojure ]; } - diff --git a/nix-conf/home/includes/common.nix b/nix-conf/home/includes/common.nix index f43168a..7f88087 100644 --- a/nix-conf/home/includes/common.nix +++ b/nix-conf/home/includes/common.nix @@ -1,14 +1,47 @@ -{ config, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let hcr = pkgs.callPackage ./scripts/hm-changes-report.nix { inherit config pkgs; }; scr = pkgs.callPackage ./scripts/system-changes-report.nix { inherit config pkgs; }; - email = builtins.readFile "${config.home.homeDirectory}/email.txt"; + unstable = import <unstable> { }; in { imports = [ ./zsh.nix + <sops-nix/modules/home-manager/sops.nix> ]; + nixpkgs.config.allowUnfreePredicate = + pkg: builtins.elem (lib.getName pkg) [ "aspell-dict-en-science" ]; + + nix = { + package = pkgs.nix; + settings = { + extra-experimental-features = [ + "nix-command" + "flakes" + ]; + }; + }; + + sops = { + age.keyFile = "${config.xdg.configHome}/sops/age/keys.txt"; + defaultSopsFile = builtins.path { + path = ./secrets.yaml; + name = "home-secrets.yaml"; + }; + secrets."ssh_config/oci" = { }; + secrets."git_email_config/default" = { }; + }; + + home.sessionVariables = { + LSP_USE_PLISTS = "true"; + }; + home.packages = with pkgs; [ hcr scr @@ -17,14 +50,10 @@ in aspellDicts.en aspellDicts.en-computers aspellDicts.en-science - bat - bat-extras.batdiff - bat-extras.batgrep - bat-extras.batman - bat-extras.batwatch - bat-extras.batpipe + bandwhich bottom broot + comma curl diff-so-fancy difftastic @@ -33,7 +62,6 @@ in ea elinks entr - eza fd file fzf @@ -44,37 +72,83 @@ in inetutils ispell isync + jd-diff-patch jq libqalculate lscolors - lsd lynx mercurial - nixfmt-classic nix-info nix-prefetch-git nix-prefetch-github + nix-search nixpkgs-review nvd pass + procs + pstree + rage ripgrep rlwrap sd + shfmt + sops + ssh-to-age tealdeer tre-command + tree ugrep uni + unzip w3m + xan + yq + zip zstd + + unstable.nixfmt-rfc-style + unstable.wcurl ]; - nix = { - package = pkgs.nix; - settings = { - extra-experimental-features = [ "nix-command" "flakes" ]; + programs.bat = { + enable = true; + extraPackages = with pkgs.bat-extras; [ + batdiff + batgrep + batman + batwatch + batpipe + ]; + config = { + style = "full"; + pager = "less -RXF"; + map-syntax = [ + ".ignore:Git Ignore" + "*.jenkinsfile:Groovy" + ]; }; }; + programs.eza = { + enable = true; + git = true; + icons = "auto"; + enableBashIntegration = false; + enableZshIntegration = false; + enableFishIntegration = false; + enableIonIntegration = false; + extraOptions = [ + "--colour=auto" + "--long" + "--group-directories-first" + "--classify" + "--no-user" + "--no-time" + "--no-filesize" + "--no-permissions" + ]; + }; + programs.gpg.enable = true; programs.nix-index = { enable = true; @@ -94,20 +168,29 @@ in set pastetoggle=<F2> nmap <silent> <F3> :silent nohlsearch<CR> imap <silent> <F3> <C-o>:silent nohlsearch<CR> + nmap <silent> <F4> :silent setlocal spell spelllang=en_gb<CR> + imap <silent> <F4> <C-o>:silent setlocal spell spelllang=en_gb<CR> + nmap <silent> <F5> :silent setlocal nospell<CR> + imap <silent> <F5> <C-o>:silent setlocal nospell<CR> + nmap <silent> <F6> :silent set diffopt+=iwhite<CR> + imap <silent> <F6> <C-o>:silent set diffopt+=iwhite<CR> + nmap <silent> <F7> :silent set diffopt-=iwhite<CR> + imap <silent> <F7> <C-o>:silent set diffopt-=iwhite<CR> ''; - plugins = [ pkgs.vimPlugins.sensible - pkgs.vimPlugins.auto-pairs - pkgs.vimPlugins.ctrlp - pkgs.vimPlugins.editorconfig-vim - pkgs.vimPlugins.inkpot - pkgs.vimPlugins.molokai - pkgs.vimPlugins.surround - pkgs.vimPlugins.vim-lastplace - pkgs.vimPlugins.vim-nix - pkgs.vimPlugins.vim-pasta - pkgs.vimPlugins.vim-repeat - pkgs.vimPlugins.vim-sexp-mappings-for-regular-people - pkgs.vimPlugins.vim-sleuth + plugins = [ + pkgs.vimPlugins.sensible + pkgs.vimPlugins.auto-pairs + pkgs.vimPlugins.ctrlp + pkgs.vimPlugins.editorconfig-vim + pkgs.vimPlugins.inkpot + pkgs.vimPlugins.molokai + pkgs.vimPlugins.surround + pkgs.vimPlugins.vim-lastplace + pkgs.vimPlugins.vim-nix + pkgs.vimPlugins.vim-pasta + pkgs.vimPlugins.vim-repeat + pkgs.vimPlugins.vim-sexp-mappings-for-regular-people + pkgs.vimPlugins.vim-sleuth ]; settings = { background = "dark"; @@ -130,17 +213,19 @@ in UseKeychain yes User djm ''; - includes = [ "~/.ssh/config_local" ]; + includes = [ + "~/.ssh/config_local" + config.sops.secrets."ssh_config/oci".path + ]; matchBlocks = { "djm.ovh" = { hostname = "v.djm.ovh"; port = 2222; - dynamicForwards = [ { port = 8889; } ]; }; "devio" = { - hostname = "devio.us"; - user = "deejayem"; - port = 2222; + hostname = "devio.us"; + user = "deejayem"; + port = 2222; }; "sdf" = { hostname = "sdf.org"; @@ -155,18 +240,12 @@ in user = "deejayem"; }; "blinkenshell" = { - hostname = "ssh.blinkenshell.org"; - port = 2222; + hostname = "ssh.blinkenshell.org"; + port = 2222; }; "hashbang" = { hostname = "de1.hashbang.sh"; }; - "o1" = { - hostname = "130.162.163.108"; - }; - "o2" = { - hostname = "143.47.239.39"; - }; "tilde.institute" = { hostname = "tilde.institute"; }; @@ -182,13 +261,29 @@ in identityFile = "~/.ssh/id_ed25519"; identitiesOnly = true; }; + "hb-backup" = { + hostname = "de1.hashbang.sh"; + identityFile = "~/.ssh/hb_backup_key"; + identitiesOnly = true; + }; + "bs-backup" = { + hostname = "ssh.blinkenshell.org"; + port = 2222; + identityFile = "~/.ssh/bs_backup_key"; + identitiesOnly = true; + }; + "tt-backup" = { + hostname = "tilde.team"; + identityFile = "~/.ssh/tt_backup_key"; + identitiesOnly = true; + }; }; }; programs.git = { enable = true; userName = "David Morgan"; - userEmail = email; + includes = [ { path = config.sops.secrets."git_email_config/default".path; } ]; aliases = { # difftastic logt = "!sh -c 'GIT_EXTERNAL_DIFF=\"difft --background=dark\" git log -p --ext-diff'"; @@ -203,9 +298,9 @@ in cshow = "!git -c delta.line-numbers=false show"; cdiff = "!git -c delta.line-numbers=false diff"; # diff-so-fancy - flog = "!git -c core.pager=\"diff-so-fancy | less\" log"; # usually used with -p - fshow = "!git -c core.pager=\"diff-so-fancy | less\" show"; - fdiff = "!git -c core.pager=\"diff-so-fancy | less\" diff"; + flog = ''!git -c core.pager="diff-so-fancy | less" log''; # usually used with -p + fshow = ''!git -c core.pager="diff-so-fancy | less" show''; + fdiff = ''!git -c core.pager="diff-so-fancy | less" diff''; upstream = "!git push -u origin HEAD"; update-master = "!git fetch origin master:master"; @@ -220,13 +315,20 @@ in diff = { tool = "difftastic"; colorMoved = "default"; - elisp = { xfuncname = "^\\((((def\\S+)|use-package)\\s+\\S+)"; }; - clojure = { xfuncname = "^\\((def\\S+\\s+\\S+)"; }; + elisp = { + xfuncname = "^\\((((def\\S+)|use-package)\\s+\\S+)"; + }; + clojure = { + xfuncname = "^\\((def\\S+\\s+\\S+)"; + }; }; difftool = { prompt = false; - difftastic = { cmd = ''difft "$LOCAL" "$REMOTE"''; }; + difftastic = { + cmd = ''difft "$LOCAL" "$REMOTE"''; + }; }; + merge.conflictstyle = "diff3"; pull = { ff = "only"; rebase = false; @@ -261,5 +363,23 @@ in signByDefault = true; }; }; -} + programs.lsd = { + enable = true; + enableZshIntegration = false; # don't set aliases + settings = { + indicators = true; + #layout = "oneline"; + sorting.dir-grouping = "first"; + blocks = [ + "git" + "permission" + "user" + "group" + "size" + "date" + "name" + ]; + }; + }; +} diff --git a/nix-conf/home/includes/darwin.nix b/nix-conf/home/includes/darwin.nix index 3d81678..e85f3f9 100644 --- a/nix-conf/home/includes/darwin.nix +++ b/nix-conf/home/includes/darwin.nix @@ -1,4 +1,9 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: with lib; let @@ -20,56 +25,120 @@ let makeWrapper ${pkgs.mopidy}/bin/mopidy $out/bin/mopidy \ --prefix PYTHONPATH : $out/${pkgs.mopidyPackages.python.sitePackages} ''; - }; + }; + + # https://github.com/NixOS/nixpkgs/issues/395169 + patched-pkgs = pkgs.extend ( + _final: prev: { + ld64 = prev.ld64.overrideAttrs (old: { + patches = old.patches ++ [ ./Dedupe-RPATH-entries.patch ]; + }); + libuv = prev.libuv.overrideAttrs (old: { + doCheck = false; + }); + dbus = prev.dbus.overrideAttrs (old: { + doCheck = false; + }); + python313 = prev.python313.override { + packageOverrides = self: super: { + execnet = super.execnet.overridePythonAttrs (old: { + doCheck = false; + }); + pytest-xdist = super.pytest-xdist.overridePythonAttrs (old: { + doCheck = false; + }); + requests = super.requests.overridePythonAttrs (old: { + doCheck = false; + }); + sphinx = super.sphinx.overridePythonAttrs (old: { + doCheck = false; + }); + }; + }; + } + ); + + # Use the patches from emacs-plus + emacs-plus = (patched-pkgs.emacs30-pgtk.overrideAttrs (old: { + patches = + (old.patches or []) + ++ [ + (pkgs.fetchpatch { + url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-30/fix-window-role.patch"; + sha256 = "0c41rgpi19vr9ai740g09lka3nkjk48ppqyqdnncjrkfgvm2710z"; + }) + (pkgs.fetchpatch { + url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-30/round-undecorated-frame.patch"; + sha256 = "uYIxNTyfbprx5mCqMNFVrBcLeo+8e21qmBE3lpcnd+4="; + }) + (pkgs.fetchpatch { + url = "https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-30/system-appearance.patch"; + sha256 = "3QLq91AQ6E921/W9nfDjdOUWR8YVsqBAT/W9c1woqAw="; + }) + ]; + })).override{ withNativeCompilation = true; }; + + emacs-plus-with-packages = (pkgs.emacsPackagesFor emacs-plus).emacsWithPackages (ps: [ + ps.vterm + ps.multi-vterm + ]); + in { - imports = [ - ./dev-common.nix - ]; + imports = [ ./dev-common.nix ]; home.packages = with pkgs; [ awscli2 cacert + caddy coreutils curl diffutils - ((emacsPackagesFor emacs29-macport).emacsWithPackages(ps: [ ps.vterm ps.multi-vterm ])) + emacs-plus-with-packages findutils gh gh-dash #gnused - mopidy-with-extensions - mpdscribble - mpc-cli - mpd - mpv - ncmpcpp + #mopidy-with-extensions + #mpdscribble + #mpc-cli + #mpd + #ncmpcpp nix # on darwin we are not using nixos (duh) nodejs - nodePackages.eslint - openvpn pam-reattach pinentry_mac pgcli pgformatter - pms + #pms + poetry postgresql podman #python310Packages.sqlparse + redis sqls - vimpc + #vimpc wget ]; + nixpkgs.config.permittedInsecurePackages = [ + "emacs-mac-macport-29.1" + "emacs-mac-macport-with-packages-29.1" + ]; + nix.settings = { sandbox = true; keep-outputs = true; keep-derivations = true; }; - programs.java = { - enable = true; - #package = (pkgs.jdk8.overrideAttrs (_: { postPatch = "ln -nsf ../zulu-8.jdk/Contents/Home/man man"; })); - }; -} + programs.bat.extraPackages = with pkgs.bat-extras; [ + (prettybat.override { + withClangTools = false; + withRustFmt = false; + }) + ]; + # TODO is this a good idea? + #programs.zsh.shellAliases = { emacs = "${emacs-plus-with-packages}/Applications/Emacs.app/Contents/MacOS/Emacs"; }; +} diff --git a/nix-conf/home/includes/dev-common.nix b/nix-conf/home/includes/dev-common.nix index a76eb72..92b286e 100644 --- a/nix-conf/home/includes/dev-common.nix +++ b/nix-conf/home/includes/dev-common.nix @@ -1,21 +1,33 @@ -{ config, pkgs, lib, ... }: { - + config, + pkgs, + lib, + ... +}: +let + inherit (lib) optionals; +in +{ imports = [ ./common.nix ./clojure.nix ]; - home.packages = with pkgs; [ - docker - docker-compose - docker-credential-helpers - ffmpeg - gopass-jsonapi - mpv - multimarkdown - neovim - ]; + home.packages = + with pkgs; + [ + docker + docker-compose + docker-credential-helpers + gopass-jsonapi + multimarkdown + neovim + ripgrep-all + ] + ++ optionals (!stdenv.isDarwin) [ + ffmpeg + mpv + ]; programs.tmux = { enable = true; @@ -47,28 +59,27 @@ } ]; extraConfig = '' - unbind-key R - bind-key R run-shell ' \ - tmux source-file ~/.config/tmux/tmux.conf > /dev/null; \ - tmux display-message "Sourced .config/tmux/tmux.conf!"' + unbind-key R + bind-key R run-shell ' \ + tmux source-file ~/.config/tmux/tmux.conf > /dev/null; \ + tmux display-message "Sourced .config/tmux/tmux.conf!"' - bind-key £ split-window -h + bind-key £ split-window -h - set-option -g status-bg '#666666' - set-option -g status-fg '#aaaaaa' - set-option -g status-left-length 50 - set-option -g status-right " %a, %b %d - %H:%M " + set-option -g status-bg '#666666' + set-option -g status-fg '#aaaaaa' + set-option -g status-left-length 50 + set-option -g status-right " %a, %b %d - %H:%M " - ${lib.optionalString pkgs.stdenv.isLinux '' - bind-key -T copy-mode y send-keys -X copy-pipe-and-cancel "xsel -i -p && xsel -o -p | xsel -i -b" - bind-key C-y run "xsel -o | tmux load-buffer - ; tmux paste-buffer" - ''} - ${lib.optionalString pkgs.stdenv.isDarwin '' - bind-key -T copy-mode y send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy" - bind-key C-y run "reattach-to-user-namespace pbpaste | tmux load-buffer - ; tmux paste-buffer" - ''} + ${lib.optionalString pkgs.stdenv.isLinux '' + bind-key -T copy-mode y send-keys -X copy-pipe-and-cancel "xsel -i -p && xsel -o -p | xsel -i -b" + bind-key C-y run "xsel -o | tmux load-buffer - ; tmux paste-buffer" + ''} + ${lib.optionalString pkgs.stdenv.isDarwin '' + bind-key -T copy-mode y send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy" + bind-key C-y run "reattach-to-user-namespace pbpaste | tmux load-buffer - ; tmux paste-buffer" + ''} ''; }; } - diff --git a/nix-conf/home/includes/irssi.nix b/nix-conf/home/includes/irssi.nix index e7cd92c..54bdc9b 100644 --- a/nix-conf/home/includes/irssi.nix +++ b/nix-conf/home/includes/irssi.nix @@ -1,4 +1,9 @@ -{ config, pkgs, lib, ... }: +{ + config, + pkgs, + lib, + ... +}: { programs.irssi = { @@ -41,7 +46,7 @@ extraConfig = '' settings = { core = { - real_name = "David Morgan"; + real_name = "djm"; user_name = "djm"; nick = "djm"; timestamp_format = "%H:%M:%S"; @@ -85,6 +90,7 @@ 11 = { items = ( { type = "CHANNEL"; chat_type = "IRC"; name = "#!"; tag = "hashbang"; }); }; 12 = { items = ( { type = "CHANNEL"; chat_type = "IRC"; name = "#nixos"; tag = "libera"; }); }; 13 = { items = ( { type = "CHANNEL"; chat_type = "IRC"; name = "#home-manager"; tag = "oftc"; }); }; + 14 = { items = ( { type = "CHANNEL"; chat_type = "IRC"; name = "#blinkenshell.log"; tag = "blinkenirc"; }); }; }; ''; networks = { @@ -123,7 +129,6 @@ }; channels = { ctrl-c.autoJoin = true; - emacs.autoJoin = true; institute.autoJoin = true; meta.autoJoin = true; team.autoJoin = true; @@ -147,7 +152,11 @@ }; blinkenirc = { nick = "djm"; - autoCommands = [ "msg chanserv invite #blinkenshell.op" "wait 2000" ]; + autoCommands = [ + "msg chanserv invite #blinkenshell.op" + "msg chanserv invite #blinkenshell.log" + "wait 2000" + ]; saslExternal = true; server = { address = "irc.blinkenshell.org"; @@ -162,6 +171,7 @@ channels = { blinkenshell.autoJoin = true; "blinkenshell.op".autoJoin = true; + "blinkenshell.log".autoJoin = true; }; }; hashbang = { diff --git a/nix-conf/home/includes/linux-dev.nix b/nix-conf/home/includes/linux-dev.nix index cfd3760..473118e 100644 --- a/nix-conf/home/includes/linux-dev.nix +++ b/nix-conf/home/includes/linux-dev.nix @@ -1,23 +1,26 @@ { config, pkgs, ... }: { - imports = [ - ./dev-common.nix - ]; + imports = [ ./dev-common.nix ]; programs.emacs = { enable = true; - package = pkgs.emacs29; - extraPackages = (epkgs: [ epkgs.vterm epkgs.multi-vterm ] ); + extraPackages = ( + epkgs: [ + epkgs.vterm + epkgs.multi-vterm + ] + ); }; home.packages = with pkgs; [ + lame libtree - mpv + mp3cat mu pinentry protonvpn-cli - youtube-dl + sword + yt-dlp ]; } - diff --git a/nix-conf/home/includes/linux-server.nix b/nix-conf/home/includes/linux-server.nix index 12164b4..62233f0 100644 --- a/nix-conf/home/includes/linux-server.nix +++ b/nix-conf/home/includes/linux-server.nix @@ -1,22 +1,21 @@ { config, pkgs, ... }: { - imports = [ - ./common.nix - ]; + imports = [ ./common.nix ]; home.packages = with pkgs; [ emacs-nox irssi libtree msmtp - neomutt pinentry restic + sword + yt-dlp ]; services.gpg-agent = { enable = true; - pinentryPackage = pkgs.pinentry-curses; + pinentry.package = pkgs.pinentry-curses; defaultCacheTtl = 34560000; maxCacheTtl = 34560000; }; @@ -51,4 +50,3 @@ programs.vim.packageConfigurable = pkgs.vim; } - diff --git a/nix-conf/home/includes/scripts/hm-changes-report.nix b/nix-conf/home/includes/scripts/hm-changes-report.nix index 303d482..65e7fe8 100644 --- a/nix-conf/home/includes/scripts/hm-changes-report.nix +++ b/nix-conf/home/includes/scripts/hm-changes-report.nix @@ -2,7 +2,7 @@ # https://github.com/gvolpe/nix-config/blob/e28a220d0087064e6bad6b992b4914a65eb545e5/home/scripts/changes-report.nix let - hm-profiles = "/nix/var/nix/profiles/per-user/${config.home.username}/profile-*-link"; + hm-profiles = "${config.home.homeDirectory}/.local/state/nix/profiles/home-manager-*-link"; in pkgs.writeShellScriptBin "hm-changes-report" '' # Disable nvd if there are less than 2 hm profiles. @@ -12,4 +12,3 @@ pkgs.writeShellScriptBin "hm-changes-report" '' ${pkgs.nvd}/bin/nvd diff $(ls -d1v ${hm-profiles} | tail -2) fi '' - diff --git a/nix-conf/home/includes/scripts/system-changes-report.nix b/nix-conf/home/includes/scripts/system-changes-report.nix index 56166cb..b94498c 100644 --- a/nix-conf/home/includes/scripts/system-changes-report.nix +++ b/nix-conf/home/includes/scripts/system-changes-report.nix @@ -12,4 +12,3 @@ pkgs.writeShellScriptBin "system-changes-report" '' ${pkgs.nvd}/bin/nvd diff $(ls -d1v ${system-profiles} | tail -2) fi '' - diff --git a/nix-conf/home/includes/secrets.yaml b/nix-conf/home/includes/secrets.yaml new file mode 100644 index 0000000..2fc9d8c --- /dev/null +++ b/nix-conf/home/includes/secrets.yaml @@ -0,0 +1,21 @@ +ssh_config: + oci: ENC[AES256_GCM,data:l1GZ6mszgDhGztWmMdkNY2wRGfLIOGfHou7m0p8NkvaZZ3oKhblyu9C2Y2uEZArC8aCysxmU0QDfeIxDAzBdszUY,iv:HD8xdaiF9s0XZAuHNjAQfEtMgKaM0R12FCv5rTq19+Y=,tag:bfa48iOXhASXc+JhmYy/EQ==,type:str] + otm: "" +git_email_config: + default: ENC[AES256_GCM,data:ADmbGuV+E5wvGdbdC12BDi2TvHeoIRWjerKxnvDV7dENCxFyy+3P01IyCA==,iv:Nik4YiC8WhWmAnM7g1ER5HU0pg88l9uFiHQNtou5jas=,tag:RtK0XKKcHHR39p3mSl5YRw==,type:str] + otm: ENC[AES256_GCM,data:dFrxmxFRU5MThUSdqWuL3ZmBCJfMUVYWQTnWQF25Cnn6lMflau5vHNEFZZDZxyFBk7A=,iv:EOv1xgxXuN3LuiO1eorazgQHBkWY9GKUjFBaYnfkLRI=,tag:Mg6SwdQSGjtlR5iiOU/q7g==,type:str] +sops: + age: + - recipient: age1w7kjp0qdgfyg9cyj5w4qc4fc9qz3w65xw2veazesfgdenqrd3ucqsc5ejv + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAybC93bWJ1d05pSWdyOHkv + eXBUa1dUcWFnNTRKZXpxckhKNXlLMVBoR0dFCnNKcVhmcWFaQkllc05iVmtub2E2 + YkRTbnNNSnF2WWlET2N4MExYNFAzZFEKLS0tIHhwbTE3bEJlTEpXOXprSTBRckF0 + cjlWWTNQR3lLLzBqTHhld05VblFJdHcKihceil9ge+IKG2GZcLpGWUncvRvmyJ7w + YiWtb/ApF4T27wsmmFyLSnG8OWkLCKzaeU4QOVIGYQcfzzcQD5nUGg== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2025-04-29T13:45:42Z" + mac: ENC[AES256_GCM,data:Z4jJujUvl8jmJQbquV9NeczVZF17HI01sDpUoSSS7cM89WUOZzAOcT3zxR4hzyCfq4je++YkBPPFl4hcqbuVyBu8zCxY4z9673sFSLYrUA8THVeLYjMOTo0Hu0tIy8vy+uZZcAuRFaXyS+GrQHAdSSm4zVkwLG9R1nod+ys6LvQ=,iv:WfubcgFSY94cyfrlAlND6CQudoISuGL5fBhm9E3O4Q4=,tag:IeKYzou3EDwGyA23FGHtdA==,type:str] + unencrypted_suffix: _unencrypted + version: 3.10.2 diff --git a/nix-conf/home/includes/zsh.nix b/nix-conf/home/includes/zsh.nix index 9729386..650f559 100644 --- a/nix-conf/home/includes/zsh.nix +++ b/nix-conf/home/includes/zsh.nix @@ -1,17 +1,33 @@ -{ config, pkgs, lib, isDarwin, ... }: +{ + config, + pkgs, + lib, + ... +}: let - inherit (lib) - optionalAttrs - optionals; + inherit (lib) optionalAttrs optionals; + show_file_or_dir_preview = "if [ -d {} ]; then eza --tree --color=always {} | head -200; else bat -n --color=always --line-range :500 {}; fi"; in { - home.packages = with pkgs; [ - zsh-completions - ]; + home.packages = with pkgs; [ zsh-completions ]; programs.fzf = { enable = true; enableZshIntegration = true; + changeDirWidgetCommand = "fd --type=d --hidden --strip-cwd-prefix --exclude .git --exclude node_modules"; # FZF_ALT_C_COMMAND + changeDirWidgetOptions = [ "--preview 'eza --tree --color=always {} | head -200'" ]; # FZF_ALT_C_OPTS + defaultCommand = "fd --hidden --strip-cwd-prefix --exclude .git --exclude node_modules"; # FZF_DEFAULT_COMMAND + defaultOptions = [ + "--bind=ctrl-t:toggle-all" + "--bind=ctrl-j:jump" + ]; # FZF_DEFAULT_OPTS + fileWidgetCommand = config.programs.fzf.defaultCommand; # FZF_CTRL_T_COMMAND + fileWidgetOptions = [ "--preview '${show_file_or_dir_preview}'" ]; # FZF_CTRL_T_OPTS + historyWidgetOptions = [ + "--preview 'echo {}'" + "--preview-window down:3:hidden:wrap" + "--bind 'ctrl-t:toggle-preview'" + ]; # FZF_CTRL_R_OPTS }; programs.zoxide = { enable = true; @@ -23,20 +39,41 @@ in }; programs.keychain = { enable = lib.mkIf pkgs.stdenv.isLinux true; - agents = [ "ssh" "gpg"]; - keys = [ "id_rsa" "id_ed25519" "C171251002C200F2" ]; - # extraFlags = [ "--quiet" "--ignore-missing" ]; + agents = [ + "ssh" + "gpg" + ]; + keys = [ + "id_rsa" + "id_ed25519" + "C171251002C200F2" + ]; + # extraFlags = [ "--quiet" "--ignore-missing" ]; }; programs.command-not-found.enable = true; programs.zsh = { enable = true; enableCompletion = true; - autosuggestion.enable = true; + autosuggestion = { + enable = true; + highlight = "fg=#808080"; + strategy = [ + "history" + "completion" + ]; + }; defaultKeymap = "emacs"; history = { - size = 100000; - save = 100000; expireDuplicatesFirst = true; + ignoreSpace = true; + save = 100000; + share = true; + size = 100000; + }; + historySubstringSearch = { + enable = true; + searchUpKey = "$terminfo[kcuu1]"; + searchDownKey = "$terminfo[kcud1]"; }; profileExtra = '' @@ -50,11 +87,23 @@ in cp = "cp -iv"; mv = "mv -iv"; mkdir = "mkdir -v"; - tree = "eza --tree"; - - pp = "pushbullet push \"Pixel\" link \"\${1}\" \"\${1}\""; - - upgrade_emacs = "cp ~/.emacs.d/straight/versions/default.el ~/straight-versions-default-`date \"+%Y-%m-%d-%H%M%S\"`.el && emacs --batch -l \"~/.emacs.d/init.el\" -f \"my/upgrade-packages\""; + cat = "bat -p"; + c = "bat -p"; + l = "eza"; + la = "eza -a"; + lg = "eza -G"; + lga = "eza -aG"; + ll = "\\eza --icons --git --colour --long --group-directories-first --classify"; + lla = "ll -a"; + t = "eza --tree"; + p = "lsd"; + pa = "lsd -a"; + pll = "lsd -l"; + pla = "lsd -la"; + + pp = ''pushbullet push "Pixel" link "''${1}" "''${1}"''; + + upgrade_emacs = ''cp ~/.emacs.d/straight/versions/default.el ~/straight-versions-default-`date "+%Y-%m-%d-%H%M%S"`.el && emacs --batch -l "~/.emacs.d/init.el" -f "my/upgrade-packages"''; diff_emacs = "difft --color always --context 0 $(ls -d1v ~/straight-versions-default-*.el | tail -1) ~/.emacs.d/straight/versions/default.el | grep '\\[9[12]' | egrep -v '(gnu-elpa-mirror|nongnu-elpa|melpa|emacsmirror-mirror)'"; nix-up = "git -C ~/dotfiles pull && doas nix-channel --update && doas nixos-rebuild switch && nix-channel --update && home-manager switch && system-changes-report && hm-changes-report && df -h && date"; @@ -65,13 +114,14 @@ in fb = "fzf --preview 'bat --color=always --style=numbers --line-range=:500 {}'"; + # Restrict matches to subdirs of the current one (https://github.com/skywind3000/z.lua/blob/ef9a49d73d2b4f262c6fbb23262253dcda7c19a7/README.md#tips) zz = "z $PWD"; els = "ea run linear ls -- -1"; erg = "ea run grouped rg --"; fd = "ea run linear fd --"; - git-reset-branch = "git fetch && git reset --hard origin/\$(git branch --show-current)"; + git-reset-branch = "git fetch && git reset --hard origin/$(git branch --show-current)"; # Git log aliases from the omz git plugin gl = "git pull"; @@ -81,165 +131,211 @@ in glgga = "git log --graph --decorate --all"; glgm = "git log --graph --max-count=10"; glo_ = "git log --oneline --decorate"; - glol = "git log --graph --pretty=\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset\""; - glols = "git log --graph --pretty=\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset\" --stat"; - glod = "git log --graph --pretty=\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset\""; - glods = "git log --graph --pretty=\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset\" --date=short"; - glola = "git log --graph --pretty=\"%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset\" --all"; + glol = ''git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"''; + glols = ''git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --stat''; + glod = ''git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset"''; + glods = ''git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset" --date=short''; + glola = ''git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset" --all''; glog = "git log --oneline --decorate --graph"; gloga = "git log --oneline --decorate --graph --all"; - } - // optionalAttrs pkgs.stdenv.isDarwin { - oemacs = "open -a /Applications/Emacs.app"; - }; + } // optionalAttrs pkgs.stdenv.isDarwin { oemacs = "open -a /Applications/Emacs.app"; }; localVariables = { PER_DIRECTORY_HISTORY_TOGGLE = "^\\\\"; # ^\\ is ^# HISTORY_START_WITH_GLOBAL = true; - - ZSH_AUTOSUGGEST_STRATEGY = ["history" "completion"]; - - NVM_AUTO_USE = true; - NVM_LAZY_LOAD = true; - - LSP_USE_PLISTS = true; LESS = "-iRXF"; }; - initExtraFirst = '' - [[ $TERM == "tramp" ]] && unsetopt zle && PS1='$ ' && return - ''; - initExtra = '' - # Based on prezto tmux plugin - if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && (-z "$SSH_TTY" || -n "$TMUX_AUTO_ATTACH") ]]; then - tmux start-server + initContent = lib.mkMerge [ + (lib.mkBefore '' + [[ $TERM == "tramp" ]] && unsetopt zle && PS1='$ ' && return + '') + '' + # Based on prezto tmux plugin + if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && (-z "$SSH_TTY" || -n "$TMUX_AUTO_ATTACH") ]]; then + tmux start-server + + if ! tmux has-session 2> /dev/null; then + tmux new-session -d -s "0" \; set-option -t "0" destroy-unattached off &> /dev/null + fi - if ! tmux has-session 2> /dev/null; then - tmux new-session -d -s "0" \; set-option -t "0" destroy-unattached off &> /dev/null + if [[ -n "$SSH_TTY" ]]; then + exec tmux -u attach-session + else + exec tmux -u attach-session -d + fi fi - if [[ -n "$SSH_TTY" ]]; then - exec tmux -u attach-session - else - exec tmux -u attach-session -d - fi - fi - - # Keep these in initExtra, rather than localVariables, because the order matters - export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules}/*" 2> /dev/null' - export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" - export FZF_ALT_C_COMMAND='rg --hidden --files --sort-files --null -g "!{.git,node_modules}/*" | xargs -0 dirname | sort -u' - export FZF_ALT_C_OPTS="--preview 'eza --tree {} | head -200'" - export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind 'ctrl-t:toggle-preview'" - export FZF_DEFAULT_OPTS="--bind=ctrl-t:toggle-all --bind=ctrl-j:jump" - - eval "$(batpipe)" - autopair-init - enable-fzf-tab - bindkey '^[[A' history-substring-search-up - bindkey '^[[B' history-substring-search-down - - # make home and end work - [[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line - [[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line - - # disable sort when completing `git checkout` - zstyle ''\':completion:*:git-checkout:*''\' sort false - # set descriptions format to enable group support - zstyle ''\':completion:*:descriptions''\' format ''\'[%d]''\' - # Allow tab to expand aliases - zstyle ':completion:*' completer _expand_alias _complete _ignored - # set list-colors to enable filename colorizing - #zstyle ''\':completion:*''\' list-colors ''${(s.:.)LS_COLORS} - # preview directory''\'s content with eza when completing cd - zstyle ''\':fzf-tab:complete:cd:*''\' fzf-preview ''\'eza -1 --color=always ''$realpath''\' - # switch group using `,` and `.` - zstyle ''\':fzf-tab:*''\' switch-group ''\',''\' ''\'.''\' - - set -o noclobber append_history share_history - - # disable flow control (so that fzf-git.sh's ^g^s can work) - stty -ixon - - function generate () { gopass generate -s -p $1 $((RANDOM % 14 + 45)) } - function fcd { cd $(fd -L --max-depth=''${1:-4} --type=d 2>/dev/null | fzf-tmux) } - - fif() { - if [ ! "$#" -gt 0 ]; then - echo "usage: fif <SEARCH_TERM>" - return 1; - fi - rg --files-with-matches --no-messages "$1" | fzf $FZF_PREVIEW_WINDOW --preview "rg --ignore-case --pretty --context 10 '$1' {}" - } + autopair-init + enable-fzf-tab + + # make home and end work + [[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line + [[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line + + # disable sort when completing `git checkout` + zstyle ':completion:*:git-checkout:*' sort false + # set descriptions format to enable group support + zstyle ':completion:*:descriptions' format '[%d]' + # Allow tab to expand aliases + zstyle ':completion:*' completer _expand_alias _complete _ignored + # set list-colors to enable filename colorizing + #zstyle ':completion:*' list-colors ''${(s.:.)LS_COLORS} + # preview directory's content with eza when completing cd + zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath' + # switch group using `,` and `.` + zstyle ':fzf-tab:*' switch-group ',' '.' + + # functions modified from https://www.josean.com/posts/7-amazing-cli-tools + _fzf_compgen_path() { + fd --hidden --exclude .git --exclude node_modules . "$1" + } + _fzf_compgen_dir() { + fd --type=d --hidden --exclude .git --exclude node_modules . "$1" + } + _fzf_comprun() { + local command=$1 + shift + + case "$command" in + cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;; + export|unset) fzf --preview "eval 'echo $'{}" "$@" ;; + ssh) fzf --preview 'dig {}' "$@" ;; + *) fzf --preview "${show_file_or_dir_preview}" "$@" ;; + esac + } - fe() { - IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0)) - [[ -n "$files" ]] && ''${EDITOR:-vim} "''${files[@]}" - } + set -o noclobber + + # disable flow control (so that fzf-git.sh's ^g^s can work) + stty -ixon + + # These functions are called as follows, after using ea (using vip as an example): + # vip # edits the first result from ea (roughly equivalent to vi `ea p 1`) + # vip <n> # edits the nth result from ea (vi `ea p <n>`) + # vip <n> foo # if the nth result from ea is a directory, edit foo in that directory (vi `ea p <n>`/foo) + # Will add +<line-number>, where the line number is available + function _vip () { + local cmd=(''${=1}) # zsh only, not portable; something like CMD=($(echo $1)) is more portable but is ugly + local idx=''${2:-1} + local base_path=$(ea p $idx) + local line=$(ea p $idx "{line}") + local ea_format="'{path}'" + + if [ -z "$base_path" ]; then + echo "No file path found for index $2" + return 1 + fi - # TODO is there a way to do this in shellAliases - alias ..="cd .." - alias -- -="cd -" + if [ $# -gt 2 -a ! -d "$base_path" ]; then + echo "$base_path is not a directory" + return 2 + fi - ...() { - local declare dirs=() - get_parent_dirs() { - if [[ -d "''${1}" ]]; then dirs+=("$1"); else return; fi - if [[ "''${1}" == '/' ]]; then - for _dir in "''${dirs[@]}"; do echo $_dir; done - else - get_parent_dirs $(dirname "$1") + if [ $# -lt 3 -a $line -ne 1 ]; then + ea_format+=" +{line}" fi + + eval $(ea p $idx "$cmd ''${ea_format}$3") } - local DIR=$(get_parent_dirs $(realpath "$PWD/..") | fzf-tmux) - cd "$DIR" - } - # From omz - function mkcd () { - mkdir -p $@ && cd ''${@:$#} - } + function vip () { + _vip $EDITOR ''${@} + } + function bp () { + _vip bat ''${@} + } + function bpp () { + # this will be split into an array in _vip + CMD="bat -p" + _vip $CMD ''${@} + } - tre () { command tre "$@" -e && source "/tmp/tre_aliases_$USER" 2>/dev/null; } + function ecd () { + cd $(ea p ''${1:-1}) + } - function gcd () { - if [ $# -eq 0 ] ; then - echo "Number of days must be specified" >&2 - return 1 - fi - if ! [[ $1 =~ '^[0-9]+$' ]] ; then - echo "Number of days must be a number" >&2 - return 2 - fi + function generate () { gopass generate -s -p $1 $((RANDOM % 14 + 45)) } + function fcd { cd $(fd -L --max-depth=''${1:-4} --type=d 2>/dev/null | fzf-tmux) } - if [ $1 -eq 0 ] ; then - GC_ARGS=(-d) - else - GC_ARGS=(--delete-older-than ''${1}d) - fi + fif() { + if [ ! "$#" -gt 0 ]; then + echo "usage: fif <SEARCH_TERM>" + return 1; + fi + rg --files-with-matches --no-messages "$1" | fzf $FZF_PREVIEW_WINDOW --preview "rg --ignore-case --pretty --context 10 '$1' {}" + } - DOAS=$(command -v doas) + fe() { + IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0)) + [[ -n "$files" ]] && ''${EDITOR:-vim} "''${files[@]}" + } - # Run as the current user (as well as root) to clean up hm generations - nix-collect-garbage ''${GC_ARGS[@]} - if [ -n $DOAS ] ; then - $DOAS nix-collect-garbage ''${GC_ARGS[@]} - fi + # TODO is there a way to do this in shellAliases + alias ..="cd .." + alias ...="cd ../.." + alias -- -="cd -" + + .,() { + local declare dirs=() + get_parent_dirs() { + if [[ -d "''${1}" ]]; then dirs+=("$1"); else return; fi + if [[ "''${1}" == '/' ]]; then + for _dir in "''${dirs[@]}"; do echo $_dir; done + else + get_parent_dirs $(dirname "$1") + fi + } + local DIR=$(get_parent_dirs $(realpath "$PWD/..") | fzf-tmux) + cd "$DIR" + } - df -h - date - } + # From omz + function mkcd () { + mkdir -p $@ && cd ''${@:$#} + } - function checkout-pr () { - git fetch ''${2:-upstream} pull/''${1}/head:pr-''${1} - git switch pr-''${1} - } + tre () { command tre "$@" -e && source "/tmp/tre_aliases_$USER" 2>/dev/null; } - [[ ! -f ~/.zsh.local ]] || source ~/.zsh.local + function gcd () { + if [ $# -eq 0 ] ; then + echo "Number of days must be specified" >&2 + return 1 + fi + if ! [[ $1 =~ '^[0-9]+$' ]] ; then + echo "Number of days must be a number" >&2 + return 2 + fi - [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh - ''; + if [ $1 -eq 0 ] ; then + GC_ARGS=(-d) + else + GC_ARGS=(--delete-older-than ''${1}d) + fi - plugins = with pkgs; [ + DOAS=$(command -v doas) + + # Run as the current user (as well as root) to clean up hm generations + nix-collect-garbage ''${GC_ARGS[@]} + if [ -n $DOAS ] ; then + $DOAS nix-collect-garbage ''${GC_ARGS[@]} + fi + + df -h + date + } + + function checkout-pr () { + git fetch ''${2:-upstream} pull/''${1}/head:pr-''${1} + git switch pr-''${1} + } + + [[ ! -f ~/.zsh.local ]] || source ~/.zsh.local + + [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh + '' + ]; + + plugins = with pkgs; [ { name = "zsh-autopair"; src = zsh-autopair; @@ -266,11 +362,6 @@ in file = "share/zsh-powerlevel10k/powerlevel10k.zsh-theme"; } { - name = "zsh-history-substring-search"; - src = zsh-history-substring-search; - file = "share/zsh-history-substring-search/zsh-history-substring-search.zsh"; - } - { name = "zsh-forgit"; src = zsh-forgit; file = "share/zsh/zsh-forgit/forgit.plugin.zsh"; @@ -283,7 +374,7 @@ in { name = "fzf-git.sh"; src = fzf-git-sh; - file = "share/zsh/fzf-git-sh/fzf-git.sh"; + file = "share/fzf-git-sh/fzf-git.sh"; } { name = "per-directory-history"; @@ -295,19 +386,6 @@ in }; file = "per-directory-history.zsh"; } - ] - ++ optionals stdenv.isDarwin [ - { - name = "zsh-nvm"; - src = fetchFromGitHub { - owner = "lukechilds"; - repo = "zsh-nvm"; - rev = "23067bd9bb6eb6f4737a3ea90cb0cb5e85f61ba2"; - sha256 = "Zwdi7bezMFKaIKYwsSftu3mJSFvadEWmY2hYnU1Kpu4="; - }; - file = "zsh-nvm.plugin.zsh"; - } ]; }; } - |