2023-02-11 00:08:58 +01:00
|
|
|
{ lib, pkgs, config, ... }:
|
2023-02-12 23:33:57 +01:00
|
|
|
|
2023-02-11 00:08:58 +01:00
|
|
|
let
|
|
|
|
cfg = config.reo101.shell;
|
2023-09-06 20:55:36 +02:00
|
|
|
|
2023-07-13 13:26:37 +02:00
|
|
|
inherit (lib)
|
|
|
|
mkEnableOption mkOption types
|
2023-09-06 20:55:36 +02:00
|
|
|
mkIf optionals optionalString
|
|
|
|
mkMerge;
|
|
|
|
|
|
|
|
shellAliases = {
|
|
|
|
cp = "${pkgs.advcpmv}/bin/advcp -rvi";
|
|
|
|
mv = "${pkgs.advcpmv}/bin/advmv -vi";
|
|
|
|
rebuild = let
|
|
|
|
rebuild_script = pkgs.writeShellScript "rebuild" ''
|
|
|
|
${
|
|
|
|
let
|
|
|
|
inherit (lib.strings)
|
|
|
|
hasInfix;
|
|
|
|
inherit (pkgs.hostPlatform)
|
|
|
|
isx86_64 isAarch64
|
|
|
|
isLinux isDarwin;
|
|
|
|
in
|
|
|
|
if isx86_64 && isLinux then
|
|
|
|
"sudo --validate && sudo nixos-rebuild"
|
|
|
|
else if isDarwin then
|
|
|
|
"darwin-rebuild"
|
|
|
|
else if isAarch64 then
|
|
|
|
"nix-on-droid"
|
|
|
|
else
|
|
|
|
"home-manager"
|
|
|
|
} --flake ${
|
|
|
|
if cfg.hostname != null
|
|
|
|
then "${cfg.flakePath}#${cfg.hostname}"
|
|
|
|
else "${cfg.flakePath}"
|
|
|
|
} ''$''\{1:-switch''\} "''$''\{@:2''\}" |& nix run nixpkgs#nix-output-monitor
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
"${rebuild_script}";
|
|
|
|
};
|
2023-02-12 23:33:57 +01:00
|
|
|
in
|
|
|
|
{
|
2023-02-17 01:47:22 +01:00
|
|
|
imports =
|
|
|
|
[
|
|
|
|
];
|
2023-02-11 00:08:58 +01:00
|
|
|
|
2023-02-17 01:47:22 +01:00
|
|
|
options =
|
|
|
|
{
|
|
|
|
reo101.shell = {
|
2023-09-06 20:55:36 +02:00
|
|
|
enable = mkEnableOption "reo101 shell setup";
|
2023-02-17 01:47:22 +01:00
|
|
|
username = mkOption {
|
2023-07-26 08:43:14 +02:00
|
|
|
description = "Username to be used (for prompt)";
|
2023-02-17 01:47:22 +01:00
|
|
|
type = types.str;
|
|
|
|
default = "${config.home.username}";
|
|
|
|
};
|
2023-07-26 08:43:14 +02:00
|
|
|
hostname = mkOption {
|
|
|
|
description = "Hostname to be used (for `rebuild`)";
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
};
|
2023-09-06 20:55:36 +02:00
|
|
|
shells = mkOption {
|
|
|
|
description = "Shells to be configured (first one is used for $SHELL)";
|
|
|
|
type =
|
|
|
|
lib.pipe
|
|
|
|
[
|
|
|
|
"nushell"
|
|
|
|
"zsh"
|
|
|
|
]
|
|
|
|
[
|
|
|
|
types.enum
|
|
|
|
types.listOf
|
|
|
|
];
|
|
|
|
default = [ "nushell" "zsh" ];
|
|
|
|
};
|
|
|
|
starship = mkOption {
|
|
|
|
description = "Use starship prompt";
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
};
|
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;
|
|
|
|
};
|
2023-07-23 16:04:31 +02:00
|
|
|
flakePath = mkOption {
|
2023-07-26 08:43:14 +02:00
|
|
|
description = "Flake path (for `rebuild`)";
|
2023-07-23 16:04:31 +02:00
|
|
|
type = types.str;
|
|
|
|
default = "${config.xdg.configHome}/rix101";
|
|
|
|
};
|
2023-02-17 01:47:22 +01:00
|
|
|
};
|
2023-02-11 00:08:58 +01:00
|
|
|
};
|
|
|
|
|
2023-02-17 01:47:22 +01:00
|
|
|
config =
|
|
|
|
mkIf cfg.enable {
|
|
|
|
home.packages = with pkgs;
|
|
|
|
builtins.concatLists [
|
2023-09-06 20:55:36 +02:00
|
|
|
(builtins.map
|
|
|
|
(lib.flip builtins.getAttr pkgs)
|
|
|
|
cfg.shells)
|
|
|
|
(optionals cfg.starship [
|
2023-02-17 01:47:22 +01:00
|
|
|
starship
|
2023-09-06 20:55:36 +02:00
|
|
|
])
|
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
|
|
|
])
|
|
|
|
];
|
|
|
|
|
2023-07-25 22:42:47 +02:00
|
|
|
# Atuin
|
2023-07-26 08:43:14 +02:00
|
|
|
home.file."${config.xdg.configHome}/atuin/config.toml" = mkIf cfg.atuin {
|
2023-12-08 00:19:37 +01:00
|
|
|
# TODO: use pkgs.substituteAll
|
2023-07-25 22:42:47 +02:00
|
|
|
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;
|
|
|
|
|
2023-09-06 20:55:36 +02:00
|
|
|
enableNushellIntegration = builtins.elem "nushell" cfg.shells;
|
|
|
|
enableZshIntegration = builtins.elem "zsh" cfg.shells;
|
|
|
|
|
2023-02-17 01:47:22 +01:00
|
|
|
nix-direnv = {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
};
|
2023-02-11 00:08:58 +01:00
|
|
|
|
2023-07-25 22:42:47 +02:00
|
|
|
# Starship
|
2023-09-06 20:55:36 +02:00
|
|
|
programs.starship = mkIf cfg.starship {
|
2023-07-25 22:42:47 +02:00
|
|
|
enable = true;
|
|
|
|
|
2023-09-06 20:55:36 +02:00
|
|
|
package = pkgs.starship;
|
|
|
|
|
2023-07-26 08:43:14 +02:00
|
|
|
settings = import ./starship.nix {
|
|
|
|
inherit (cfg) username;
|
|
|
|
};
|
2023-07-25 22:42:47 +02:00
|
|
|
};
|
|
|
|
|
2023-09-06 20:55:36 +02:00
|
|
|
# Zoxide
|
|
|
|
programs.zoxide = mkIf cfg.zoxide {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
package = pkgs.zoxide;
|
|
|
|
|
|
|
|
enableNushellIntegration = builtins.elem "nushell" cfg.shells;
|
|
|
|
enableZshIntegration = builtins.elem "zsh" cfg.shells;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Shell
|
2023-07-31 06:55:07 +02:00
|
|
|
home.sessionVariables = {
|
2023-09-06 20:55:36 +02:00
|
|
|
SHELL =
|
|
|
|
let
|
|
|
|
shellPackage = builtins.getAttr (builtins.head cfg.shells) pkgs;
|
|
|
|
in
|
|
|
|
"${shellPackage}/${shellPackage.shellPath}";
|
2023-07-31 06:55:07 +02:00
|
|
|
};
|
|
|
|
|
2023-09-06 20:55:36 +02:00
|
|
|
# Nushell
|
2023-10-23 08:01:07 +02:00
|
|
|
programs.nushell = mkMerge [
|
2023-09-06 20:55:36 +02:00
|
|
|
(mkIf (builtins.elem "nushell" cfg.shells) {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
package = pkgs.nushell;
|
|
|
|
|
|
|
|
configFile.source = ./nushell/config.nu;
|
|
|
|
envFile.source = ./nushell/env.nu;
|
|
|
|
loginFile.source = ./nushell/login.nu;
|
|
|
|
|
|
|
|
inherit shellAliases;
|
|
|
|
|
|
|
|
environmentVariables = {};
|
|
|
|
})
|
|
|
|
(mkIf cfg.atuin {
|
|
|
|
extraEnv = ''
|
|
|
|
let atuin_cache = "${config.xdg.cacheHome}/atuin"
|
|
|
|
if not ($atuin_cache | path exists) {
|
|
|
|
mkdir $atuin_cache
|
|
|
|
}
|
|
|
|
${pkgs.atuin}/bin/atuin init nu | save --force ${config.xdg.cacheHome}/atuin/init.nu
|
|
|
|
'';
|
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
source ${config.xdg.cacheHome}/atuin/init.nu
|
|
|
|
|
|
|
|
# Ctrl-R
|
|
|
|
$env.config = (
|
|
|
|
$env.config | upsert keybindings (
|
|
|
|
$env.config.keybindings
|
|
|
|
| append {
|
|
|
|
name: atuin
|
|
|
|
modifier: control
|
|
|
|
keycode: char_r
|
|
|
|
mode: [emacs, vi_normal, vi_insert]
|
|
|
|
event: { send: executehostcommand cmd: (_atuin_search_cmd) }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Up
|
|
|
|
$env.config = (
|
|
|
|
$env.config | upsert keybindings (
|
|
|
|
$env.config.keybindings
|
|
|
|
| append {
|
|
|
|
name: atuin
|
|
|
|
modifier: none
|
|
|
|
keycode: up
|
|
|
|
mode: [emacs, vi_normal, vi_insert]
|
|
|
|
event: { send: executehostcommand cmd: (_atuin_search_cmd '--shell-up-key-binding') }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
# Zsh
|
|
|
|
programs.zsh = mkIf (builtins.elem "zsh" cfg.shells) {
|
2023-02-17 01:47:22 +01:00
|
|
|
enable = true;
|
2023-07-31 06:55:07 +02:00
|
|
|
package = pkgs.zsh;
|
|
|
|
|
2023-02-17 01:47:22 +01:00
|
|
|
enableCompletion = true;
|
2023-07-31 06:55:07 +02:00
|
|
|
|
2023-07-13 13:26:37 +02:00
|
|
|
dotDir = ".config/zsh";
|
2023-02-11 00:08:58 +01:00
|
|
|
|
2023-09-06 20:55:36 +02:00
|
|
|
shellAliases = shellAliases // {
|
2023-07-13 13:26:37 +02:00
|
|
|
ls = "${pkgs.lsd}/bin/lsd";
|
|
|
|
mkdir = "mkdir -vp";
|
2023-02-17 01:47:22 +01:00
|
|
|
};
|
2023-02-11 00:08:58 +01:00
|
|
|
|
2023-02-17 01:47:22 +01:00
|
|
|
history = {
|
|
|
|
size = 10000;
|
|
|
|
path = "${config.xdg.dataHome}/zsh/history";
|
|
|
|
};
|
2023-02-11 00:08:58 +01:00
|
|
|
|
2023-02-17 01:47:22 +01:00
|
|
|
initExtra =
|
|
|
|
builtins.concatStringsSep "\n"
|
|
|
|
[
|
2023-07-13 13:26:37 +02:00
|
|
|
''
|
2023-09-06 20:55:36 +02:00
|
|
|
function take() {
|
|
|
|
mkdir -p "''$''\{@''\}" && cd "''$''\{@''\}"
|
2023-07-13 13:26:37 +02:00
|
|
|
}
|
|
|
|
''
|
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() {
|
2023-07-13 13:26:37 +02:00
|
|
|
# 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-09-06 20:55:36 +02:00
|
|
|
# NOTE: done by `programs.zoxide`
|
|
|
|
# (optionalString cfg.zoxide ''
|
|
|
|
# eval "$(${pkgs.zoxide}/bin/zoxide init zsh)"
|
|
|
|
# '')
|
|
|
|
# cfg.extraConfig
|
2023-02-17 01:47:22 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
plugins = [
|
|
|
|
{
|
|
|
|
name = "zsh-nix-shell";
|
|
|
|
file = "nix-shell.plugin.zsh";
|
|
|
|
src = pkgs.fetchFromGitHub {
|
|
|
|
owner = "chisui";
|
|
|
|
repo = "zsh-nix-shell";
|
2023-07-13 13:26:37 +02:00
|
|
|
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";
|
2023-07-13 13:26:37 +02:00
|
|
|
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";
|
2023-07-13 13:26:37 +02:00
|
|
|
rev = "1bda23100e8d140a19be0eed67395c64f6a6074c";
|
|
|
|
sha256 = "sha256-3arAa5EBG+U9cCauChX9K0KF3hkd+t04/trlWKk/gOw=";
|
2023-02-17 01:47:22 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2023-02-11 00:08:58 +01:00
|
|
|
};
|
2023-02-12 23:33:57 +01:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = with lib.maintainers; [ reo101 ];
|
|
|
|
};
|
2023-02-11 00:08:58 +01:00
|
|
|
}
|