From 7decd40844224c894195fd948ac9829d2f9d0765 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 23 Dec 2024 11:14:18 -0500 Subject: [PATCH 1/3] Switch to zsh. --- nix/configuration/configuration.nix | 1 + nix/configuration/roles/zsh/default.nix | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 nix/configuration/roles/zsh/default.nix diff --git a/nix/configuration/configuration.nix b/nix/configuration/configuration.nix index c8fe1c8..6d9e79e 100644 --- a/nix/configuration/configuration.nix +++ b/nix/configuration/configuration.nix @@ -22,6 +22,7 @@ ./zfs.nix ./network.nix ./roles/firewall + ./roles/zsh ./roles/graphics ./roles/sound ./roles/sway diff --git a/nix/configuration/roles/zsh/default.nix b/nix/configuration/roles/zsh/default.nix new file mode 100644 index 0000000..ec8801a --- /dev/null +++ b/nix/configuration/roles/zsh/default.nix @@ -0,0 +1,17 @@ +{ + config, + lib, + pkgs, + ... +}: + +{ + imports = [ ]; + + environment.systemPackages = with pkgs; [ + zsh + ]; + + users.users.talexander.shell = pkgs.zsh; + environment.shells = with pkgs; [ zsh ]; +} From 5e424b35e435aa0bb9a55f9fd53dca1823eb75f3 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 23 Dec 2024 13:50:36 -0500 Subject: [PATCH 2/3] Make a zsh-histdb package. --- .../flakes/zsh-histdb/flake.lock | 61 +++++++++++++++++++ nix/configuration/flakes/zsh-histdb/flake.nix | 34 +++++++++++ .../flakes/zsh-histdb/package.nix | 28 +++++++++ 3 files changed, 123 insertions(+) create mode 100644 nix/configuration/flakes/zsh-histdb/flake.lock create mode 100644 nix/configuration/flakes/zsh-histdb/flake.nix create mode 100644 nix/configuration/flakes/zsh-histdb/package.nix diff --git a/nix/configuration/flakes/zsh-histdb/flake.lock b/nix/configuration/flakes/zsh-histdb/flake.lock new file mode 100644 index 0000000..b3604a4 --- /dev/null +++ b/nix/configuration/flakes/zsh-histdb/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1734875076, + "narHash": "sha256-Pzyb+YNG5u3zP79zoi8HXYMs15Q5dfjDgwCdUI5B0nY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1807c2b91223227ad5599d7067a61665c52d1295", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "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/nix/configuration/flakes/zsh-histdb/flake.nix b/nix/configuration/flakes/zsh-histdb/flake.nix new file mode 100644 index 0000000..f831ce1 --- /dev/null +++ b/nix/configuration/flakes/zsh-histdb/flake.nix @@ -0,0 +1,34 @@ +{ + description = "A slightly better history for zsh"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = + { + self, + nixpkgs, + flake-utils, + ... + }: + let + out = + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + # Maybe pkgs = import nixpkgs { inherit system; }; ? + appliedOverlay = self.overlays.default pkgs pkgs; + in + { + packages = rec { + default = zsh-histdb; + zsh-histdb = appliedOverlay.zsh-histdb; + }; + }; + in + flake-utils.lib.eachDefaultSystem out + // { + overlays.default = final: prev: { + zsh-histdb = final.callPackage ./package.nix { }; + }; + }; +} diff --git a/nix/configuration/flakes/zsh-histdb/package.nix b/nix/configuration/flakes/zsh-histdb/package.nix new file mode 100644 index 0000000..6a43797 --- /dev/null +++ b/nix/configuration/flakes/zsh-histdb/package.nix @@ -0,0 +1,28 @@ +# unpackPhase +# patchPhase +# configurePhase +# buildPhase +# checkPhase +# installPhase +# fixupPhase +# installCheckPhase +# distPhase +{ + stdenv, + pkgs, + sqlite, + ... +}: +stdenv.mkDerivation { + name = "zsh-histdb"; + src = pkgs.fetchgit { + url = "https://github.com/larkery/zsh-histdb.git"; + rev = "90a6c104d0fcc0410d665e148fa7da28c49684eb"; + sha256 = "sha256-vtG1poaRVbfb/wKPChk1WpPgDq+7udLqLfYfLqap4Vg="; + }; + buildInputs = [ sqlite ]; + installPhase = '' + mkdir -p $out/share/zsh/plugins/zsh-histdb + cp -r $src/histdb-* $src/*.zsh $src/db_migrations $out/share/zsh/plugins/zsh-histdb/ + ''; +} From 64d495afa57e9291b828e547c07a1db56050cee3 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 23 Dec 2024 15:44:53 -0500 Subject: [PATCH 3/3] Use zsh-histdb package. --- nix/configuration/flake.lock | 54 ++++++++++++++++- nix/configuration/flake.nix | 8 +++ nix/configuration/roles/zsh/default.nix | 81 +++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 1 deletion(-) diff --git a/nix/configuration/flake.lock b/nix/configuration/flake.lock index 8b0048b..e64af3f 100644 --- a/nix/configuration/flake.lock +++ b/nix/configuration/flake.lock @@ -76,6 +76,24 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ @@ -259,7 +277,8 @@ "lanzaboote": "lanzaboote", "nixpkgs": "nixpkgs", "nixpkgs-b93b4e9b5": "nixpkgs-b93b4e9b5", - "nixpkgs-unstable": "nixpkgs-unstable" + "nixpkgs-unstable": "nixpkgs-unstable", + "zsh-histdb": "zsh-histdb" } }, "rust-overlay": { @@ -301,6 +320,39 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "zsh-histdb": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1, + "narHash": "sha256-vPz7cJzdLAWFWQQ/KSXGB+HsUfO8CnPX4AO4zjf9llo=", + "path": "flakes/zsh-histdb", + "type": "path" + }, + "original": { + "path": "flakes/zsh-histdb", + "type": "path" + } } }, "root": "root", diff --git a/nix/configuration/flake.nix b/nix/configuration/flake.nix index 63bd9e2..a320118 100644 --- a/nix/configuration/flake.nix +++ b/nix/configuration/flake.nix @@ -38,6 +38,12 @@ lanzaboote = { url = "github:nix-community/lanzaboote/v0.4.1"; + # Optional but recommended to limit the size of your system closure. + inputs.nixpkgs.follows = "nixpkgs"; + }; + zsh-histdb = { + url = "path:flakes/zsh-histdb"; + # Optional but recommended to limit the size of your system closure. inputs.nixpkgs.follows = "nixpkgs"; }; @@ -52,6 +58,7 @@ impermanence, home-manager, lanzaboote, + zsh-histdb, ... }@inputs: let @@ -73,6 +80,7 @@ home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; } + { nixpkgs.overlays = [ zsh-histdb.overlays.default ]; } ./configuration.nix ]; }; diff --git a/nix/configuration/roles/zsh/default.nix b/nix/configuration/roles/zsh/default.nix index ec8801a..d4d254b 100644 --- a/nix/configuration/roles/zsh/default.nix +++ b/nix/configuration/roles/zsh/default.nix @@ -5,13 +5,94 @@ ... }: +let + zshrc = pkgs.writeTextFile { + name = ".zshrc"; + text = '' + # Lines configured by zsh-newuser-install + HISTFILE=~/.zhistory + HISTSIZE=100000 + SAVEHIST=100000 + setopt appendhistory notify + unsetopt beep + bindkey -e + # End of lines configured by zsh-newuser-install + # The following lines were added by compinstall + # + + # Use menu complete immediately instead of after the first tab + setopt MENU_COMPLETE + + zstyle :compinstall filename "$HOME/.zshrc" + + autoload -Uz compinit + compinit + # End of lines added by compinstall + + # Enable the 2d menu for tab completion + zstyle ':completion:*' menu select + + autoload colors zsh/terminfo + if [[ "$terminfo[colors]" -ge 8 ]]; then + colors + fi + for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do + eval PR_$color='%{$terminfo[bold]$fg[''${(L)color}]%}' + eval PR_LIGHT_$color='%{$fg[''${(L)color}]%}' + (( count = $count + 1 )) + done + PR_NO_COLOR="%{$terminfo[sgr0]%}" + PS1="[$PR_BLUE%n$PR_WHITE@$PR_GREEN%U%m%u$PR_NO_COLOR:$PR_RED%2c$PR_NO_COLOR]%(!.#.$) " + + source ${pkgs.zsh-histdb}/share/zsh/plugins/zsh-histdb/sqlite-history.zsh + autoload -Uz add-zsh-hook + + source ${pkgs.zsh-histdb}/share/zsh/plugins/zsh-histdb/histdb-interactive.zsh + bindkey '^r' _histdb-isearch + + # TODO: Consider moving to /etc/profile.d + #while read file; do + # if [ -e "$file" ]; then + # source "$file" + # fi + #done <<<"$(find $HOME/.config/ansible_deploy/zshrc -maxdepth 1 -type f -name '*.zsh' -print)" + ''; + }; +in { imports = [ ]; environment.systemPackages = with pkgs; [ zsh + sqlite # TODO: can this be pulled into zsh-histdb automatically? ]; users.users.talexander.shell = pkgs.zsh; environment.shells = with pkgs; [ zsh ]; + + programs.zsh = { + enable = true; + }; + + home-manager.users.talexander = + { pkgs, ... }: + { + home.file.".zshrc" = { + source = "${zshrc}"; + }; + }; + + environment.persistence."/persist" = lib.mkIf (!config.me.buildingIso) { + hideMounts = true; + users.talexander = { + directories = [ + { + directory = ".histdb"; + user = "talexander"; + group = "talexander"; + mode = "0700"; + } + ]; + }; + }; }