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 = 'luasnip' },
{ name = 'buffer' }, { name = 'buffer' },
{ name = 'path' }, { name = 'path' },
{ name = 'conjure' },
-- { name = 'cmp_tabnine' }, -- { name = 'cmp_tabnine' },
}, },
} }

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
# This module aims to be merge (not inject/override) with top-level pkgs to provide # This module aims to be merge (not inject/override) with top-level pkgs to provide
# personalized/custom packages # personalized/custom packages
{ pkgs, lib, ... }@pkgs_input: { { 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 { { pkgs, lib, ... } @ pkgs_input:
name = "dot-hwtr"; pkgs.stdenv.mkDerivation {
native 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/
'';
} }