From 11fd8e0440b5c4044264f382708eabf289b28a70 Mon Sep 17 00:00:00 2001 From: Danilo Reyes Date: Sun, 12 Oct 2025 13:51:45 -0600 Subject: [PATCH] refractor shell configurations with flake-parts --- modules/dev/emacs.nix | 3 ++- modules/dev/nix.nix | 3 ++- modules/scripts/download.nix | 33 ++++++++++++--------------------- modules/shell/tools.nix | 33 ++++++++++++--------------------- parts/core.nix | 6 ++++++ 5 files changed, 34 insertions(+), 44 deletions(-) diff --git a/modules/dev/emacs.nix b/modules/dev/emacs.nix index e0c17a6..467fa96 100644 --- a/modules/dev/emacs.nix +++ b/modules/dev/emacs.nix @@ -1,5 +1,6 @@ { config, + inputs, lib, pkgs, ... @@ -14,7 +15,7 @@ "doom/templates/programming.org".source = ../../dotfiles/doom/templates/programming.org; }; services.lorri.enable = true; - programs.${config.my.shell.type}.shellAliases = { + programs.${config.my.shell.type}.shellAliases = inputs.self.lib.mergeAliases inputs.self.lib.commonAliases { edit = "emacsclient -t"; e = "edit"; }; diff --git a/modules/dev/nix.nix b/modules/dev/nix.nix index 2f4b11d..0253068 100644 --- a/modules/dev/nix.nix +++ b/modules/dev/nix.nix @@ -1,5 +1,6 @@ { config, + inputs, lib, pkgs, ... @@ -33,7 +34,7 @@ in }; config = lib.mkIf config.my.dev.nix.enable { users.users.jawz = { inherit packages; }; - home-manager.users.jawz.programs.${shellType}.shellAliases = { + home-manager.users.jawz.programs.${shellType}.shellAliases = inputs.self.lib.mergeAliases inputs.self.lib.commonAliases { nixformat = '' deadnix -e && \ nix run nixpkgs#nixfmt-tree && \ diff --git a/modules/scripts/download.nix b/modules/scripts/download.nix index 506fef9..85c487f 100644 --- a/modules/scripts/download.nix +++ b/modules/scripts/download.nix @@ -17,32 +17,23 @@ in { home-manager.users.jawz.programs.${config.my.shell.type} = { - shellAliases = { + shellAliases = inputs.self.lib.mergeAliases inputs.self.lib.commonAliases { dl = "${download}/bin/download -u jawz -i"; comic = ''dl "$(cat "$LC" | fzf --multi --exact -i)"''; gallery = ''dl "$(cat "$LW" | fzf --multi --exact -i)"''; }; } - // ( - if config.my.shell.type == "bash" then - { - initExtra = '' - list_root=$XDG_CONFIG_HOME/jawz/lists/jawz - export LW=$list_root/watch.txt - export LI=$list_root/instant.txt - export LC=$list_root/comic.txt - ''; - } - else - { - initContent = '' - list_root=$XDG_CONFIG_HOME/jawz/lists/jawz - export LW=$list_root/watch.txt - export LI=$list_root/instant.txt - export LC=$list_root/comic.txt - ''; - } - ); + // inputs.self.lib.shellConditional config.my.shell.type '' + list_root=$XDG_CONFIG_HOME/jawz/lists/jawz + export LW=$list_root/watch.txt + export LI=$list_root/instant.txt + export LC=$list_root/comic.txt + '' '' + list_root=$XDG_CONFIG_HOME/jawz/lists/jawz + export LW=$list_root/watch.txt + export LI=$list_root/instant.txt + export LC=$list_root/comic.txt + ''; systemd.user = { services = let diff --git a/modules/shell/tools.nix b/modules/shell/tools.nix index 345d403..48629a8 100644 --- a/modules/shell/tools.nix +++ b/modules/shell/tools.nix @@ -57,7 +57,7 @@ in }; }; ${shellType} = { - shellAliases = { + shellAliases = inputs.self.lib.mergeAliases inputs.self.lib.commonAliases { cd = "z"; hh = "hstr"; ls = "eza --icons --group-directories-first"; @@ -70,26 +70,17 @@ in uniq --count | sort -rn''; }; } - // ( - if shellType == "bash" then - { - initExtra = '' - if command -v fzf-share >/dev/null; then - source "$(fzf-share)/key-bindings.bash" - source "$(fzf-share)/completion.bash" - fi - ''; - } - else - { - initContent = '' - if command -v fzf-share >/dev/null; then - source "$(fzf-share)/key-bindings.bash" - source "$(fzf-share)/completion.bash" - fi - ''; - } - ); + // inputs.self.lib.shellConditional shellType '' + if command -v fzf-share >/dev/null; then + source "$(fzf-share)/key-bindings.bash" + source "$(fzf-share)/completion.bash" + fi + '' '' + if command -v fzf-share >/dev/null; then + source "$(fzf-share)/key-bindings.bash" + source "$(fzf-share)/completion.bash" + fi + ''; }; programs = { starship.enable = true; diff --git a/parts/core.nix b/parts/core.nix index aec4a3f..69ab957 100644 --- a/parts/core.nix +++ b/parts/core.nix @@ -192,6 +192,12 @@ in |> builtins.filter ( name: !(lib.hasPrefix "wg-" name) && name != "vps" && name != "router" && name != hostName ); + shellConditional = shellType: bashContent: zshContent: + if shellType == "bash" then + { initExtra = bashContent; } + else + { initContent = zshContent; }; + mergeAliases = baseAliases: extraAliases: baseAliases // extraAliases; }; }; }