refactor: small meta changes

This commit is contained in:
catvayor 2025-03-02 10:20:19 +01:00
parent 7717a942e3
commit 4561728cfc
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
3 changed files with 112 additions and 124 deletions

View file

@ -17,7 +17,8 @@ let
value = import ./machines/${name}; value = import ./machines/${name};
}) (builtins.readDir ./machines); }) (builtins.readDir ./machines);
meta' = evalModules { meta =
(evalModules {
modules = [ modules = [
./kat/meta.nix ./kat/meta.nix
{ machines = mapAttrs (_: n: n.meta) nodes; } { machines = mapAttrs (_: n: n.meta) nodes; }
@ -25,10 +26,7 @@ let
specialArgs = { specialArgs = {
inherit pkgs sources; inherit pkgs sources;
}; };
}; }).config;
meta = meta'.config // {
machines = mapAttrs (_: node: node.node_meta) meta'.config.machines;
};
meta-lib = self: rec { meta-lib = self: rec {
self-meta = meta.machines.${self}; self-meta = meta.machines.${self};
@ -38,11 +36,13 @@ let
hubs = filterAttrs (_: node: node.vpn-hub) other-meta; hubs = filterAttrs (_: node: node.vpn-hub) other-meta;
non-hubs = filterAttrs (_: node: node.wg-key != null && !node.vpn-hub) other-meta; non-hubs = filterAttrs (_: node: node.wg-key != null && !node.vpn-hub) other-meta;
all-subnets = all-subnets =
[ "10.42.0.0/16" ] ++ flatten [ "10.42.0.0/16" ]
(map (mapAttrsToList (_: node: node.subnets)) [ ++ flatten (
map (mapAttrsToList (_: node: node.subnets)) [
hubs hubs
non-hubs non-hubs
]); ]
);
in in
if self-meta.vpn-hub then if self-meta.vpn-hub then
mapAttrsToList (_: node: { mapAttrsToList (_: node: {
@ -69,7 +69,7 @@ in
users = import ./users; users = import ./users;
kat-path = ./kat; kat-path = ./kat;
}; };
nodeNixpkgs = mapAttrs (_: node: node.nixpkgs-paths.nixpkgs-src) meta.machines; nodeNixpkgs = mapAttrs (_: node: node.nixpkgs) meta.machines;
nodeSpecialArgs = mapAttrs (name: node: { nodeSpecialArgs = mapAttrs (name: node: {
self-meta = node; self-meta = node;
meta = meta // { meta = meta // {

View file

@ -65,13 +65,12 @@ in
}; };
systemd.network.enable = true; systemd.network.enable = true;
nixpkgs.overlays = import self-meta.nixpkgs-paths.overlays; nixpkgs.overlays = import self-meta.nixpkgs-overlays;
nix = { nix = {
nixPath = [ nixPath = [
"nixpkgs=${self-meta.nixpkgs-paths.nixpkgs}" "nixpkgs=${self-meta.nixpkgs}"
"nixos=${self-meta.nixpkgs-paths.nixpkgs}" "nixos=${self-meta.nixpkgs}"
"nixpkgs-src=${self-meta.nixpkgs-paths.nixpkgs-src}" "nixpkgs-overlays=${self-meta.nixpkgs-overlays}"
"overlays=${self-meta.nixpkgs-paths.overlays}"
]; ];
channel.enable = false; channel.enable = false;
settings = { settings = {

View file

@ -7,6 +7,7 @@
let let
inherit (lib) inherit (lib)
concatStringsSep concatStringsSep
mapAttrs
mkOption mkOption
; ;
inherit (lib.types) inherit (lib.types)
@ -21,7 +22,8 @@ let
unspecified unspecified
; ;
patched_lix = let patched_lix =
let
fetchTree-fix = pkgs.fetchurl { fetchTree-fix = pkgs.fetchurl {
url = "https://gerrit.lix.systems/changes/lix~2399/revisions/1/patch?download"; url = "https://gerrit.lix.systems/changes/lix~2399/revisions/1/patch?download";
hash = "sha256-ecZOnpQmUYY2uSLwrt8QHkeLW+L5RZWVvi58h4GkGEY="; hash = "sha256-ecZOnpQmUYY2uSLwrt8QHkeLW+L5RZWVvi58h4GkGEY=";
@ -31,7 +33,8 @@ let
base64 -d $downloadedFile > $out base64 -d $downloadedFile > $out
''; '';
}; };
in pkgs.applyPatches { in
pkgs.applyPatches {
src = sources.lix; src = sources.lix;
name = "lix"; name = "lix";
patches = [ patches = [
@ -46,9 +49,7 @@ let
'') '')
]; ];
machine_meta = machine_meta = {
{ config, ... }:
{
options = { options = {
version = mkOption { version = mkOption {
type = enum [ type = enum [
@ -92,14 +93,10 @@ let
type = nullOr str; type = nullOr str;
default = null; default = null;
}; };
node_meta = mkOption {
type = unspecified;
readOnly = true;
}; };
}; };
config.node_meta = rec { node_meta = cfg: rec {
inherit (config) inherit (cfg)
version version
wg-key wg-key
vpn-ip4 vpn-ip4
@ -110,35 +107,27 @@ let
patches = [ patches = [
./nginx-fallback.patch ./nginx-fallback.patch
./ocamlPackagesExtentions.patch ./ocamlPackagesExtentions.patch
] ++ config.patches; ] ++ cfg.patches;
overlay-paths = default_overlay_paths ++ config.overlay-paths; overlay-paths = default_overlay_paths ++ cfg.overlay-paths;
nixpkgs-paths = { nixpkgs = pkgs.applyPatches {
nixpkgs-src = pkgs.applyPatches {
src = sources."nixpkgs-${version}"; src = sources."nixpkgs-${version}";
name = "nixpkgs-${version}-patched"; name = "nixpkgs-${version}-patched";
inherit patches; inherit patches;
}; };
nixpkgs = pkgs.writeText "nixpkgs-entry.nix" '' nixpkgs-overlays = pkgs.writeText "nixpkgs-overlays.nix" ''
{ overlays ? [ ], ... }@args:
import ${nixpkgs-paths.nixpkgs-src} (args // {
overlays = import ${nixpkgs-paths.overlays} ++ overlays;
})
'';
overlays = pkgs.writeText "nixpkgs-overlays.nix" ''
[ [
${concatStringsSep "\n " (map (p: "(import ${p})") overlay-paths)} ${concatStringsSep "\n " (map (p: "(import ${p})") overlay-paths)}
] ]
''; '';
};
home-manager = "${sources."home-manager-${version}"}/nixos"; home-manager = "${sources."home-manager-${version}"}/nixos";
nixvim = import sources."nixvim-${version}"; nixvim = import sources."nixvim-${version}";
}; };
};
in in
{ {
options = { options = {
machines = mkOption { machines = mkOption {
type = attrsOf (submodule machine_meta); type = attrsOf (submodule machine_meta);
apply = mapAttrs (_: node_meta);
}; };
general_overlays = mkOption { general_overlays = mkOption {
type = listOf unspecified; type = listOf unspecified;