home-manager: modularize home configurations

This commit is contained in:
xinyangli 2023-12-24 18:53:47 +08:00
parent ac9918c759
commit 552cc4f144
16 changed files with 261 additions and 227 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

4
.gitignore vendored
View file

@ -1 +1,3 @@
result .direnv
.vscode
result

View file

@ -55,23 +55,42 @@
outputs = { self, ... }@inputs: outputs = { self, ... }@inputs:
with inputs; with inputs;
let let
homeConfigurations = import ./home;
sharedModules = [
self.homeManagerModules
inputs.nix-index-database.hmModules.nix-index
];
mkHome = user: host: { config, system, ... }: { mkHome = user: host: { config, system, ... }: {
imports = [ imports = [
home-manager.nixosModules.home-manager
{ {
home-manager.useGlobalPkgs = true; home-manager = {
home-manager.useUserPackages = true; inherit sharedModules;
home-manager.users.xin = import ./home/${user}/${host}; useGlobalPkgs = true;
home-manager.extraSpecialArgs = { inherit inputs system; }; useUserPackages = true;
extraSpecialArgs = { inherit inputs; };
};
home-manager.users.${user} = homeConfigurations.${user}.${host};
} }
self.homeManagerModules
]; ];
}; };
mkHomeConfiguration = user: settings: {
name = user;
value = home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs { system = "x86_64-linux"; };
modules = [
self.homeManagerModules
] ++ sharedModules;
specialArgs = {
inherit inputs;
};
};
};
mkNixos = { system, modules, specialArgs ? {}}: nixpkgs.lib.nixosSystem { mkNixos = { system, modules, specialArgs ? {}}: nixpkgs.lib.nixosSystem {
inherit system; inherit system;
specialArgs = specialArgs // { inherit inputs system; }; specialArgs = specialArgs // { inherit inputs system; };
modules = [ modules = [
self.nixosModules.default self.nixosModules.default
home-manager.nixosModules.home-manager
nur.nixosModules.nur nur.nixosModules.nur
] ++ modules; ] ++ modules;
}; };
@ -81,6 +100,8 @@
nixosModules.default = import ./modules/nixos; nixosModules.default = import ./modules/nixos;
homeManagerModules = import ./modules/home-manager; homeManagerModules = import ./modules/home-manager;
homeConfigurations = listToAttrs [ (mkHomeConfiguration "xin" "calcite") ];
colmenaHive = colmena.lib.makeHive { colmenaHive = colmena.lib.makeHive {
meta = { meta = {
nixpkgs = import nixpkgs { nixpkgs = import nixpkgs {
@ -166,5 +187,14 @@
} }
]; ];
}).config.system.build.sdImage; }).config.system.build.sdImage;
}; } // flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShells = {
default = pkgs.mkShell {
packages = with pkgs; [ git colmena ];
};
};
}
);
} }

5
home/default.nix Normal file
View file

@ -0,0 +1,5 @@
{
xin = {
calcite = import ./xin/calcite.nix;
};
}

View file

@ -1,19 +0,0 @@
{ config, ... }: {
programs.alacritty = {
enable = true;
settings = {
shell = {
program = config.programs.zellij.package + "/bin/zellij";
args = [
"attach"
"-c"
];
};
font.size = 10.0;
window = {
resize_increments = true;
dynamic_padding = true;
};
};
};
}

View file

@ -1,10 +1,7 @@
{ inputs, config, pkgs, ... }: { config, pkgs, ... }:
{ {
imports = [ imports = [
../common ./common
../vscode.nix
../alacritty.nix
inputs.nix-index-database.hmModules.nix-index
]; ];
programs.nix-index-database.comma.enable = true; programs.nix-index-database.comma.enable = true;
@ -35,10 +32,13 @@
remmina remmina
]; ];
# custom-hm = { custom-hm = {
# fish = { enable = true; }; alacritty = { enable = true; };
# git = { enable = true; }; direnv = { enable = true; };
# neovim = { enable = true; }; fish = { enable = true; };
# zellij = { enable = true; }; git = { enable = true; };
# }; neovim = { enable = true; };
vscode = { enable = true; };
zellij = { enable = true; };
};
} }

View file

@ -1,133 +0,0 @@
{ config, pkgs, inputs, system, ... }:
{
home.packages = with pkgs; [
pkgs.wl-clipboard-x11
];
programs.vscode = {
enable = true;
enableUpdateCheck = false;
enableExtensionUpdateCheck = false;
mutableExtensionsDir = false;
extensions = (with inputs.nix-vscode-extensions.extensions.${system}.vscode-marketplace; [
arrterian.nix-env-selector
bbenoist.nix
ms-azuretools.vscode-docker
ms-vscode-remote.remote-ssh
vscodevim.vim
github.vscode-pull-request-github
eamodio.gitlens
gruntfuggly.todo-tree # todo highlight
# Language support
# Python
ms-python.python
# Markdown
davidanson.vscode-markdownlint
# C/C++
ms-vscode.cmake-tools
llvm-vs-code-extensions.vscode-clangd
# Nix
jnoortheen.nix-ide
# Latex
james-yu.latex-workshop
# Vue
vue.volar
ms-vscode-remote.remote-ssh-edit
mushan.vscode-paste-image
]) ++ (with pkgs.vscode-extensions; [
# Rust
rust-lang.rust-analyzer
github.copilot
]);
userSettings = {
"workbench.colorTheme" = "Default Dark+";
"terminal.integrated.sendKeybindingsToShell" = true;
"extensions.ignoreRecommendations" = true;
"files.autoSave" = "afterDelay";
"editor.inlineSuggest.enabled" = true;
"editor.rulers" = [
80
];
"editor.mouseWheelZoom" = true;
"git.autofetch" = true;
"window.zoomLevel" = -1;
"nix.enableLanguageServer" = true;
"latex-workshop.latex.autoBuild.run" = "never";
"latex-workshop.latex.tools" = [
{
"name" = "xelatex";
"command" = "xelatex";
"args" = [
"-synctex=1"
"-interaction=nonstopmode"
"-file-line-error"
"-pdf"
"%DOCFILE%"
];
}
{
"name" = "pdflatex";
"command" = "pdflatex";
"args" = [
"-synctex=1"
"-interaction=nonstopmode"
"-file-line-error"
"%DOCFILE%"
];
}
{
"name" = "bibtex";
"command" = "bibtex";
"args" = [
"%DOCFILE%"
];
}
];
"latex-workshop.latex.recipes" = [
{
"name" = "xelatex";
"tools" = [
"xelatex"
];
}
{
"name" = "pdflatex";
"tools" = [
"pdflatex"
];
}
{
"name" = "xe->bib->xe->xe";
"tools" = [
"xelatex"
"bibtex"
"xelatex"
"xelatex"
];
}
{
"name" = "pdf->bib->pdf->pdf";
"tools" = [
"pdflatex"
"bibtex"
"pdflatex"
"pdflatex"
];
}
];
"[latex]" = {
"editor.formatOnPaste" = false;
"editor.suggestSelection" = "recentlyusedbyprefix";
"editor.wordWrap" = "bounded";
"editor.wordWrapColumn" = 80;
"editor.unicodeHighlight.ambiguousCharacters" = false;
};
# Extension vscode-paste-image
"pasteImage.path" = "\${currentFileDir}/.assets";
};
};
}

View file

@ -1,36 +0,0 @@
{ config, lib, pkgs, ... }:
{
environment.systemPackages = [
(pkgs.vscode-with-extensions.override {
vscodeExtensions = with pkgs.vscode-extensions; [
arrterian.nix-env-selector
bbenoist.nix
ms-azuretools.vscode-docker
ms-vscode-remote.remote-ssh
vscodevim.vim
github.copilot
github.vscode-pull-request-github
eamodio.gitlens
gruntfuggly.todo-tree # todo highlight
vadimcn.vscode-lldb # debugger
# Language support
ms-python.python
davidanson.vscode-markdownlint
llvm-vs-code-extensions.vscode-clangd
jnoortheen.nix-ide
james-yu.latex-workshop
rust-lang.rust-analyzer
] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
{
name = "remote-ssh-edit";
publisher = "ms-vscode-remote";
version = "0.47.2";
sha256 = "1hp6gjh4xp2m1xlm1jsdzxw9d8frkiidhph6nvl24d0h8z34w49g";
}
];
})
];
}

View file

@ -0,0 +1,31 @@
{ config, lib, ... }:
with lib;
let
cfg = config.custom-hm.alacritty;
in
{
options.custom-hm.alacritty = {
enable = mkEnableOption "alacritty";
};
config = mkIf cfg.enable {
programs.alacritty = {
enable = true;
settings = {
shell = {
program = config.programs.zellij.package + "/bin/zellij";
args = [
"attach"
"-c"
];
};
font.size = 10.0;
window = {
resize_increments = true;
dynamic_padding = true;
};
};
};
};
}

View file

@ -1,10 +1,12 @@
{ config, pkgs, ... }:
{ {
imports = [ imports = [
./alacritty.nix
./direnv.nix
./fish.nix ./fish.nix
./git.nix ./git.nix
./tmux.nix ./tmux.nix
./vim.nix ./vim.nix
./vscode.nix
./zellij.nix ./zellij.nix
]; ];
} }

View file

@ -0,0 +1,18 @@
{ config, lib, ... }:
with lib;
let
cfg = config.custom-hm.direnv;
in
{
options.custom-hm.direnv = {
enable = mkEnableOption "direnv";
};
config = {
programs = mkIf config.custom-hm.direnv.enable {
direnv = {
enable = true;
};
};
};
}

View file

@ -6,7 +6,7 @@ let
cfg = config.custom-hm.fish; cfg = config.custom-hm.fish;
in in
{ {
options = { options.custom-hm.fish = {
enable = mkEnableOption "fish"; enable = mkEnableOption "fish";
plugins = mkOption { plugins = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
@ -30,9 +30,9 @@ in
programs.fish = mkIf cfg.enable { programs.fish = mkIf cfg.enable {
enable = true; enable = true;
plugins = with pkgs; filter ( plugins = with pkgs; filter (
e: hasAttr e.name builtins.listToAttrs # { "xxx" = true; } e: hasAttr e.name (builtins.listToAttrs # { "xxx" = true; }
(map (p: { name = p; value = true; }) cfg.plugins) # { name = "xxx"; value = true; } (map (p: { name = p; value = true; }) cfg.plugins) # { name = "xxx"; value = true; }
) [ )) [
{ {
name = "pisces"; name = "pisces";
src = fishPlugins.pisces.src; src = fishPlugins.pisces.src;

View file

@ -6,7 +6,7 @@ let
cfg = config.custom-hm.git; cfg = config.custom-hm.git;
in in
{ {
options = { options.custom-hm.git = {
enable = mkEnableOption "Enable git configuration"; enable = mkEnableOption "Enable git configuration";
}; };
config = { config = {

View file

@ -6,7 +6,7 @@ let
cfg = config.custom-hm.neovim; cfg = config.custom-hm.neovim;
in in
{ {
options = { options.custom-hm.neovim = {
enable = mkEnableOption "neovim configurations"; enable = mkEnableOption "neovim configurations";
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {

View file

@ -0,0 +1,146 @@
{ inputs, config, lib, pkgs, ... }:
with lib;
let
cfg = config.custom-hm.vscode;
in
{
options.custom-hm.vscode = {
enable = mkEnableOption "Vscode config";
};
config = mkIf cfg.enable {
home.packages = with pkgs; [
pkgs.wl-clipboard-x11
];
programs.vscode = {
enable = true;
enableUpdateCheck = false;
enableExtensionUpdateCheck = false;
mutableExtensionsDir = false;
extensions = (with inputs.nix-vscode-extensions.extensions.${pkgs.system}.vscode-marketplace; [
mkhl.direnv
bbenoist.nix
ms-azuretools.vscode-docker
ms-vscode-remote.remote-ssh
vscodevim.vim
github.vscode-pull-request-github
eamodio.gitlens
gruntfuggly.todo-tree # todo highlight
# Language support
# Python
ms-python.python
# Markdown
davidanson.vscode-markdownlint
# C/C++
ms-vscode.cmake-tools
llvm-vs-code-extensions.vscode-clangd
# Nix
jnoortheen.nix-ide
# Latex
james-yu.latex-workshop
# Vue
vue.volar
# Scale / chisel
scalameta.metals
sterben.fpga-support
ms-vscode-remote.remote-ssh-edit
mushan.vscode-paste-image
]) ++ (with pkgs.vscode-extensions; [
catppuccin.catppuccin-vsc
# Rust
rust-lang.rust-analyzer
github.copilot
]);
userSettings = {
"workbench.colorTheme" = "Catppuccin Macchiato";
"terminal.integrated.sendKeybindingsToShell" = true;
"extensions.ignoreRecommendations" = true;
"files.autoSave" = "afterDelay";
"editor.inlineSuggest.enabled" = true;
"editor.rulers" = [
80
];
"editor.mouseWheelZoom" = true;
"git.autofetch" = true;
"window.zoomLevel" = -1;
"nix.enableLanguageServer" = true;
"latex-workshop.latex.autoBuild.run" = "never";
"latex-workshop.latex.tools" = [
{
"name" = "xelatex";
"command" = "xelatex";
"args" = [
"-synctex=1"
"-interaction=nonstopmode"
"-file-line-error"
"-pdf"
"%DOCFILE%"
];
}
{
"name" = "pdflatex";
"command" = "pdflatex";
"args" = [
"-synctex=1"
"-interaction=nonstopmode"
"-file-line-error"
"%DOCFILE%"
];
}
{
"name" = "bibtex";
"command" = "bibtex";
"args" = [
"%DOCFILE%"
];
}
];
"latex-workshop.latex.recipes" = [
{
"name" = "xelatex";
"tools" = [
"xelatex"
];
}
{
"name" = "pdflatex";
"tools" = [
"pdflatex"
];
}
{
"name" = "xe->bib->xe->xe";
"tools" = [
"xelatex"
"bibtex"
"xelatex"
"xelatex"
];
}
{
"name" = "pdf->bib->pdf->pdf";
"tools" = [
"pdflatex"
"bibtex"
"pdflatex"
"pdflatex"
];
}
];
"[latex]" = {
"editor.formatOnPaste" = false;
"editor.suggestSelection" = "recentlyusedbyprefix";
"editor.wordWrap" = "bounded";
"editor.wordWrapColumn" = 80;
"editor.unicodeHighlight.ambiguousCharacters" = false;
};
};
};
};
}

View file

@ -6,7 +6,7 @@ let
cfg = config.custom-hm.zellij; cfg = config.custom-hm.zellij;
in in
{ {
options = { options.custom-hm.zellij = {
enable = mkEnableOption "zellij configurations"; enable = mkEnableOption "zellij configurations";
}; };
config = { config = {
@ -21,19 +21,6 @@ in
]; ];
}; };
theme = "catppuccin-macchiato"; 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 ];
};
}; };
}; };
}; };