WIP: turn home-manager config into different modules

consolidate-nix
pegasust 2022-12-05 07:42:20 +00:00
parent 123d6e8ede
commit aefc759927
6 changed files with 105 additions and 44 deletions

View File

@ -521,6 +521,7 @@ cmp.setup {
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'conjure' },
-- { name = 'cmp_tabnine' },
},
}

View File

@ -82,6 +82,19 @@
"type": "github"
}
},
"my-pkgs": {
"flake": false,
"locked": {
"lastModified": 1,
"narHash": "sha256-OKUT7wDDlUzcbGPOTiOpzFpiTG8EgZ6Wtq+Ra5A3av8=",
"path": "../pkgs",
"type": "path"
},
"original": {
"path": "../pkgs",
"type": "path"
}
},
"nixgl": {
"inputs": {
"flake-utils": "flake-utils_2",
@ -153,6 +166,7 @@
"flake-utils": "flake-utils",
"from-yaml": "from-yaml",
"home-manager": "home-manager",
"my-pkgs": "my-pkgs",
"nixgl": "nixgl",
"nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay"

View File

@ -13,6 +13,10 @@
url = "github:pegasust/fromYaml";
flake = false;
};
my-pkgs = {
url = "path:../pkgs";
flake = false;
};
};
outputs =
@ -22,6 +26,7 @@
, rust-overlay
, flake-utils
, from-yaml
, my-pkgs
, ...
}:
let
@ -30,9 +35,9 @@
# pkgs = nixpkgs.legacyPackages.${system}.appendOverlays overlays;
pkgs = import nixpkgs {
inherit system overlays;
config = {allowUnfree = true;};
config = { allowUnfree = true; };
};
lib = (import ../lib-nix { inherit pkgs from-yaml; lib = pkgs.lib; });
lib = (import ../lib { inherit pkgs from-yaml; lib = pkgs.lib; });
in
{
homeConfigurations =
@ -47,34 +52,42 @@
inherit pkgs;
modules = [
./home.nix
{
home = {
username = "hungtr";
homeDirectory = "/home/hungtr";
stateVersion = "22.05";
};
}
];
# optionally pass inarguments to module
# we migrate this from in-place modules to allow flexibility
# in this case, we can add "home" to input arglist of home.nix
extraSpecialArgs = {
myLib = lib;
myHome = {
username = "hungtr";
homeDirectory = "/home/hungtr";
};
inherit my-pkgs;
};
};
"nixos@Felia" = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home.nix
{
home = {
username = "nixos";
homeDirectory = "/home/nixos";
stateVersion = "22.05";
};
}
];
# optionally pass inarguments to module
# we migrate this from in-place modules to allow flexibility
# in this case, we can add "home" to input arglist of home.nix
extraSpecialArgs = {
myLib = lib;
myHome = {
username = "nixos";
homeDirectory = "/home/nixos";
shellInitExtra = ''
'' + x11_wsl;
};
inherit my-pkgs;
shellInitExtra = ''
'' + x11_wsl;
};
};
# NOTE: This is never actually tested
@ -82,34 +95,42 @@
inherit pkgs;
modules = [
./home.nix
{
home = {
username = "ubuntu_admin";
homeDirectory = "/home/ubuntu_admin";
stateVersion = "22.05";
};
}
];
extraSpecialArgs = {
myLib = lib;
myHome = {
username = "ubuntu_admin";
homeDirectory = "/home/ubuntu_admin";
shellInitExtra = ''
'' + x11_wsl;
};
inherit my-pkgs;
shellInitExtra = ''
'' + x11_wsl;
};
};
hwtr = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home.nix
{
home = {
username = "hwtr";
homeDirectory = "/home/hwtr";
stateVersion = "22.05";
};
}
];
extraSpecialArgs = {
myLib = lib;
myHome = {
username = "hwtr";
homeDirectory = "/home/hwtr";
packages = [
pkgs.nixgl.nixGLIntel
pkgs.postman
];
shellAliases = {
nixGL = "nixGLIntel";
};
inherit my-pkgs;
extraPackages = [
pkgs.nixgl.nixGLIntel
pkgs.postman
];
shellAliases = {
nixGL = "nixGLIntel";
};
};
};

