Use attribute sets in flake.nix

This will let me be more fine grained in what is applied where and will
allow importing of host-specific modules like those from
https://github.com/NixOS/nixos-hardware
This commit is contained in:
Gene Liverman 2024-06-05 22:08:30 -04:00
parent ab960a3d18
commit b00e9f7364

View file

@ -59,7 +59,7 @@
home-manager, nix-darwin, nix-flatpak, nix-homebrew, nixpkgs-terraform, sops-nix, ... }: let home-manager, nix-darwin, nix-flatpak, nix-homebrew, nixpkgs-terraform, sops-nix, ... }: let
# creates a macOS system config # creates a macOS system config
darwinHostConfig = system: hostname: username: nix-darwin.lib.darwinSystem { darwinHostConfig = { system, hostname, username, additionaModules, additionaSpecialArgs }: nix-darwin.lib.darwinSystem {
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
config = { config = {
@ -68,7 +68,7 @@
}; };
overlays = [ nixpkgs-terraform.overlays.default ]; overlays = [ nixpkgs-terraform.overlays.default ];
}; };
specialArgs = { inherit inputs hostname username; }; specialArgs = { inherit inputs hostname username; } // additionaSpecialArgs;
modules = [ modules = [
nix-homebrew.darwinModules.nix-homebrew { nix-homebrew.darwinModules.nix-homebrew {
nix-homebrew = { nix-homebrew = {
@ -92,11 +92,11 @@
./modules/system/common/all-darwin.nix # system-wide stuff ./modules/system/common/all-darwin.nix # system-wide stuff
./modules/hosts/darwin/${hostname} # host specific stuff ./modules/hosts/darwin/${hostname} # host specific stuff
]; # end modules ] ++ additionaModules; # end modules
}; # end darwinSystem }; # end darwinSystem
# creates a nixos system config # creates a nixos system config
nixosHostConfig = system: hostname: username: nixpkgs.lib.nixosSystem { nixosHostConfig = { system, hostname, username, additionaModules, additionaSpecialArgs }: nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs compose2nix hostname username; specialArgs = { inherit inputs compose2nix hostname username;
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
@ -106,7 +106,7 @@
}; };
overlays = [ nixpkgs-terraform.overlays.default ]; overlays = [ nixpkgs-terraform.overlays.default ];
}; };
}; } // additionaSpecialArgs;
modules = [ modules = [
disko.nixosModules.disko disko.nixosModules.disko
@ -126,10 +126,10 @@
sops-nix.nixosModules.sops # system wide secrets management sops-nix.nixosModules.sops # system wide secrets management
./modules/system/common/all-nixos.nix # system-wide stuff ./modules/system/common/all-nixos.nix # system-wide stuff
./modules/hosts/nixos/${hostname} # host specific stuff ./modules/hosts/nixos/${hostname} # host specific stuff
]; ] ++ additionaModules;
}; # end nixosSystem }; # end nixosSystem
linuxHomeConfig = system: hostname: username: home-manager.lib.homeManagerConfiguration { linuxHomeConfig = { system, hostname, username, additionaModules, additionaSpecialArgs }: home-manager.lib.homeManagerConfiguration {
extraSpecialArgs = { inherit genebean-omp-themes hostname username; extraSpecialArgs = { inherit genebean-omp-themes hostname username;
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
@ -139,7 +139,7 @@
}; };
overlays = [ nixpkgs-terraform.overlays.default ]; overlays = [ nixpkgs-terraform.overlays.default ];
}; };
}; } // additionaSpecialArgs;
modules = [ modules = [
./modules/home-manager/hosts/${hostname}/${username}.nix ./modules/home-manager/hosts/${hostname}/${username}.nix
{ {
@ -149,24 +149,69 @@
}; };
} }
sops-nix.homeManagerModules.sops sops-nix.homeManagerModules.sops
]; ] ++ additionaModules;
}; # end homeManagerConfiguration }; # end homeManagerConfiguration
in { in {
darwinConfigurations = { # Darwin (macOS) hosts
AirPuppet = darwinHostConfig "x86_64-darwin" "AirPuppet" "gene"; darwinConfigurations = {
Blue-Rock = darwinHostConfig "x86_64-darwin" "Blue-Rock" "gene.liverman"; AirPuppet = darwinHostConfig {
mightymac = darwinHostConfig "aarch64-darwin" "mightymac" "gene.liverman"; system = "x86_64-darwin";
hostname = "AirPuppet";
username = "gene";
additionaModules = [];
additionaSpecialArgs = {};
}; };
Blue-Rock = darwinHostConfig {
nixosConfigurations = { system = "x86_64-darwin";
hetznix01 = nixosHostConfig "aarch64-linux" "hetznix01" "gene"; hostname = "Blue-Rock";
nixnuc = nixosHostConfig "x86_64-linux" "nixnuc" "gene"; username = "gene.liverman";
rainbow-planet = nixosHostConfig "x86_64-linux" "rainbow-planet" "gene"; additionaModules = [];
additionaSpecialArgs = {};
}; };
mightymac = darwinHostConfig {
system = "aarch64-darwin";
hostname = "mightymac";
username = "gene.liverman";
additionaModules = [];
additionaSpecialArgs = {};
};
}; # end darwinConfigurations
homeConfigurations = { # NixOS hosts
gene = linuxHomeConfig "x86_64-linux" "mini-watcher" "gene"; nixosConfigurations = {
}; hetznix01 = nixosHostConfig {
system = "aarch64-linux";
hostname = "hetznix01";
username = "gene";
additionaModules = [];
additionaSpecialArgs = {};
};
nixnuc = nixosHostConfig {
system = "x86_64-linux";
hostname = "nixnuc";
username = "gene";
additionaModules = [];
additionaSpecialArgs = {};
};
rainbow-planet = nixosHostConfig {
system = "x86_64-linux";
hostname = "rainbow-planet";
username = "gene";
additionaModules = [];
additionaSpecialArgs = {};
};
}; # end nixosConfigurations
# Home Manager (only) users
homeConfigurations = {
gene = linuxHomeConfig {
system = "x86_64-linux";
hostname = "mini-watcher";
username = "gene";
additionaModules = [];
additionaSpecialArgs = {};
};
}; # end homeConfigurations
}; };
} }