Created
April 6, 2022 05:24
-
-
Save jhillyerd/d2a2f4ee99dfefe7f1a672a643e6edc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "Home Services"; | |
inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; }; | |
outputs = { self, nixpkgs }@attrs: | |
let | |
inherit (nixpkgs.lib) attrsets nixosSystem; | |
# List of hosts available to build. | |
hosts = [ "nexus" ]; | |
in rec { | |
# Convert list of hosts into a set of output attrs. | |
nixosConfigurations = let | |
genPrefixAttrs = prefix: names: f: | |
attrsets.listToAttrs | |
(map (n: attrsets.nameValuePair (prefix + n) (f n)) names); | |
systemTemplate = environment: host: | |
nixosSystem { | |
system = "x86_64-linux"; | |
specialArgs = attrs // { | |
inherit environment; | |
nodes = nixosConfigurations; | |
}; | |
modules = | |
[ { networking.hostName = host; } (./hosts + "/${host}.nix") ]; | |
}; | |
in attrsets.genAttrs hosts (systemTemplate "prod") | |
// genPrefixAttrs "vm-" hosts (systemTemplate "test"); | |
# Generate VM build packages to test each host. | |
packages."x86_64-linux" = with nixpkgs.lib; | |
mapAttrs' (host: sys: { | |
name = "${host}"; | |
value = sys.config.system.build.vm; | |
}) self.nixosConfigurations; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment