rix101/modules/home-manager/reo101-shell/default.nix

199 lines
5.5 KiB
Nix
Raw Normal View History

{ lib, pkgs, config, ... }:
let
cfg = config.reo101.shell;
inherit (lib)
mkEnableOption mkOption types
mkIf optionals optionalString;
in
{
2023-02-17 01:47:22 +01:00
imports =
[
];
2023-02-17 01:47:22 +01:00
options =
{
reo101.shell = {
enable = mkEnableOption "reo101 zsh setup";
username = mkOption {
description = "Username to be used in prompt";
type = types.str;
default = "${config.home.username}";
};
2023-05-12 23:17:07 +02:00
atuin = mkOption {
description = "Integrate with atuin";
type = types.bool;
default = true;
};
2023-02-17 01:47:22 +01:00
direnv = mkOption {
description = "Integrate with direnv";
type = types.bool;
default = true;
};
zoxide = mkOption {
description = "Integrate with zoxide";
type = types.bool;
default = true;
};
flakePath = mkOption {
description = "Flake path (used for `rebuild` command)";
type = types.str;
default = "${config.xdg.configHome}/rix101";
};
2023-02-17 01:47:22 +01:00
extraConfig = mkOption {
description = "Extra zsh config";
type = types.str;
2023-02-17 01:47:22 +01:00
default = ''
'';
2023-02-17 01:47:22 +01:00
};
};
};
2023-02-17 01:47:22 +01:00
config =
mkIf cfg.enable {
home.packages = with pkgs;
builtins.concatLists [
[
zsh
starship
]
2023-05-12 23:17:07 +02:00
(optionals cfg.atuin [
atuin
])
2023-02-17 01:47:22 +01:00
(optionals cfg.direnv [
2023-05-12 23:17:07 +02:00
direnv
2023-02-17 01:47:22 +01:00
])
(optionals cfg.zoxide [
2023-05-12 23:17:07 +02:00
zoxide
2023-02-17 01:47:22 +01:00
])
];
# Atuin
home.file."${config.xdg.configHome}/config.toml" = mkIf cfg.atuin {
text = import ./atuin.nix {
keyPath = "${config.xdg.dataHome}/atuin/key";
};
};
# Direnv
2023-02-17 01:47:22 +01:00
programs.direnv = mkIf cfg.direnv {
enable = true;
nix-direnv = {
enable = true;
};
};
# Starship
programs.starship = {
enable = true;
settings = import ./starship.nix { username = cfg.username; };
};
# Zsh
2023-02-17 01:47:22 +01:00
programs.zsh = {
enable = true;
enableCompletion = true;
dotDir = ".config/zsh";
2023-02-17 01:47:22 +01:00
shellAliases = {
ls = "${pkgs.lsd}/bin/lsd";
cp = "${pkgs.advcpmv}/bin/advcp -rvi";
mv = "${pkgs.advcpmv}/bin/advmv -vi";
mkdir = "mkdir -vp";
2023-02-17 01:47:22 +01:00
};
2023-02-17 01:47:22 +01:00
history = {
size = 10000;
path = "${config.xdg.dataHome}/zsh/history";
};
2023-02-17 01:47:22 +01:00
initExtra =
builtins.concatStringsSep "\n"
[
''
rebuild () {
${
let
inherit (lib.strings) hasInfix;
in
if hasInfix "nixos" pkgs.system then
"sudo --validate && sudo nixos-rebuild"
else if hasInfix "darwin" pkgs.system then
"darwin-rebuild"
else if "aarch64-linux" == pkgs.system then
"nix-on-droid"
else
"home-manager"
} --flake ${cfg.flakePath} ''$''\{1:-switch''\} |& nix run nixpkgs#nix-output-monitor
}
''
2023-05-12 23:17:07 +02:00
(optionalString cfg.atuin ''
export ATUIN_NOBIND="true"
eval "$(${pkgs.atuin}/bin/atuin init zsh)"
function zvm_after_init() {
# bindkey "^r" _atuin_search_widget
zvm_bindkey viins "^R" _atuin_search_widget
2023-05-12 23:17:07 +02:00
}
2023-02-17 01:47:22 +01:00
'')
2023-05-12 23:17:07 +02:00
# NOTE: done by `programs.direnv`
# (optionalString cfg.direnv ''
# eval "$(${pkgs.direnv}/bin/direnv hook zsh)"
# '')
2023-02-17 01:47:22 +01:00
(optionalString cfg.zoxide ''
2023-05-12 23:17:07 +02:00
eval "$(${pkgs.zoxide}/bin/zoxide init zsh)"
2023-02-17 01:47:22 +01:00
'')
cfg.extraConfig
];
plugins = [
{
name = "zsh-nix-shell";
file = "nix-shell.plugin.zsh";
src = pkgs.fetchFromGitHub {
owner = "chisui";
repo = "zsh-nix-shell";
rev = "v0.7.0";
sha256 = "sha256-oQpYKBt0gmOSBgay2HgbXiDoZo5FoUKwyHSlUrOAP5E=";
2023-02-17 01:47:22 +01:00
};
}
{
name = "fast-syntax-highlighting";
2023-04-17 10:44:54 +02:00
file = "fast-syntax-highlighting.plugin.zsh";
2023-02-17 01:47:22 +01:00
src = pkgs.fetchFromGitHub {
2023-04-17 10:44:54 +02:00
owner = "zdharma-continuum";
2023-02-17 01:47:22 +01:00
repo = "fast-syntax-highlighting";
rev = "cf318e06a9b7c9f2219d78f41b46fa6e06011fd9";
sha256 = "sha256-RVX9ZSzjBW3LpFs2W86lKI6vtcvDWP6EPxzeTcRZua4=";
};
}
{
name = "zsh-autosuggestions";
file = "zsh-autosuggestions.plugin.zsh";
src = pkgs.fetchFromGitHub {
owner = "zsh-users";
repo = "zsh-autosuggestions";
rev = "a411ef3e0992d4839f0732ebeb9823024afaaaa8";
sha256 = "sha256-KLUYpUu4DHRumQZ3w59m9aTW6TBKMCXl2UcKi4uMd7w=";
2023-02-17 01:47:22 +01:00
};
}
{
name = "zsh-vi-mode";
file = "zsh-vi-mode.plugin.zsh";
src = pkgs.fetchFromGitHub {
owner = "jeffreytse";
repo = "zsh-vi-mode";
rev = "1bda23100e8d140a19be0eed67395c64f6a6074c";
sha256 = "sha256-3arAa5EBG+U9cCauChX9K0KF3hkd+t04/trlWKk/gOw=";
2023-02-17 01:47:22 +01:00
};
}
];
};
};
meta = {
maintainers = with lib.maintainers; [ reo101 ];
};
}