hackens-org-configurations/hive.nix

74 lines
1.7 KiB
Nix
Raw Normal View History

2023-12-04 17:42:06 +01:00
let
sources = import ./npins;
metadata = import ./meta.nix;
defaultNixpkgs = importNixpkgsPath "x86_64-linux" sources."nixos-unstable";
inherit (defaultNixpkgs) lib;
2024-09-24 12:33:51 +02:00
revision =
node:
(builtins.fromJSON (builtins.readFile ./npins/sources.json)).pins.${pkgsVersion node}.revision;
2023-12-04 17:42:06 +01:00
mkNode = node: {
2024-09-24 12:33:51 +02:00
${node} =
{
name,
nodes,
...
}:
{
imports = [
./machines/${node}/_configuration.nix
] ++ lib.attrByPath [ "imports" ] [ ] metadata.nodes.${node};
inherit (metadata.nodes.${node}) deployment;
nix.nixPath = builtins.map (n: "${n}=${sources.${n}}") (builtins.attrNames sources) ++ [
"nixpkgs=${mkNixpkgsPath name}"
];
system.nixos.tags = [
(revision node)
];
};
2023-12-04 17:42:06 +01:00
};
2024-09-24 12:33:51 +02:00
pkgsVersion =
node:
lib.attrByPath [
node
"nixpkgs"
] "nixos-unstable" metadata.nodes;
2023-12-04 17:42:06 +01:00
mkNixpkgsPath = node: sources.${pkgsVersion node};
mkNixpkgs = node: {
2024-09-24 12:33:51 +02:00
${node} = importNixpkgsPath (lib.attrByPath [ "arch" ] "x86_64-linux" metadata.nodes.${node}) (
mkNixpkgsPath node
);
2023-12-04 17:42:06 +01:00
};
2024-09-24 12:33:51 +02:00
importNixpkgsPath =
arch: p:
import p {
config.allowUnfree = true;
2024-10-12 17:45:41 +02:00
overlays = import ./pkgs/overlays.nix { inherit sources; };
2024-09-24 12:33:51 +02:00
system = arch;
};
2023-12-04 17:42:06 +01:00
nodes = builtins.attrNames metadata.nodes;
2024-09-24 12:33:51 +02:00
concatAttrs = builtins.foldl' (x: y: x // y) { };
2023-12-04 17:42:06 +01:00
in
2024-09-24 12:33:51 +02:00
{
meta = {
specialArgs = {
2024-10-12 17:45:41 +02:00
inherit sources metadata;
2023-12-04 17:42:06 +01:00
};
2024-09-24 12:33:51 +02:00
nixpkgs = defaultNixpkgs;
nodeNixpkgs = concatAttrs (builtins.map mkNixpkgs nodes);
specialArgs = {
lib = lib;
};
};
}
// (concatAttrs (builtins.map mkNode nodes))