Skip to content

Commit

Permalink
Split nix definitions by the shells and packages (#223)
Browse files Browse the repository at this point in the history
* Split nix definitions by the shells and packages

* Refactor with the specific files

* Add an empty commit
  • Loading branch information
kachick committed Jul 31, 2023
1 parent d1bbfe3 commit 082c426
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 284 deletions.
53 changes: 53 additions & 0 deletions home/.config/home-manager/fish.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{ pkgs, ... }:

{
xdg.configFile."fish/fish_variables".source = ../fish/fish_variables;
xdg.configFile."fish/functions/fish_prompt.fish".source = ../fish/functions/fish_prompt.fish;

programs.fish = {
enable = true;

shellInit =
''
switch (uname -s)
case Linux
# Keep this comment
case Darwin
# nix
# https://github.com/NixOS/nix/issues/2280
if test -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fenv source '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
end
case FreeBSD NetBSD DragonFly
# Keep this comment
case '*'
# Keep this comment
end
# nix
if test -e "$HOME/.nix-profile/etc/profile.d/nix.sh"
fenv source "$HOME/.nix-profile/etc/profile.d/nix.sh"
end
# home-manager
if test -e "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
fenv source "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
end
# starship
if status is-interactive
starship init fish | source
end
'';

plugins = [{
name = "foreign-env";
src = pkgs.fetchFromGitHub {
owner = "oh-my-fish";
repo = "plugin-foreign-env";
rev = "3ee95536106c11073d6ff466c1681cde31001383";
sha256 = "sha256-vyW/X2lLjsieMpP9Wi2bZPjReaZBkqUbkh15zOi8T4Y=";
};
}];
};
}
291 changes: 7 additions & 284 deletions home/.config/home-manager/home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
# - How to get sha256? => assume by `lib.fakeSha256`

{
imports = [
./packages.nix
./zsh.nix
./fish.nix
./nushell.nix
];

home.username = lib.mkDefault "kachick";
# TODO: How to cover lima? The default is /home/kachick.local
home.homeDirectory = if pkgs.stdenv.hostPlatform.isDarwin then "/Users/${config.home.username}" else "/home/${config.home.username}";
Expand Down Expand Up @@ -67,53 +74,6 @@
package = pkgs.nix;
};

programs.fish = {
enable = true;

shellInit =
''
switch (uname -s)
case Linux
# Keep this comment
case Darwin
# nix
# https://github.com/NixOS/nix/issues/2280
if test -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fenv source '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
end
case FreeBSD NetBSD DragonFly
# Keep this comment
case '*'
# Keep this comment
end
# nix
if test -e "$HOME/.nix-profile/etc/profile.d/nix.sh"
fenv source "$HOME/.nix-profile/etc/profile.d/nix.sh"
end
# home-manager
if test -e "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
fenv source "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
end
# starship
if status is-interactive
starship init fish | source
end
'';

plugins = [{
name = "foreign-env";
src = pkgs.fetchFromGitHub {
owner = "oh-my-fish";
repo = "plugin-foreign-env";
rev = "3ee95536106c11073d6ff466c1681cde31001383";
sha256 = "sha256-vyW/X2lLjsieMpP9Wi2bZPjReaZBkqUbkh15zOi8T4Y=";
};
}];
};

programs.readline = {
enable = true;
variables = {
Expand All @@ -132,15 +92,10 @@
nix-direnv = {
enable = true;
};

enableZshIntegration = true;
enableNushellIntegration = true;
};

programs.zoxide = {
enable = true;
enableZshIntegration = true;
enableNushellIntegration = true;
};

# https://nixos.wiki/wiki/Home_Manager
Expand All @@ -149,8 +104,6 @@

xdg.configFile."home-manager/home.nix".source = ./home.nix;
xdg.configFile."git/config".source = ../git/config;
xdg.configFile."fish/fish_variables".source = ../fish/fish_variables;
xdg.configFile."fish/functions/fish_prompt.fish".source = ../fish/functions/fish_prompt.fish;
xdg.configFile."alacritty/alacritty.yml".source = ../alacritty/alacritty.yml;

# Not under "starship/starship.toml"
Expand Down Expand Up @@ -193,163 +146,12 @@
irb-power_assert
'';

# https://nixos.wiki/wiki/Zsh
# https://github.com/nix-community/home-manager/blob/master/modules/programs/zsh.nix
programs.zsh = {
enable = true;

# How about to point `xdg.configFile`?
dotDir = ".config/zsh";

history = {
# in memory
size = 100000;

# in file
save = 4200000;
path = "${config.xdg.stateHome}/zsh/history";

ignoreDups = true;
ignoreSpace = true;

extended = true;
share = true;
};

historySubstringSearch = {
enable = true;
};
enableSyntaxHighlighting = true;
enableAutosuggestions = true;
enableCompletion = true;

# home-manager path will set in `programs.home-manager.enable = true`;
envExtra = ''
# https://wiki.archlinux.jp/index.php/XDG_Base_Directory
# https://www.reddit.com/r/zsh/comments/tpwx9t/zcompcache_vs_zcompdump/
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache"
if [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then . "$HOME/.nix-profile/etc/profile.d/nix.sh"; fi # added by Nix installer
'';

initExtra = ''
typeset -g HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='fg=blue,bold'
typeset -g HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'
typeset -g HISTORY_SUBSTRING_SEARCH_FUZZY='true'
setopt correct
unsetopt BEEP
setopt hist_ignore_all_dups
setopt hist_reduce_blanks
setopt hist_save_no_dups
setopt hist_no_store
eval "$($XDG_DATA_HOME/rtx/bin/rtx activate -s zsh)"
case ''${OSTYPE} in
darwin*)
test -e "''${HOME}/.iterm2_shell_integration.zsh" && source "''${HOME}/.iterm2_shell_integration.zsh"
;;
esac
# https://github.com/starship/starship/blob/0d98c4c0b7999f5a8bd6e7db68fd27b0696b3bef/docs/uk-UA/advanced-config/README.md#change-window-title
function set_win_title() {
echo -ne "\033]0; $(basename "$PWD") \007"
}
precmd_functions+=(set_win_title)
zshaddhistory() { whence ''${''${(z)1}[1]} >| /dev/null || return 1 }
'';

# TODO: May move to sessionVariables
profileExtra = ''
if [[ "$OSTYPE" == darwin* ]]; then
export BROWSER='open'
fi
'';
};

programs.nushell = {
enable = true;

# Do not set `shell_integration: true for now`
# - window title requires `shell_integration: true` - https://github.com/nushell/nushell/issues/2527
# - several terminal requires `shell_integration: false` - https://github.com/nushell/nushell/issues/6214
extraConfig = ''
let-env config = {
show_banner: false
keybindings: [
# https://github.com/nushell/nushell/issues/1616#issuecomment-1386714173
{
name: fuzzy_history
modifier: control
keycode: char_r
mode: [emacs, vi_normal, vi_insert]
event: [
{
send: ExecuteHostCommand
cmd: "commandline (
history
| each { |it| $it.command }
| uniq
| reverse
| str join (char -i 0)
| fzf --read0 --layout=reverse --height=40% -q (commandline)
| decode utf-8
| str trim
)"
}
]
}
# Same as above for Up Arrow
{
name: fuzzy_history
modifier: control
keycode: Up
mode: [emacs, vi_normal, vi_insert]
event: [
{
send: ExecuteHostCommand
cmd: "commandline (
history
| each { |it| $it.command }
| uniq
| reverse
| str join (char -i 0)
| fzf --read0 --layout=reverse --height=40% -q (commandline)
| decode utf-8
| str trim
)"
}
]
}
]
}
'';
};

