From afde8b154ceb882df73eee671cfd324871819711 Mon Sep 17 00:00:00 2001 From: rasmus-kirk Date: Tue, 7 Jan 2025 17:15:03 +0100 Subject: [PATCH] Updated stuff --- configurations/home-manager/work/home.nix | 4 - flake.lock | 6 +- flake.nix | 5 +- modules/home-manager/fonts/default.nix | 2 +- .../homeManagerScripts/default.nix | 169 +++++++++++------- modules/home-manager/jiten/default.nix | 14 +- modules/home-manager/yazi/default.nix | 27 ++- .../yazi/plugins/auto-tab/init.lua | 9 + 8 files changed, 160 insertions(+), 76 deletions(-) create mode 100644 modules/home-manager/yazi/plugins/auto-tab/init.lua diff --git a/configurations/home-manager/work/home.nix b/configurations/home-manager/work/home.nix index e4964fd..2831376 100644 --- a/configurations/home-manager/work/home.nix +++ b/configurations/home-manager/work/home.nix @@ -120,10 +120,6 @@ in { slack signal-desktop - # Fonts - (nerdfonts.override {fonts = ["FiraCode"];}) - fira-code - # Document handling texlive.combined.scheme-full pandoc diff --git a/flake.lock b/flake.lock index 9cd1f35..05a98a2 100644 --- a/flake.lock +++ b/flake.lock @@ -54,11 +54,11 @@ ] }, "locked": { - "lastModified": 1736781604, - "narHash": "sha256-nIjcN89nxaI5ZnwU/1gzc3rBVQ/te5sHraYeG4cyJX4=", + "lastModified": 1736785676, + "narHash": "sha256-TY0jUwR3EW0fnS0X5wXMAVy6h4Z7Y6a3m+Yq++C9AyE=", "owner": "nix-community", "repo": "home-manager", - "rev": "9616d81f98032d1ee9bec68ab4b6a8c833add88c", + "rev": "fc52a210b60f2f52c74eac41a8647c1573d2071d", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index cd67fc9..7bef39c 100644 --- a/flake.nix +++ b/flake.nix @@ -48,7 +48,10 @@ }; homeManagerModules = rec { - kirk = import ./modules/home-manager; + kirk = { + imports = [ ./modules/home-manager ]; + config._module.args = {inherit inputs;}; + }; default = kirk; }; diff --git a/modules/home-manager/fonts/default.nix b/modules/home-manager/fonts/default.nix index cdef2e8..91fa65f 100644 --- a/modules/home-manager/fonts/default.nix +++ b/modules/home-manager/fonts/default.nix @@ -31,7 +31,7 @@ in { home.packages = with pkgs; [ # Fonts - (nerdfonts.override {fonts = ["FiraCode"];}) + nerd-fonts.fira-code fira-code ]; }; diff --git a/modules/home-manager/homeManagerScripts/default.nix b/modules/home-manager/homeManagerScripts/default.nix index e7ea632..6fa393e 100644 --- a/modules/home-manager/homeManagerScripts/default.nix +++ b/modules/home-manager/homeManagerScripts/default.nix @@ -1,4 +1,5 @@ { + inputs, config, pkgs, lib, @@ -11,56 +12,106 @@ with lib; let then cfg.configDir else "${config.xdg.configHome}/home-manager"; - hm-clean = pkgs.writeShellApplication { - name = "hm-clean"; + hm = pkgs.writeShellApplication { + name = "hm"; + runtimeInputs = with pkgs; [ fzf git ]; text = '' - # Delete old home-manager profiles - home-manager expire-generations '-30 days' && - # Delete old nix profiles - nix profile wipe-history --older-than 30d && - # Optimize space - nix store gc && - nix store optimise - ''; - }; + command="''${1:-}" + # Check if a parameter is provided + if [ -z "$command" ]; then + echo "Usage: hm " + echo "" + echo "Commands:" + echo " rebuild Rebuild the Home Manager configuration." + echo " upgrade Upgrade Home Manager packages. Note that this also rebuilds the configuration." + echo " options Shows available Home Manager configuration options." + echo " garbage-collect Garbage collects, freeing up unused hard drive space allocated to unused Nix packages." + echo " update Updating Nix flake inputs. This updates packages for the next rebuild..." + echo " test Test the Home Manager configuration." + echo " rollback Roll back to the previous configuration." + echo "" + echo "Garbage collecting will:" + echo "- Delete Home Manager configurations and nix profiles older than 30 days" + echo "- Delete unused packages in the Nix store" + echo "- Optimize the Nix store, by replacing identical files in the store by hard links" + exit 1 + fi - hm-update = pkgs.writeShellApplication { - name = "hm-update"; - text = '' - nix flake update --flake ${configDir} - ''; - }; + update() { + echo "[HM-INFO]: Updating packages for the next rebuild, by updating the Nix flake inputs..." + echo "" + nix flake update --flake ${configDir} + } - hm-upgrade = pkgs.writeShellApplication { - name = "hm-upgrade"; - text = '' - # Update, switch to new config, and cleanup - ${hm-update}/bin/hm-update && - ${hm-rebuild}/bin/hm-rebuild && - ${hm-clean}/bin/hm-clean - ''; - }; + rebuild() { + echo "[HM-INFO]: Rebuilding Home Manager configuration..." + echo "" + pushd "${configDir}" + git add . + home-manager switch -b backup --flake .#${cfg.machine} + popd + } - hm-rebuild = pkgs.writeShellApplication { - name = "hm-rebuild"; - text = '' - pushd ${configDir} - git add . - # Switch configuration, backing up files - home-manager switch -b backup --flake .#${cfg.machine} - popd - ''; - }; + garbage_collect() { + echo "[HM-INFO]: Garbage collecting the Nix store..." + echo "" + home-manager expire-generations '-30 days' + nix profile wipe-history --older-than 30d + nix store gc + nix store optimise + } - hm-rollback = pkgs.writeShellApplication { - name = "hm-rollback"; - runtimeInputs = [pkgs.fzf]; - text = '' - gen=$(home-manager generations | grep -P "^[0-9]{4}-[0-9]{2}-[0-9]{2}" | fzf) - genPath=$(echo "$gen" | grep -oP "/nix/store/.*") + rollback() { + echo "" + gen=$(home-manager generations | grep -P "^[0-9]{4}-[0-9]{2}-[0-9]{2}" | fzf) + genPath=$(echo "$gen" | grep -oP "/nix/store/.*") + genId=$(echo "$gen" | grep -oP "(?<=id )\d+") - echo -e '\033[1mActivating selected generation:\n\033[0m' - "$genPath"/activate + if [ -z "$gen" ]; then + echo "[HM-ERROR]: No generation selected. Aborting." + exit 1 + fi + + echo "[HM-INFO]: Activating generation $genId:" + "$genPath"/activate + } + + # Handle the command + case "$1" in + rebuild) + rebuild + ;; + upgrade) + echo "[HM-INFO]: Upgrading Home Manager packages..." + echo "" + update && + rebuild && + garbage-collect + ;; + options) + man home-configuration.nix + ;; + garbage-collect) + garbage-collect + ;; + update) + update + ;; + rollback) + rollback + ;; + test) + tmpdir=$(mktemp -d) && + echo "[HM-INFO]: Building the test configuration to \"$tmpdir\"..." && + cd "$tmpdir" && + home-manager build --show-trace --flake ${configDir}#${cfg.machine} + ;; + *) + echo "[HM-ERROR]: Unknown command: $1" + echo "Valid commands are: rebuild, upgrade, options, garbage-collect, rollback, update, test" + exit 1 + ;; + esac ''; }; in { @@ -70,17 +121,13 @@ in { managing home-manager easier. These scripts are lean bash scripts that compose a couple of nix and home-manager commands: - - `hm-update`: Updates the available packages, usually, you don't need - to run this, but the other scripts use it. - - `hm-clean`: Cleans up older configurations and garbage collects the - nix store, cleaning up unused packages and freeing up harddisk space - - `hm-rebuild`: Builds your configuration. Backs up files; if you - fx have a `.bashrc` and home-manager needs to overwrite it, the old - `.bashrc` is renamed to `.bashrc.bck` - - `hm-upgrade`: Updates all packages, rebuilds and finally older - configurations/garbage collects - - `hm-rollback`: Use this command to roll back to a previous working - home manager configuration. + - `hm rebuild`: Rebuild the Home Manager configuration." + - `hm upgrade`: Upgrade Home Manager packages. Note that this also rebuilds the configuration." + - `hm options`: Shows available Home Manager configuration options." + - `hm garbage-collect`: Garbage collects, freeing up unused hard drive space allocated to unused Nix packages." + - `hm update`: Updating Nix flake inputs. This updates packages for the next rebuild..." + - `hm test`: Test the Home Manager configuration." + - `hm rollback`: Roll back to the previous configuration." ''; configDir = mkOption { @@ -115,12 +162,14 @@ in { entries = lib.mkForce []; }; + # Use the pinned nixpkgs version that is already used, when using `nix shell nixpkgs#package` + nix.registry.nixpkgs = { + from = { id = "nixpkgs"; type = "indirect"; }; + flake = inputs.nixpkgs; + }; + home.packages = [ - hm-update - hm-upgrade - hm-rebuild - hm-clean - hm-rollback + hm ]; }; } diff --git a/modules/home-manager/jiten/default.nix b/modules/home-manager/jiten/default.nix index 10b3973..1da6ccd 100644 --- a/modules/home-manager/jiten/default.nix +++ b/modules/home-manager/jiten/default.nix @@ -35,8 +35,18 @@ in { config = mkIf cfg.enable { home.packages = with pkgs; [jiten]; - programs.zsh.initExtra = mkIf cfg.dailyWord "cat ${config.xdg.stateHome}/word-of-the-day/japanese.txt"; - programs.bash.initExtra = mkIf cfg.dailyWord "cat ${config.xdg.stateHome}/word-of-the-day/japanese.txt"; + programs.zsh.initExtra = mkIf cfg.dailyWord '' + if [[ -z "$ZSH_WORD_DISPLAYED" ]]; then + export ZSH_WORD_DISPLAYED=true + cat ${config.xdg.stateHome}/word-of-the-day/japanese.txt + fi + ''; + programs.bash.initExtra = mkIf cfg.dailyWord '' + if [[ -z "$BASH_WORD_DISPLAYED" ]]; then + export BASH_WORD_DISPLAYED=true + cat ${config.xdg.stateHome}/word-of-the-day/japanese.txt + fi + ''; systemd.user = mkIf cfg.dailyWord { timers = { diff --git a/modules/home-manager/yazi/default.nix b/modules/home-manager/yazi/default.nix index 44b5a0e..2a6d4fc 100644 --- a/modules/home-manager/yazi/default.nix +++ b/modules/home-manager/yazi/default.nix @@ -15,9 +15,9 @@ with lib; let cp -r "${name}".yazi/* "$out" ''; src = pkgs.fetchgit { - rev = "5e65389d1308188e5a990059c06729e2edb18f8a"; + rev = "600614a9dc59a12a63721738498c5541c7923873"; url = "https://github.com/yazi-rs/plugins.git"; - hash = "sha256-XHaQjudV9YSMm4vF7PQrKGJ078oVF1U1Du10zXEJ9I0="; + hash = "sha256-mQkivPt9tOXom78jgvSwveF/8SD8M2XCXxGY8oijl+o="; }; }; mkYaziPluginGithub = x: @@ -38,8 +38,8 @@ with lib; let gruvbox-dark = mkYaziPluginGithub { name = "gruvbox-dark"; url = "https://github.com/bennyyip/gruvbox-dark.yazi.git"; - rev = "c204853de7a78bc99ea628e51857ce65506468db"; - hash = "sha256-NBco10MINyAJk1YWHwYUzvI9mnTJl9aYyDtQSTUP3Hs="; + rev = "b4cc9f2a3016f9b5a9bbb5aeb4619d029ee61397"; + hash = "sha256-9ZZHXP0Junaj6r80nE8oDNEU5WIKVdtz4g72BFzcSAM="; }; exifaudio = mkYaziPluginGithub { name = "exifaudio"; @@ -81,8 +81,11 @@ in { enableZshIntegration = true; shellWrapperName = "j"; initLua = '' - require("full-border"):setup() require("git"):setup() + require("full-border"):setup() + require("session"):setup { + sync_yanked = true, + } ''; keymap = { manager.prepend_keymap = @@ -112,6 +115,20 @@ in { run = "create"; desc = "Create a file"; } + { + on = ["m" "t"]; + run = ''shell "foot /dev/null &"''; + desc = "Create a new terminal"; + } + { + on = ["m" "j"]; + run = ''shell "foot /dev/null zsh -c 'source ~/.zshrc; j; zsh'& "''; + desc = "Create a new terminal with yazi open"; + } + { + on = [ "2" ]; + run = "plugin switch-create-tab --args=1"; + } # Selection { on = ";"; diff --git a/modules/home-manager/yazi/plugins/auto-tab/init.lua b/modules/home-manager/yazi/plugins/auto-tab/init.lua new file mode 100644 index 0000000..8524f2f --- /dev/null +++ b/modules/home-manager/yazi/plugins/auto-tab/init.lua @@ -0,0 +1,9 @@ +--- @sync entry +local function entry(_, args) +for _ = #cx.tabs, args[1] do +ya.manager_emit("tab_create", { current = true }) +end +ya.manager_emit("tab_switch", { args[1] }) +end + +return { entry = entry }