From aefc759927ef79b66b92b03a74d744236a31f3a0 Mon Sep 17 00:00:00 2001 From: pegasust Date: Mon, 5 Dec 2022 07:42:20 +0000 Subject: [PATCH] WIP: turn home-manager config into different modules --- neovim/init.lua | 1 + nix-conf/home-manager/flake.lock | 14 ++++++ nix-conf/home-manager/flake.nix | 77 +++++++++++++++++++----------- nix-conf/home-manager/home.nix | 33 ++++++++----- nix-conf/pkgs/default.nix | 3 +- nix-conf/pkgs/dot-hwtr/default.nix | 21 ++++++-- 6 files changed, 105 insertions(+), 44 deletions(-) diff --git a/neovim/init.lua b/neovim/init.lua index 3337b90..e04621a 100644 --- a/neovim/init.lua +++ b/neovim/init.lua @@ -521,6 +521,7 @@ cmp.setup { { name = 'luasnip' }, { name = 'buffer' }, { name = 'path' }, + { name = 'conjure' }, -- { name = 'cmp_tabnine' }, }, } diff --git a/nix-conf/home-manager/flake.lock b/nix-conf/home-manager/flake.lock index c58fdee..8f923e6 100644 --- a/nix-conf/home-manager/flake.lock +++ b/nix-conf/home-manager/flake.lock @@ -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" diff --git a/nix-conf/home-manager/flake.nix b/nix-conf/home-manager/flake.nix index 158288f..0dd8d49 100644 --- a/nix-conf/home-manager/flake.nix +++ b/nix-conf/home-manager/flake.nix @@ -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"; }; }; }; diff --git a/nix-conf/home-manager/home.nix b/nix-conf/home-manager/home.nix index ed9f438..c169674 100644 --- a/nix-conf/home-manager/home.nix +++ b/nix-conf/home-manager/home.nix @@ -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; diff --git a/nix-conf/pkgs/default.nix b/nix-conf/pkgs/default.nix index d40c66a..a1d9d43 100644 --- a/nix-conf/pkgs/default.nix +++ b/nix-conf/pkgs/default.nix @@ -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; + } diff --git a/nix-conf/pkgs/dot-hwtr/default.nix b/nix-conf/pkgs/dot-hwtr/default.nix index ec01c78..44244da 100644 --- a/nix-conf/pkgs/dot-hwtr/default.nix +++ b/nix-conf/pkgs/dot-hwtr/default.nix @@ -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/ + ''; }