From ac9918c75960fad578ba224fe7e022e2d4ce7424 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Sun, 17 Dec 2023 13:59:09 +0800 Subject: [PATCH] wip: modularize home-manager --- flake.nix | 1 + home/xin/calcite/default.nix | 7 +++ home/xin/common/default.nix | 9 +--- home/xin/common/fish.nix | 37 --------------- home/xin/common/git.nix | 13 ------ home/xin/common/vim.nix | 32 ------------- home/xin/common/zellij.nix | 28 ------------ machines/calcite/configuration.nix | 1 - modules/home-manager/default.nix | 9 +++- modules/home-manager/fish.nix | 72 ++++++++++++++++++++++++++++++ modules/home-manager/git.nix | 26 +++++++++++ modules/home-manager/tmux.nix | 1 + modules/home-manager/vim.nix | 43 ++++++++++++++++++ modules/home-manager/zellij.nix | 40 +++++++++++++++++ 14 files changed, 200 insertions(+), 119 deletions(-) delete mode 100644 home/xin/common/fish.nix delete mode 100644 home/xin/common/git.nix delete mode 100644 home/xin/common/vim.nix delete mode 100644 home/xin/common/zellij.nix create mode 100644 modules/home-manager/fish.nix create mode 100644 modules/home-manager/git.nix create mode 100644 modules/home-manager/tmux.nix create mode 100644 modules/home-manager/vim.nix create mode 100644 modules/home-manager/zellij.nix diff --git a/flake.nix b/flake.nix index d89b9ae..e15efa8 100644 --- a/flake.nix +++ b/flake.nix @@ -63,6 +63,7 @@ home-manager.users.xin = import ./home/${user}/${host}; home-manager.extraSpecialArgs = { inherit inputs system; }; } + self.homeManagerModules ]; }; mkNixos = { system, modules, specialArgs ? {}}: nixpkgs.lib.nixosSystem { diff --git a/home/xin/calcite/default.nix b/home/xin/calcite/default.nix index 94e3d77..544e438 100644 --- a/home/xin/calcite/default.nix +++ b/home/xin/calcite/default.nix @@ -34,4 +34,11 @@ thunderbird remmina ]; + + # custom-hm = { + # fish = { enable = true; }; + # git = { enable = true; }; + # neovim = { enable = true; }; + # zellij = { enable = true; }; + # }; } diff --git a/home/xin/common/default.nix b/home/xin/common/default.nix index c76d3e8..0e0677c 100644 --- a/home/xin/common/default.nix +++ b/home/xin/common/default.nix @@ -1,10 +1,5 @@ -{ pkgs, ... }: { - imports = [ - ./fish.nix - ./git.nix - ./zellij.nix - ./vim.nix - ]; +{ inputs, pkgs, ... }: { + imports = [ ]; home.packages = with pkgs; [ dig diff --git a/home/xin/common/fish.nix b/home/xin/common/fish.nix deleted file mode 100644 index 7d8fecb..0000000 --- a/home/xin/common/fish.nix +++ /dev/null @@ -1,37 +0,0 @@ -{ pkgs, ... }: { - programs.fish = { - enable = true; - plugins = with pkgs; [ - { - name = "pisces"; - src = fishPlugins.pisces.src; - } - { - name = "done"; - src = fishPlugins.done.src; - } - { - name = "hydro"; - src = fishPlugins.hydro.src; - } - ]; - interactiveShellInit = '' - fish_config theme choose 'ayu Dark' - fish_config prompt choose arrow - ${pkgs.nix-your-shell}/bin/nix-your-shell fish | source - function fish_right_prompt - if test -n "$IN_NIX_SHELL" - echo -n "" - else if test $SHLVL -ge 3 - echo -n "<🚀lv$SHLVL>" - end - end - function fish_command_not_found - ${pkgs.comma}/bin/comma $argv - end - ''; - functions = { - gitignore = "curl -sL https://www.gitignore.io/api/$argv"; - }; - }; -} diff --git a/home/xin/common/git.nix b/home/xin/common/git.nix deleted file mode 100644 index 98c2e84..0000000 --- a/home/xin/common/git.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ - programs.git = { - enable = true; - delta.enable = true; - userName = "Xinyang Li"; - userEmail = "lixinyang411@gmail.com"; - aliases = { - graph = "log --all --oneline --graph --decorate"; - s = "status"; - d = "diff"; - }; - }; -} \ No newline at end of file diff --git a/home/xin/common/vim.nix b/home/xin/common/vim.nix deleted file mode 100644 index f73228d..0000000 --- a/home/xin/common/vim.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ pkgs, ... }: { - programs.neovim = { - enable = true; - vimAlias = true; - vimdiffAlias = true; - plugins = with pkgs.vimPlugins; [ - nvim-treesitter.withAllGrammars - dracula-nvim - ]; - extraConfig = '' - set nocompatible - - syntax on - set number - set relativenumber - set shortmess+=I - set laststatus=2 - - set ignorecase - set smartcase - set list - set listchars=tab:→· - set tabstop=4 - set shiftwidth=4 - set expandtab - - set mouse+=a - - colorscheme dracula - ''; -}; -} diff --git a/home/xin/common/zellij.nix b/home/xin/common/zellij.nix deleted file mode 100644 index e485d11..0000000 --- a/home/xin/common/zellij.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ - programs.zellij = { - enable = true; - settings = { - default_shell = "fish"; - keybinds = { - unbind = [ - "Ctrl p" - "Ctrl n" - ]; - }; - theme = "dracula"; - themes.dracula = { - fg = [ 248 248 242 ]; - bg = [ 40 42 54 ]; - black = [ 0 0 0 ]; - red = [ 255 85 85 ]; - green = [ 80 250 123 ]; - yellow = [ 241 250 140 ]; - blue = [ 98 114 164 ]; - magenta = [ 255 121 198 ]; - cyan = [ 139 233 253 ]; - white = [ 255 255 255 ]; - orange = [ 255 184 108 ]; - }; - }; - }; -} diff --git a/machines/calcite/configuration.nix b/machines/calcite/configuration.nix index 1871c6d..7017de9 100644 --- a/machines/calcite/configuration.nix +++ b/machines/calcite/configuration.nix @@ -189,7 +189,6 @@ gnomeExtensions.paperwm gnomeExtensions.search-light gnomeExtensions.tray-icons-reloaded - gnomeExtensions.gsconnect gnome.gnome-tweaks gthumb diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix index 0e0dcd2..6ab8a89 100644 --- a/modules/home-manager/default.nix +++ b/modules/home-manager/default.nix @@ -1,3 +1,10 @@ +{ config, pkgs, ... }: { - + imports = [ + ./fish.nix + ./git.nix + ./tmux.nix + ./vim.nix + ./zellij.nix + ]; } \ No newline at end of file diff --git a/modules/home-manager/fish.nix b/modules/home-manager/fish.nix new file mode 100644 index 0000000..54dda10 --- /dev/null +++ b/modules/home-manager/fish.nix @@ -0,0 +1,72 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.custom-hm.fish; +in +{ + options = { + enable = mkEnableOption "fish"; + plugins = mkOption { + type = types.listOf types.str; + default = [ "pisces" "done" "hydro" ]; + }; + functions = { + enable = mkOption { + type = types.bool; + default = true; + }; + }; + alias = { + enable = mkOption { + type = types.bool; + default = true; + }; + }; + }; + + config = { + programs.fish = mkIf cfg.enable { + enable = true; + plugins = with pkgs; filter ( + e: hasAttr e.name builtins.listToAttrs # { "xxx" = true; } + (map (p: { name = p; value = true; }) cfg.plugins) # { name = "xxx"; value = true; } + ) [ + { + name = "pisces"; + src = fishPlugins.pisces.src; + } + { + name = "done"; + src = fishPlugins.done.src; + } + { + name = "hydro"; + src = fishPlugins.hydro.src; + } + ]; + interactiveShellInit = let + extraInit = if cfg.functions.enable then '' + ${pkgs.nix-your-shell}/bin/nix-your-shell fish | source + function fish_right_prompt + if test -n "$IN_NIX_SHELL" + echo -n "" + else if test $SHLVL -ge 3 + echo -n "<🚀lv$SHLVL>" + end + end + function fish_command_not_found + ${pkgs.comma}/bin/comma $argv + end + '' else ""; + in '' + fish_config theme choose 'ayu Dark' + fish_config prompt choose arrow + '' + extraInit; + functions = mkIf cfg.functions.enable { + gitignore = "curl -sL https://www.gitignore.io/api/$argv"; + }; + }; + }; +} diff --git a/modules/home-manager/git.nix b/modules/home-manager/git.nix new file mode 100644 index 0000000..2eefe65 --- /dev/null +++ b/modules/home-manager/git.nix @@ -0,0 +1,26 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.custom-hm.git; +in +{ + options = { + enable = mkEnableOption "Enable git configuration"; + }; + config = { + programs.git = { + enable = true; + delta.enable = true; + userName = "Xinyang Li"; + userEmail = "lixinyang411@gmail.com"; + aliases = { + graph = "log --all --oneline --graph --decorate"; + a = "add"; + d = "diff"; + s = "status"; + }; + }; + }; +} \ No newline at end of file diff --git a/modules/home-manager/tmux.nix b/modules/home-manager/tmux.nix new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/modules/home-manager/tmux.nix @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/modules/home-manager/vim.nix b/modules/home-manager/vim.nix new file mode 100644 index 0000000..0c1f886 --- /dev/null +++ b/modules/home-manager/vim.nix @@ -0,0 +1,43 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.custom-hm.neovim; +in +{ + options = { + enable = mkEnableOption "neovim configurations"; + }; + config = mkIf cfg.enable { + programs.neovim = { + enable = true; + vimAlias = true; + vimdiffAlias = true; + plugins = with pkgs.vimPlugins; [ + catppuccin-nvim + ]; + extraConfig = '' + set nocompatible + + syntax on + set number + set relativenumber + set shortmess+=I + set laststatus=2 + + set ignorecase + set smartcase + set list + set listchars=tab:→· + set tabstop=4 + set shiftwidth=4 + set expandtab + + set mouse+=a + + colorscheme catppuccin-macchiato + ''; + }; + }; +} diff --git a/modules/home-manager/zellij.nix b/modules/home-manager/zellij.nix new file mode 100644 index 0000000..b795130 --- /dev/null +++ b/modules/home-manager/zellij.nix @@ -0,0 +1,40 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.custom-hm.zellij; +in +{ + options = { + enable = mkEnableOption "zellij configurations"; + }; + config = { + programs.zellij = mkIf cfg.enable { + enable = true; + settings = { + default_shell = "fish"; + keybinds = { + unbind = [ + "Ctrl p" + "Ctrl n" + ]; + }; + theme = "catppuccin-macchiato"; + themes.dracula = { + fg = [ 248 248 242 ]; + bg = [ 40 42 54 ]; + black = [ 0 0 0 ]; + red = [ 255 85 85 ]; + green = [ 80 250 123 ]; + yellow = [ 241 250 140 ]; + blue = [ 98 114 164 ]; + magenta = [ 255 121 198 ]; + cyan = [ 139 233 253 ]; + white = [ 255 255 255 ]; + orange = [ 255 184 108 ]; + }; + }; + }; + }; +}