Compare commits

...

5 Commits

7 changed files with 216 additions and 101 deletions

View File

@ -1,3 +1,12 @@
{ {
mkModuleArgs = import ./mkModuleArgs.nix;
modules = [
./alacritty.nix
./git.nix
./ssh.nix
./shells.nix
{
config.programs.home-manager.enable = true;
}
];
} }

View File

@ -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;
};
}

View File

View File

@ -0,0 +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 <path> 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 "";
};
};
}

View File

@ -0,0 +1,23 @@
{ 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";
};
}

View File

@ -33,7 +33,8 @@
config = { allowUnfree = true; }; config = { allowUnfree = true; };
}; };
# lib = (import ../lib { inherit pkgs; lib = pkgs.lib; }); # lib = (import ../lib { inherit pkgs; lib = pkgs.lib; });
mkModuleArgs = import ./base/mkModuleArgs.nix; base = import ./base;
inherit (base) mkModuleArgs;
in in
{ {
homeConfigurations = homeConfigurations =
@ -46,7 +47,7 @@
rec { rec {
"hungtr" = home-manager.lib.homeManagerConfiguration { "hungtr" = home-manager.lib.homeManagerConfiguration {
inherit pkgs; inherit pkgs;
modules = [ modules = base.modules ++ [
./home.nix ./home.nix
]; ];
# optionally pass inarguments to module # optionally pass inarguments to module
@ -64,6 +65,12 @@
inherit pkgs; inherit pkgs;
modules = [ modules = [
./home.nix ./home.nix
{
base.shells = {
shellInitExtra = ''
'' + x11_wsl;
};
}
]; ];
# optionally pass inarguments to module # optionally pass inarguments to module
# we migrate this from in-place modules to allow flexibility # we migrate this from in-place modules to allow flexibility
@ -73,8 +80,6 @@
myHome = { myHome = {
username = "nixos"; username = "nixos";
homeDirectory = "/home/nixos"; homeDirectory = "/home/nixos";
shellInitExtra = ''
'' + x11_wsl;
}; };
}; };
}; };
@ -98,11 +103,15 @@
# Personal laptop # Personal laptop
hwtr = home-manager.lib.homeManagerConfiguration { hwtr = home-manager.lib.homeManagerConfiguration {
inherit pkgs; inherit pkgs;
modules = [ modules = base.modules ++ [
./home.nix ./home.nix
./base/alacritty.nix
{ {
base.alacritty.font.family = "BitstreamVeraSansMono Nerd Font"; base.alacritty.font.family = "BitstreamVeraSansMono Nerd Font";
base.shells = {
shellAliases = {
nixGL = "nixGLIntel";
};
};
} }
]; ];
extraSpecialArgs = mkModuleArgs { extraSpecialArgs = mkModuleArgs {
@ -114,9 +123,6 @@
pkgs.nixgl.nixGLIntel pkgs.nixgl.nixGLIntel
pkgs.postman pkgs.postman
]; ];
shellAliases = {
nixGL = "nixGLIntel";
};
}; };
}; };
}; };

View File

@ -66,39 +66,12 @@ in
## Configs ## ## Configs ##
xdg.configFile."nvim/init.lua".source = "${proj_root}//neovim/init.lua"; 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"; xdg.configFile."zk/config.toml".source = "${proj_root}//zk/config.toml";
## Programs ## ## Programs ##
programs.jq = { programs.jq = {
enable = true; 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 <path> 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.home-manager.enable = true;
programs.fzf.enable = true;
programs.neovim = { programs.neovim = {
enable = true; enable = true;
viAlias = true; viAlias = true;
@ -115,66 +88,4 @@ in
# https://github.com/nix-community/home-manager/pull/3287 # https://github.com/nix-community/home-manager/pull/3287
# extraConfig = builtins.readFile "${proj_root}/neovim/init.lua"; # 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 = pkgs.lib.recursiveUpdate {
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 "";
};
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;
extraConfig = builtins.readFile "${proj_root}/ssh/config";
};
} }