From ca42be3f5f44d07212a7ec54a54d9b29d42eaaaa Mon Sep 17 00:00:00 2001 From: pegasust Date: Sat, 10 Dec 2022 18:46:05 -0700 Subject: [PATCH 1/4] more organization for componentizing home-manager conifg --- nix-conf/home-manager/base/default.nix | 8 ++- nix-conf/home-manager/base/git.nix | 81 +++++++++++++++++++++++++- nix-conf/home-manager/base/shells.nix | 1 + nix-conf/home-manager/base/ssh.nix | 1 + nix-conf/home-manager/flake.nix | 8 +-- nix-conf/home-manager/home.nix | 34 ----------- 6 files changed, 92 insertions(+), 41 deletions(-) diff --git a/nix-conf/home-manager/base/default.nix b/nix-conf/home-manager/base/default.nix index 14bdb9b..993686f 100644 --- a/nix-conf/home-manager/base/default.nix +++ b/nix-conf/home-manager/base/default.nix @@ -1,3 +1,9 @@ { - + mkModuleArgs = import ./mkModuleArgs.nix; + modules = [ + ./alacritty.nix + ./git.nix + ./ssh.nix + ./shells.nix + ]; } diff --git a/nix-conf/home-manager/base/git.nix b/nix-conf/home-manager/base/git.nix index 8665a30..8db840b 100644 --- a/nix-conf/home-manager/base/git.nix +++ b/nix-conf/home-manager/base/git.nix @@ -1,3 +1,80 @@ -{ - +{ config +, myLib +, ... }: +let + cfg = config.base.git; + baseAliases = { + a = "add"; + c = "commit"; + ca = "commit --amend"; + cm = "commit -m"; + lol = "log --graph --decorate --pretty=oneline --abbrev-commit"; + lola = "log --graph --decorate --pretty=oneline --abbrev-commit --all"; + sts = "status"; + co = "checkout"; + b = "branch"; + }; +in +{ + options.base.git = { + aliases = myLib.mkOption { + type = myLib.types.attrs; + default = { }; + example = baseAliases; + description = '' + Additional git aliases. This settings comes with base configuration. + Redeclaring the base config will override the values. + ''; # TODO: Add baseAliases as string here (builtins.toString doesn't work) + }; + name = myLib.mkOption { + type = myLib.types.str; + default = "Pegasust"; + description = "Git username that appears on commits"; + example = "Pegasust"; + }; + email = myLib.mkOption { + type = myLib.types.str; + default = "pegasucksgg@gmail.com"; + example = "peagsucksgg@gmail.com"; + description = "Git email that appears on commits"; + }; + ignores = myLib.mkOption { + type = myLib.types.listOf myLib.types.str; + default = [ + ".vscode" # vscode settings + ".direnv" # .envrc cached outputs + ]; + description = '' + .gitignore patterns that are applied in every repository. + This is useful for IDE-specific settings. + ''; + example = [ ".direnv" "node_modules" ]; + }; + enable = myLib.mkOption { + type = myLib.types.bool; + default = true; + description = '' + Enables git + ''; + example = false; + }; + credentialCacheTimeoutSeconds = myLib.mkOption { + type = myLib.types.int; + default = 3000; + description = "Credential cache (in-memory store) for Git in seconds."; + example = 3000; + }; + }; +# TODO : anyway to override configuration? + config.programs.git = { + inherit (cfg) enable ignores; + userName = cfg.name; + userEmail = cfg.email; + aliases = baseAliases // cfg.aliases; + extraConfig = { + credential.helper = "cache --timeout=${builtins.toString cfg.credentialCacheTimeoutSeconds}"; + }; + lfs.enable = true; + }; +} diff --git a/nix-conf/home-manager/base/shells.nix b/nix-conf/home-manager/base/shells.nix index e69de29..0967ef4 100644 --- a/nix-conf/home-manager/base/shells.nix +++ b/nix-conf/home-manager/base/shells.nix @@ -0,0 +1 @@ +{} diff --git a/nix-conf/home-manager/base/ssh.nix b/nix-conf/home-manager/base/ssh.nix index e69de29..0967ef4 100644 --- a/nix-conf/home-manager/base/ssh.nix +++ b/nix-conf/home-manager/base/ssh.nix @@ -0,0 +1 @@ +{} diff --git a/nix-conf/home-manager/flake.nix b/nix-conf/home-manager/flake.nix index 5d2dad1..d6476fd 100644 --- a/nix-conf/home-manager/flake.nix +++ b/nix-conf/home-manager/flake.nix @@ -28,7 +28,8 @@ config = { allowUnfree = true; }; }; # lib = (import ../lib { inherit pkgs; lib = pkgs.lib; }); - mkModuleArgs = import ./base/mkModuleArgs.nix; + base = import ./base; + inherit (base) mkModuleArgs; in { homeConfigurations = @@ -41,7 +42,7 @@ rec { "hungtr" = home-manager.lib.homeManagerConfiguration { inherit pkgs; - modules = [ + modules = base.modules ++ [ ./home.nix ]; # optionally pass inarguments to module @@ -93,9 +94,8 @@ # Personal laptop hwtr = home-manager.lib.homeManagerConfiguration { inherit pkgs; - modules = [ + modules = base.modules ++ [ ./home.nix - ./base/alacritty.nix { base.alacritty.font.family = "BitstreamVeraSansMono Nerd Font"; } diff --git a/nix-conf/home-manager/home.nix b/nix-conf/home-manager/home.nix index 112654f..b77930e 100644 --- a/nix-conf/home-manager/home.nix +++ b/nix-conf/home-manager/home.nix @@ -139,40 +139,6 @@ in }; initExtra = myHome.shellInitExtra or ""; }; - programs.git = { - enable = true; - lfs.enable = true; - aliases = { - a = "add"; - c = "commit"; - ca = "commit --amend"; - cm = "commit -m"; - lol = "log --graph --decorate --pretty=oneline --abbrev-commit"; - lola = "log --graph --decorate --pretty=oneline --abbrev-commit --all"; - sts = "status"; - co = "checkout"; - b = "branch"; - }; - # No idea why this is not appearing in home-manager search - # It's in source code, though - userName = "pegasust"; - userEmail = "pegasucksgg@gmail.com"; - extraConfig = { - merge = { tool = "vimdiff"; conflictstyle = "diff3"; }; - }; - ignores = [ - # vscode-related settings - ".vscode" - # envrc cached outputs - ".direnv" - ]; - extraConfig = { - # cache credential for 50 minutes (a pomodoro session) - credential.helper = "cache --timeout=3000"; - }; - # why is this no longer valid? - # pull = { rebase=true; }; - }; programs.ssh = { enable = true; forwardAgent = true; From ad01a1fd65395a88963f624769adc118796c1db6 Mon Sep 17 00:00:00 2001 From: pegasust Date: Sat, 10 Dec 2022 18:55:34 -0700 Subject: [PATCH 2/4] improv: componentize ssh --- nix-conf/home-manager/base/neovim.nix | 0 nix-conf/home-manager/base/ssh.nix | 23 ++++++++++++++++++++++- nix-conf/home-manager/home.nix | 5 ----- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 nix-conf/home-manager/base/neovim.nix diff --git a/nix-conf/home-manager/base/neovim.nix b/nix-conf/home-manager/base/neovim.nix new file mode 100644 index 0000000..e69de29 diff --git a/nix-conf/home-manager/base/ssh.nix b/nix-conf/home-manager/base/ssh.nix index 0967ef4..435c7bf 100644 --- a/nix-conf/home-manager/base/ssh.nix +++ b/nix-conf/home-manager/base/ssh.nix @@ -1 +1,22 @@ -{} +{ config +, proj_root +, myLib +, ... +}: +let cfg = config.base.ssh; +in +{ + options.base.ssh.enable = myLib.mkOption { + type = myLib.types.bool; + default = true; + example = false; + description = '' + Enables SSH + ''; + }; + config.programs.ssh = { + inherit (cfg) enable; + forwardAgent = true; + extraConfig = builtins.readFile "${proj_root}/ssh/config"; + }; +} diff --git a/nix-conf/home-manager/home.nix b/nix-conf/home-manager/home.nix index b77930e..8b970c9 100644 --- a/nix-conf/home-manager/home.nix +++ b/nix-conf/home-manager/home.nix @@ -139,9 +139,4 @@ in }; initExtra = myHome.shellInitExtra or ""; }; - programs.ssh = { - enable = true; - forwardAgent = true; - extraConfig = builtins.readFile "${proj_root}/ssh/config"; - }; } From 9161d088efe4cfc8b6634aad415c7a8898d07492 Mon Sep 17 00:00:00 2001 From: pegasust Date: Sat, 10 Dec 2022 18:58:30 -0700 Subject: [PATCH 3/4] improv: home-manager away --- nix-conf/home-manager/base/default.nix | 3 +++ nix-conf/home-manager/base/ssh.nix | 1 + nix-conf/home-manager/home.nix | 1 - 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/nix-conf/home-manager/base/default.nix b/nix-conf/home-manager/base/default.nix index 993686f..5621907 100644 --- a/nix-conf/home-manager/base/default.nix +++ b/nix-conf/home-manager/base/default.nix @@ -5,5 +5,8 @@ ./git.nix ./ssh.nix ./shells.nix + { + config.programs.home-manager.enable = true; + } ]; } diff --git a/nix-conf/home-manager/base/ssh.nix b/nix-conf/home-manager/base/ssh.nix index 435c7bf..aedb1e3 100644 --- a/nix-conf/home-manager/base/ssh.nix +++ b/nix-conf/home-manager/base/ssh.nix @@ -20,3 +20,4 @@ in extraConfig = builtins.readFile "${proj_root}/ssh/config"; }; } + diff --git a/nix-conf/home-manager/home.nix b/nix-conf/home-manager/home.nix index 8b970c9..f1acd1b 100644 --- a/nix-conf/home-manager/home.nix +++ b/nix-conf/home-manager/home.nix @@ -98,7 +98,6 @@ in enable = true; enableZshIntegration = true; }; - programs.home-manager.enable = true; programs.fzf.enable = true; programs.neovim = { enable = true; From f1284ba35b7b0b122351bc8d0c369e073db80f9f Mon Sep 17 00:00:00 2001 From: pegasust Date: Sun, 11 Dec 2022 00:34:36 -0700 Subject: [PATCH 4/4] improv: shells.nix module --- nix-conf/home-manager/base/shells.nix | 90 ++++++++++++++++++++++++++- nix-conf/home-manager/flake.nix | 16 +++-- nix-conf/home-manager/home.nix | 49 --------------- 3 files changed, 100 insertions(+), 55 deletions(-) diff --git a/nix-conf/home-manager/base/shells.nix b/nix-conf/home-manager/base/shells.nix index 0967ef4..8f034d2 100644 --- a/nix-conf/home-manager/base/shells.nix +++ b/nix-conf/home-manager/base/shells.nix @@ -1 +1,89 @@ -{} +# Configurations for shell stuffs. +# Should probably be decoupled even more +{ config +, proj_root +, myLib +, ... +}: +let cfg = config.base.shells; +in +{ + options.base.shells = { + enable = myLib.mkOption { + type = myLib.types.bool; + description = "Enable umbrella shell configuration"; + default = true; + example = false; + }; + # TODO: Support shell-specific init + shellInitExtra = myLib.mkOption { + type = myLib.types.str; + description = "Extra shell init. The syntax should be sh-compliant"; + default = ""; + example = '' + # X11 support for WSL + export DISPLAY=$(ip route list default | awk '{print $3}'):0 + export LIBGL_ALWAYS_INDIRECT=1 + ''; + }; + shellAliases = myLib.mkOption { + type = myLib.types.attrs; + description = "Shell command aliases"; + default = { }; + example = { + nixGL = "nixGLIntel"; + }; + }; + }; + config = myLib.mkIf cfg.enable { + xdg.configFile."starship.toml".source = "${proj_root}//starship/starship.toml"; + # nix: Propagates the environment with packages and vars when enter (children of) + # a directory with shell.nix-compatible and .envrc + programs.direnv = { + enable = true; + nix-direnv.enable = true; + # nix-direnv.enableFlakes = true; # must remove. this will always be supported. + }; + # z as smarter cd + programs.zoxide = { + enable = true; + enableZshIntegration = true; + }; + programs.tmux = { + enable = true; + extraConfig = builtins.readFile "${proj_root}/tmux/tmux.conf"; + }; + programs.exa = { + enable = true; + enableAliases = true; + }; + programs.starship = { + enable = true; + enableZshIntegration = true; + }; + programs.fzf.enable = true; + programs.bash = { + enable = true; + enableCompletion = true; + initExtra = cfg.shellInitExtra or ""; + }; + programs.zsh = { + enable = true; + enableCompletion = true; + enableAutosuggestions = true; + shellAliases = { + nix-rebuild = "sudo nixos-rebuild switch"; + hm-switch = "home-manager switch --flake"; + } // (cfg.shellAliases or { }); + history = { + size = 10000; + path = "${config.xdg.dataHome}/zsh/history"; + }; + oh-my-zsh = { + enable = true; + plugins = [ "git" "sudo" "command-not-found" "gitignore" "ripgrep" "rust" ]; + }; + initExtra = cfg.shellInitExtra or ""; + }; + }; +} diff --git a/nix-conf/home-manager/flake.nix b/nix-conf/home-manager/flake.nix index d6476fd..83259a3 100644 --- a/nix-conf/home-manager/flake.nix +++ b/nix-conf/home-manager/flake.nix @@ -60,6 +60,12 @@ inherit pkgs; modules = [ ./home.nix + { + base.shells = { + shellInitExtra = '' + '' + x11_wsl; + }; + } ]; # optionally pass inarguments to module # we migrate this from in-place modules to allow flexibility @@ -69,8 +75,6 @@ myHome = { username = "nixos"; homeDirectory = "/home/nixos"; - shellInitExtra = '' - '' + x11_wsl; }; }; }; @@ -98,6 +102,11 @@ ./home.nix { base.alacritty.font.family = "BitstreamVeraSansMono Nerd Font"; + base.shells = { + shellAliases = { + nixGL = "nixGLIntel"; + }; + }; } ]; extraSpecialArgs = mkModuleArgs { @@ -109,9 +118,6 @@ pkgs.nixgl.nixGLIntel pkgs.postman ]; - shellAliases = { - nixGL = "nixGLIntel"; - }; }; }; }; diff --git a/nix-conf/home-manager/home.nix b/nix-conf/home-manager/home.nix index f1acd1b..a20f127 100644 --- a/nix-conf/home-manager/home.nix +++ b/nix-conf/home-manager/home.nix @@ -67,38 +67,12 @@ in ## Configs ## xdg.configFile."nvim/init.lua".source = "${proj_root}//neovim/init.lua"; - xdg.configFile."starship.toml".source = "${proj_root}//starship/starship.toml"; xdg.configFile."zk/config.toml".source = "${proj_root}//zk/config.toml"; ## Programs ## programs.jq = { enable = true; }; - # nix: Propagates the environment with packages and vars when enter (children of) - # a directory with shell.nix-compatible and .envrc - programs.direnv = { - enable = true; - nix-direnv.enable = true; - # nix-direnv.enableFlakes = true; # must remove. this will always be supported. - }; - # z as smarter cd - programs.zoxide = { - enable = true; - enableZshIntegration = true; - }; - programs.tmux = { - enable = true; - extraConfig = builtins.readFile "${proj_root}/tmux/tmux.conf"; - }; - programs.exa = { - enable = true; - enableAliases = true; - }; - programs.starship = { - enable = true; - enableZshIntegration = true; - }; - programs.fzf.enable = true; programs.neovim = { enable = true; viAlias = true; @@ -115,27 +89,4 @@ in # https://github.com/nix-community/home-manager/pull/3287 # extraConfig = builtins.readFile "${proj_root}/neovim/init.lua"; }; - programs.bash = { - enable = true; - enableCompletion = true; - initExtra = myHome.shellInitExtra or ""; - }; - programs.zsh = { - enable = true; - enableCompletion = true; - enableAutosuggestions = true; - shellAliases = { - nix-rebuild = "sudo nixos-rebuild switch"; - hm-switch = "home-manager switch --flake"; - } // (myHome.shellAliases or { }); - history = { - size = 10000; - path = "${config.xdg.dataHome}/zsh/history"; - }; - oh-my-zsh = { - enable = true; - plugins = [ "git" "sudo" "command-not-found" "gitignore" "ripgrep" "rust" ]; - }; - initExtra = myHome.shellInitExtra or ""; - }; }