View File

@ -1,7 +1,12 @@
# myHome is injected from extraSpecialArgs in flake.nix
{ config
, lib
, pkgs
, myHome
, my-pkgs ? []
, myLib ? []
, extraPackages ? []
, shellInitExtra ? ""
, shellAliases ? {}
, ...
}:
let
@ -28,14 +33,17 @@ let
# ]))
];
proj_root = builtins.toString ./../..;
_my-pkgs = import my-pkgs { inherit pkgs; lib = pkgs.lib // my-pkgs.lib // myLib; };
in
{
home = {
username = myHome.username;
homeDirectory = myHome.homeDirectory;
stateVersion = myHome.stateVersion or "22.05";
};
# config = {
# # my-pkgs = mkOption {
# # type = ;
# # default = {};
# # example = {};
# # description = "TODO: complete the type to get every other fields";
# # };
# };
home.packages = pkgs.lib.unique ([
pkgs.ncdu
pkgs.htop
@ -60,7 +68,7 @@ in
# pkgs.python310.numpy
# pkgs.python310Packages.tensorflow
# pkgs.python310Packages.scikit-learn
] ++ (myHome.packages or [ ]) ++ nvim_pkgs);
] ++ (extraPackages) ++ nvim_pkgs);
## Configs ##
xdg.configFile."nvim/init.lua".text = builtins.readFile "${proj_root}//neovim/init.lua";
@ -71,8 +79,9 @@ in
programs.jq = {
enable = true;
};
programs.alacritty = myHome.programs.alacritty or {
programs.alacritty = {
enable = true;
# settings = builtins.fromJSON (builtins.readFile "${_my-pkgs.dot-hwtr}/alacritty/alacritty.json");
# settings = myLib.fromYaml (builtins.readFile "${proj_root}/alacritty/alacritty.yml");
};
# nix: Propagates the environment with packages and vars when enter (children of)
@ -120,7 +129,7 @@ in
programs.bash = {
enable = true;
enableCompletion = true;
initExtra = myHome.shellInitExtra or "";
initExtra = shellInitExtra;
};
programs.zsh = {
enable = true;
@ -129,7 +138,7 @@ in
shellAliases = {
nix-rebuild = "sudo nixos-rebuild switch";
hm-switch = "home-manager switch --flake";
} // (myHome.shellAliases or { });
} // (shellAliases);
history = {
size = 10000;
path = "${config.xdg.dataHome}/zsh/history";
@ -138,7 +147,7 @@ in
enable = true;
plugins = [ "git" "sudo" "command-not-found" "gitignore" "ripgrep" "rust" ];
};
initExtra = myHome.shellInitExtra or "";
initExtra = shellInitExtra;
};
programs.git = {
enable = true;

View File

@ -1,5 +1,6 @@
# This module aims to be merge (not inject/override) with top-level pkgs to provide
# personalized/custom packages
{ pkgs, lib, ... }@pkgs_input: {
dot-hwtr = import "./dot-hwtr" pkgs_input;
dot-hwtr = import ./dot-hwtr pkgs_input;
}

View File

@ -1,4 +1,19 @@
{ pkgs, lib, ... }@pkgs_input: pkgs.stdenv.mkDerivation {
name = "dot-hwtr";
native
{ pkgs, lib, ... } @ pkgs_input:
pkgs.stdenv.mkDerivation {
pname = "dot-hwtr";
version = "0.0.1";
src = ./../../..; # project root
nativeBuildInputs = [
pkgs.yq
pkgs.jq
];
buildPhase = ''
# Translate alacritty.yml -> alacritty.json. Technically, yml is superset of json
yq . alacritty/alacritty.yml > alacritty/alacritty.json
'';
installPhase = ''
echo "Nothing to install. It should be available under $out/alacritty/alacritty.json"
mkdir -p $out/alacritty
cp alacritty/* $out/alacritty/
'';
}