From 0af238c15b0533fda5f7e46cce92d66a6e5c6ecd Mon Sep 17 00:00:00 2001 From: RGBCube Date: Wed, 3 May 2023 13:39:22 +0300 Subject: [PATCH] Clean: Clean flake.nix --- flake.nix | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index 127a3e0..673cf26 100644 --- a/flake.nix +++ b/flake.nix @@ -25,36 +25,40 @@ ... }: let - lib = nixpkgs.lib; + importConfiguration = directory: - importConfiguration = directory: { - nixosConfigurations.${builtins.baseNameOf directory} = - let - hostPlatform = import (directory + "/platform.nix"); - in - lib.nixosSystem { + let + hostPlatform = import (directory + "/platform.nix"); + # The folder name is the host name of the machine. + hostName = builtins.baseNameOf directory; + userName = import (directory + "/username.nix"); + in + + { + nixosConfigurations.${hostName} = nixpkgs.lib.nixosSystem { specialArgs = { - inherit lib; + lib = nixpkgs.lib; pkgs = import nixpkgs { system = hostPlatform; config.allowUnfree = true; }; + # Helper function for DRY. homeManagerConfiguration = attrs: { - home-manager.users.${import (directory + "/username.nix")} = attrs; + home-manager.users.${userName} = attrs; }; }; modules = [ directory + home-manager.nixosModules.home-manager + + # Extra configuration derived from the metadata. { networking.hostName = builtins.baseNameOf directory; nixpkgs.hostPlatform = hostPlatform; - } - home-manager.nixosModules.home-manager - { home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; } @@ -62,6 +66,7 @@ }; }; in + # Basically imports all machines in ./machines/. builtins.foldl' lib.recursiveUpdate {} (builtins.map importConfiguration [ ./machines/asus # HACK: Use a function to list the directory. ]);