Skip to content

Commit

Permalink
feat(home): use package override to get fish working on non nixos system
Browse files Browse the repository at this point in the history
Signed-off-by: budimanjojo <[email protected]>
  • Loading branch information
budimanjojo committed Aug 24, 2024
1 parent 2041fa2 commit 00f515a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
15 changes: 15 additions & 0 deletions chezmoi/.chezmoiscripts/run_once_after_90-cleanup.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ function not_needed_directory () {
fi
}

function not_needed_file() {
local file=$1
if [ -f "$file" ]; then
if [ "$EUID" -ne 0 ]; then
sudo rm "$file"
echo "deleted $file, not needed anymore"
else
rm "$file"
echo "deleted $file, not needed anymore"
fi
fi
}

not_needed_executable "kubectl" "{{ .chezmoi.homeDir }}/.local/bin"
not_needed_executable "flux" "{{ .chezmoi.homeDir }}/.local/bin"
not_needed_executable "kustomize" "/usr/local/bin"
Expand All @@ -61,6 +74,8 @@ not_needed_executable "node" "/usr/local/bin"
not_needed_directory "{{ .chezmoi.homeDir }}/.local/share/nvim/lsp_servers"
not_needed_directory "{{ .chezmoi.homeDir }}/.local/share/aquaproj-aqua"

not_needed_file "{{ .chezmoi.homeDir }}/.config/fish/conf.d/nix.fish"

if [ "$(command -v brew)" ]; then
echo "uninstalling brew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
Expand Down
26 changes: 0 additions & 26 deletions chezmoi/.chezmoiscripts/run_once_before_10-setup-fish.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,8 @@ set_default_shell() {
fi
}

fish_source_lines() {
cat <<EOF
# Nix
if test -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.fish'
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.fish'
end

EOF
}

ensure_nix_fish_profile_sourced() {
if [ ! -f "{{ .chezmoi.homeDir }}/.config/fish/conf.d/nix.fish" ]; then
local target_dir="{{ .chezmoi.homeDir }}/.config/fish/conf.d"
mkdir -p "$target_dir"
echo "Writing nix.fish file to $target_dir"
fish_source_lines | tee "$target_dir/nix.fish" >/dev/null
fi
}

# Set fish as default shell
set_default_shell

# Nix official installer doesn't handle fish shell Nix integration properly
# when the operating system doesn't have fish installed in the system beforehand
# This is not the case with Detsys installer (at least in Ubuntu)
# Because the provided `nix-daemon.fish` is idempotent anyway
# so there's no harm in handling it ourselves in case the installer fails to do it
ensure_nix_fish_profile_sourced

echo -e "\0033[0;32m>>>>> Finish Setting Up Fish Shell <<<<<\033[0m"
{{ end -}}
27 changes: 23 additions & 4 deletions home/_modules/shell/fish/default.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{
config,
lib,
config,
osConfig,
pkgs,
myPkgs,
...
}:
let
inherit (lib) myLib mkEnableOption mkIf;

cfg = config.myHome.shell.fish;
isNixos = myLib.isNixos osConfig;
in
{
options.myHome.shell.fish = {
enable = lib.mkEnableOption "fish shell";
enable = mkEnableOption "fish shell";
};

config = lib.mkIf (cfg.enable) {
config = mkIf (cfg.enable) {
myHome.shell = {
dircolors.enable = true;
starship.enable = true;
Expand All @@ -22,6 +26,21 @@ in
programs = {
fish = {
enable = true;
package = mkIf (!isNixos) (
pkgs.fish.override {
fishEnvPreInit = ''
# This will ensure that $NIX_PROFILE variable is set as fast as possible
# so Nix managed programs can work properly without needing to tweak the OS.
# Usually this is done by Nix installer by putting these lines inside fish system config dir
# but it's a hit or miss especially when fish is not installed in the system beforehand.
# And I also found problem that vendor completion of Nix installed programs are not working
# without calling fish twice, I assume it's because $NIX_PROFILE is not set fast enough
if test -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.fish'
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.fish'
end
'';
}
);
plugins =
with pkgs.fishPlugins;
[
Expand All @@ -44,7 +63,7 @@ in
}
]
++ [
(lib.mkIf (config.programs.tmux.enable && !config.programs.zellij.enable) {
(mkIf (config.programs.tmux.enable && !config.programs.zellij.enable) {
name = "tmux-fish";
src = myPkgs.fish-plugins.tmux-fish.src;
})
Expand Down

0 comments on commit 00f515a

Please sign in to comment.