programs.fzf = {
enable = true;

# enableShellIntegration = true;

enableZshIntegration = true;

# enableFishIntegration = true;

# fzf manager does not have nushell integration yet.
# https://github.com/nushell/nushell/issues/1616#issuecomment-1386714173 may help you.
};

programs.starship = {
enable = true;

# enableShellIntegration = true;
enableZshIntegration = true;
# enableFishIntegration = true;
enableNushellIntegration = true;
};

# - Tiny tools by me, they may be rewritten with another language.
Expand All @@ -358,83 +160,4 @@
xdg.dataFile."homemade/bin/updeps".source = ../../../home/.local/share/homemade/bin/updeps.bash;
xdg.dataFile."homemade/bin/la".source = ../../../home/.local/share/homemade/bin/la.bash;
xdg.dataFile."homemade/bin/zj".source = ../../../home/.local/share/homemade/bin/zj.bash;

home.packages = [
pkgs.dprint
pkgs.gitleaks
pkgs.shellcheck
pkgs.shfmt
pkgs.git
pkgs.coreutils
pkgs.tig
pkgs.tree
pkgs.curl
pkgs.wget
pkgs.zsh
# Don't include bash - https://github.com/NixOS/nixpkgs/issues/29960, https://github.com/NixOS/nix/issues/730
# pkgs.bash
pkgs.fish
pkgs.nushell
pkgs.starship
pkgs.jq
pkgs.gh
pkgs.direnv
pkgs.ripgrep
pkgs.fzf
pkgs.exa
pkgs.bat
pkgs.duf
pkgs.fd
pkgs.du-dust
pkgs.procs
pkgs.bottom
pkgs.tig
pkgs.zellij
pkgs.nixpkgs-fmt
pkgs.nil
pkgs.typos
pkgs.hyperfine
pkgs.zoxide
pkgs.difftastic

# Required in many asdf(rtx) plugins
pkgs.unzip

# Includes follows in each repository if needed, not in global
# pkgs.deno
# pkgs.rustup
# pkgs.go
# pkgs.crystal
# pkgs.elmPackages.elm
# pkgs.gcc
# pkgs.sqlite
# pkgs.postgresql
# pkgs.gnumake
# pkgs.cargo-make

# This section is just a note for my strggle
# Often failed to build ruby even if I enabled following dependencies
# pkgs.zlib
# pkgs.libyaml
# pkgs.openssl
#
# Don't include nixpkgs ruby, because of installing into .nix-profile hides
# adhoc use of https://github.com/bobvanderlinden/nixpkgs-ruby
# pkgs.ruby

# As a boardgamer
# pkgs.tesseract
# pkgs.imagemagick
# pkgs.pngquant
# pkgs.img2pdf
# pkgs.ocrmypdf
] ++ (
if pkgs.stdenv.hostPlatform.isDarwin then
[ ]
else
[
# Fix missing locales as `locale: Cannot set LC_CTYPE to default locale`
pkgs.glibc
]
);
}

0 comments on commit 082c426

Please sign in to comment.