refactor fish.nix

This commit is contained in:
krizej 2024-10-16 14:07:58 +02:00
parent e893ff6a39
commit 0d4b6f0107
3 changed files with 51 additions and 29 deletions

View file

@ -38,7 +38,6 @@
pamixer
sqlitebrowser
obs-studio
yt-dlp
aseprite
cloc
viu

View file

@ -1,51 +1,64 @@
{ lib, pkgs, config, hostname, ... }: let
inherit (lib) mkIf mkEnableOption mkOption types mergeAttrs;
{ lib, pkgs, config, ... }: let
inherit (lib) mkIf mkEnableOption mkOption types;
cfg = config.chuj.stuff.fish;
user = config.chuj.system.user;
in {
options.chuj.stuff.fish = {
enable = mkEnableOption "fish";
extraAliases = mkOption {
aliases = mkOption {
type = types.attrs;
default = {};
};
abbrs = mkOption {
type = types.attrs;
default = {};
};
functions = mkOption {
type = types.attrs;
default = {};
};
};
config = let
XDG_DATA_HOME = config.home-manager.users.${user}.xdg.dataHome;
in mkIf cfg.enable {
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.fish ];
programs.fish.enable = true;
users.users.${user}.shell = pkgs.fish;
programs.fish.promptInit = ''
${pkgs.any-nix-shell}/bin/any-nix-shell fish --info-right | source
${lib.getExe pkgs.any-nix-shell} fish --info-right | source
'';
home-manager.users.${user}.programs.fish = {
enable = true;
# todo: move some to abbrs
shellAliases = mergeAttrs {
"ls" = "${pkgs.eza}/bin/eza -lhs type";
shellAliases = let
XDG_DATA_HOME = config.home-manager.users.${user}.xdg.dataHome;
yt-dlp = lib.getExe pkgs.yt-dlp;
curl = lib.getExe pkgs.curl;
wget = lib.getExe pkgs.wget;
xclip = lib.getExe pkgs.xclip;
in {
"ytmp3" = "${yt-dlp} -o '%(title)s.%(ext)s' -x --audio-format mp3";
"myip" = "${curl} ifconfig.me";
"wget" = "${wget} --hsts-file='${XDG_DATA_HOME}/wget-hsts'";
"2clip" = "${xclip} -selection clipboard";
} // cfg.aliases;
shellAbbrs = {
"ls" = "eza -lhs type";
"cp" = "cp -v";
"mv" = "mv -v";
"ytmp3" = "yt-dlp -o '%(title)s.%(ext)s' -x --audio-format mp3";
"myip" = "curl ifconfig.me";
"0x0" = ''curl -F"file=@$argv" https://0x0.st'';
"wget" = "${pkgs.wget}/bin/wget --hsts-file='${XDG_DATA_HOME}/wget-hsts'";
} // cfg.abbrs;
# ulimit -n 4096 fixes the "too many open files" error i get sometimes when
# updating the entire flake
"rebuild" = "ulimit -n 4096 && sudo nixos-rebuild switch --flake ~/nix#${hostname} -v";
} cfg.extraAliases;
shellAbbrs = { # todo: mkif xclip in pkgs
"2clip" = "xclip -selection clipboard";
};
functions = {
"fish_greeting" = "${(pkgs.fortune.override { withOffensive = true; })}/bin/fortune";
functions = let
readlink = lib.getExe' pkgs.coreutils "readlink";
which = lib.getExe pkgs.which;
curl = lib.getExe pkgs.curl;
fortune = lib.getExe (pkgs.fortune.override { withOffensive = true; });
in {
"WHICH" = "${readlink} -f $(${which} $argv[1])";
"0x0" = ''${curl} -F"file=@$argv[1]" https://0x0.st'';
"fish_greeting" = "${fortune}";
"fish_prompt" = ''
# name: Informative Vcs
# author: Mariusz Smykula <mariuszs at gmail.com>
@ -112,7 +125,7 @@ in {
echo -n "$suffix "
# end
'';
};
} // cfg.functions;
};
};
}

View file

@ -1,4 +1,4 @@
{ lib, pkgs, config, ... } @ args: let
{ lib, pkgs, config, hostname, ... } @ args: let
inherit (lib) mkOption types;
cfg = config.chuj.system;
in {
@ -57,7 +57,10 @@ in {
'';
};
environment.systemPackages = with pkgs; [
environment.systemPackages = with pkgs; let
nixos-rebuild = lib.getExe pkgs.nixos-rebuild;
sudo = "/run/wrappers/bin/sudo"; # is this correct
in [
ed # is the standard text editor.
ripgrep
@ -65,6 +68,7 @@ in {
tree
btop
wget
eza
zip
unzip
@ -76,6 +80,12 @@ in {
gcc
gnumake
python311
(writeShellScriptBin "rebuild" ''
set -e
ulimit -n 4096 # this fixes the "too many open files" error
${sudo} ${nixos-rebuild} switch --flake ~/nix#${hostname} -v
'')
];
};
}