From ad442e140c643eb3a80f5d4f59aa00b21c00888f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 22 Jan 2025 13:02:57 +0900 Subject: nix: refactor flake.nix by flake-utils --- flake.nix | 66 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 30 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index ae4dec7..c8d8d33 100644 --- a/flake.nix +++ b/flake.nix @@ -28,40 +28,46 @@ ... }: let - readJSON = p: builtins.fromJSON (builtins.readFile p); - machines = [ - (readJSON ./mitamae/node.akashi.json) - (readJSON ./mitamae/node.hotaru.json) - (readJSON ./mitamae/node.pc168.json) - ]; - mkHomeConfiguration = - { - system, - env, - ... - }: - home-manager.lib.homeManagerConfiguration { - pkgs = import nixpkgs { + eachDefaultSystem = + f: + flake-utils.lib.eachDefaultSystem ( + system: + f { inherit system; - config.allowUnfree = true; - }; - extraSpecialArgs = { inherit env; }; - modules = [ - ./home-manager/home.nix - ]; - }; + pkgs = import nixpkgs { inherit system; }; + } + ); in - flake-utils.lib.eachDefaultSystem (system: { - formatter = nixpkgs.legacyPackages.${system}.nixfmt-rfc-style; - }) + eachDefaultSystem ( + { system, pkgs }: + { + formatter = pkgs.nixfmt-rfc-style; + } + ) // { homeConfigurations = ( - builtins.listToAttrs ( - builtins.map (machine: { - name = machine.name; - value = mkHomeConfiguration machine.flake; - }) machines - ) + let + readJSON = p: builtins.fromJSON (builtins.readFile p); + mkHomeConfiguration = + { + system, + env, + ... + }: + home-manager.lib.homeManagerConfiguration { + pkgs = import nixpkgs { inherit system; }; + extraSpecialArgs = { inherit env; }; + modules = [ + ./home-manager/home.nix + ]; + }; + mkHomeConfigurationFromJSON = p: mkHomeConfiguration (readJSON p).flake; + in + { + akashi = mkHomeConfigurationFromJSON ./mitamae/node.akashi.json; + hotaru = mkHomeConfigurationFromJSON ./mitamae/node.hotaru.json; + pc168 = mkHomeConfigurationFromJSON ./mitamae/node.pc168.json; + } ); }; } -- cgit v1.2.3-70-g09d2