From 614556113283dcaff77af0b3c83039d8e9468652 Mon Sep 17 00:00:00 2001 From: winston Date: Thu, 15 Jun 2023 01:40:55 +0200 Subject: [PATCH] feat: add home-manager only config --- .justfile | 3 ++ flake.nix | 15 +++++++++- home/lib.nix | 33 ++++++++++++++++++++++ lib/default.nix => machines/lib.nix | 43 +++++++++++++---------------- 4 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 home/lib.nix rename lib/default.nix => machines/lib.nix (57%) diff --git a/.justfile b/.justfile index 2534752..5d06e4b 100644 --- a/.justfile +++ b/.justfile @@ -21,6 +21,9 @@ rebuild *args: build *args: @just rebuild build {{args}} +home *args: + nix run .\#homeConfigurations.winston.activationPackage + [linux] boot *args: @just rebuild boot {{args}} diff --git a/flake.nix b/flake.nix index 3742d4d..514618e 100644 --- a/flake.nix +++ b/flake.nix @@ -31,7 +31,7 @@ }; outputs = {flake-parts, ...} @ inputs: let - inherit (import ./lib {inherit inputs;}) mkSystems overlays; + inherit (import ./machines/lib.nix {inherit inputs;}) mkSystems overlays; in flake-parts.lib.mkFlake {inherit inputs;} { @@ -84,6 +84,19 @@ inherit (self'.checks.pre-commit-check) shellHook; nativeBuildInputs = with pkgs; [git-crypt just sops]; }; + + legacyPackages.homeConfigurations = let + homeLib = import ./home/lib.nix { + inherit inputs pkgs username; + isNixos = false; + }; + username = "winston"; + in { + ${username} = inputs.home-manager.lib.homeManagerConfiguration { + inherit pkgs; + inherit (homeLib) extraSpecialArgs modules; + }; + }; }; }; diff --git a/home/lib.nix b/home/lib.nix new file mode 100644 index 0000000..b3e178f --- /dev/null +++ b/home/lib.nix @@ -0,0 +1,33 @@ +{ + inputs, + pkgs, + username, + isNixOS ? true, +}: rec { + extraSpecialArgs = { + flakePath = + if pkgs.stdenv.isDarwin + then "/Users/${username}/.config/nixpkgs" + else "/home/${username}/.config/nixpkgs"; + }; + hmStandaloneConfig = { + home.homeDirectory = + if pkgs.stdenv.isLinux + then "/home/${username}" + else if pkgs.stdenv.isDarwin + then "/Users/${username}" + else throw "Unsupported system"; + home.stateVersion = "23.05"; + home.username = username; + targets.genericLinux.enable = true; + xdg.mime.enable = true; + }; + modules = with inputs; + [ + nix-index-database.hmModules.nix-index + sops.homeManagerModules.sops + caarlos0-nur.homeManagerModules.default + nekowinston-nur.homeManagerModules.default + ] + ++ pkgs.lib.optionals (!isNixOS) [hmStandaloneConfig]; +} diff --git a/lib/default.nix b/machines/lib.nix similarity index 57% rename from lib/default.nix rename to machines/lib.nix index d51cf6d..fe6d2e7 100644 --- a/lib/default.nix +++ b/machines/lib.nix @@ -10,30 +10,22 @@ }; sway-unwrapped = inputs.swayfx.packages.${prev.system}.default; }; - commonHMConfig = {username}: ({ + hmCommonConfig = {username}: ({ config, pkgs, ... - }: { + }: let + homeLib = import ../home/lib.nix {inherit inputs username pkgs;}; + in { config = { nixpkgs.overlays = [overlays]; home-manager = { backupFileExtension = "backup"; + extraSpecialArgs = homeLib.extraSpecialArgs; + sharedModules = homeLib.modules; useGlobalPkgs = true; useUserPackages = true; - sharedModules = with inputs; [ - nix-index-database.hmModules.nix-index - sops.homeManagerModules.sops - caarlos0-nur.homeManagerModules.default - nekowinston-nur.homeManagerModules.default - ]; users.${username}.imports = [../home]; - extraSpecialArgs = { - flakePath = - if pkgs.stdenv.isDarwin - then "/Users/${username}/.config/nixpkgs" - else "/home/${username}/.config/nixpkgs"; - }; }; }; }); @@ -53,23 +45,26 @@ else if isDarwin then "darwinConfigurations" else throw "Unsupported system"; - builder = + builder = with inputs; if isLinux - then inputs.nixpkgs.lib.nixosSystem + then nixpkgs.lib.nixosSystem else if isDarwin - then inputs.darwin.lib.darwinSystem + then darwin.lib.darwinSystem + else throw "Unsupported system"; + module = + if isLinux + then "nixosModules" + else if isDarwin + then "darwinModules" else throw "Unsupported system"; pkgs = inputs.nixpkgs.legacyPackages.${system}; - inherit (pkgs) lib; - inherit (pkgs.stdenv) isLinux isDarwin; + inherit (pkgs.stdenv) isDarwin isLinux; in { ${target}."${host}" = builder { inherit system; - modules = - [../machines/common ../machines/${host}] - ++ lib.optionals isLinux [inputs.home-manager.nixosModules.home-manager] - ++ lib.optionals isDarwin [inputs.home-manager.darwinModules.home-manager] - ++ [(commonHMConfig {inherit username;})] + modules = with inputs; + [./common ./${host} home-manager.${module}.home-manager] + ++ [(hmCommonConfig {inherit username;})] ++ extraModules; }; };