From 4561728cfcbd90a4a210704d8d19662a598a0aa6 Mon Sep 17 00:00:00 2001 From: catvayor Date: Sun, 2 Mar 2025 10:20:19 +0100 Subject: [PATCH] refactor: small meta changes --- hive.nix | 36 ++++----- kat/default.nix | 9 +-- kat/meta.nix | 191 +++++++++++++++++++++++------------------------- 3 files changed, 112 insertions(+), 124 deletions(-) diff --git a/hive.nix b/hive.nix index eb43757..b69de7a 100644 --- a/hive.nix +++ b/hive.nix @@ -17,18 +17,16 @@ let value = import ./machines/${name}; }) (builtins.readDir ./machines); - meta' = evalModules { - modules = [ - ./kat/meta.nix - { machines = mapAttrs (_: n: n.meta) nodes; } - ]; - specialArgs = { - inherit pkgs sources; - }; - }; - meta = meta'.config // { - machines = mapAttrs (_: node: node.node_meta) meta'.config.machines; - }; + meta = + (evalModules { + modules = [ + ./kat/meta.nix + { machines = mapAttrs (_: n: n.meta) nodes; } + ]; + specialArgs = { + inherit pkgs sources; + }; + }).config; meta-lib = self: rec { self-meta = meta.machines.${self}; @@ -38,11 +36,13 @@ let hubs = filterAttrs (_: node: node.vpn-hub) other-meta; non-hubs = filterAttrs (_: node: node.wg-key != null && !node.vpn-hub) other-meta; all-subnets = - [ "10.42.0.0/16" ] ++ flatten - (map (mapAttrsToList (_: node: node.subnets)) [ - hubs - non-hubs - ]); + [ "10.42.0.0/16" ] + ++ flatten ( + map (mapAttrsToList (_: node: node.subnets)) [ + hubs + non-hubs + ] + ); in if self-meta.vpn-hub then mapAttrsToList (_: node: { @@ -69,7 +69,7 @@ in users = import ./users; kat-path = ./kat; }; - nodeNixpkgs = mapAttrs (_: node: node.nixpkgs-paths.nixpkgs-src) meta.machines; + nodeNixpkgs = mapAttrs (_: node: node.nixpkgs) meta.machines; nodeSpecialArgs = mapAttrs (name: node: { self-meta = node; meta = meta // { diff --git a/kat/default.nix b/kat/default.nix index 6c51717..471baeb 100644 --- a/kat/default.nix +++ b/kat/default.nix @@ -65,13 +65,12 @@ in }; systemd.network.enable = true; - nixpkgs.overlays = import self-meta.nixpkgs-paths.overlays; + nixpkgs.overlays = import self-meta.nixpkgs-overlays; nix = { nixPath = [ - "nixpkgs=${self-meta.nixpkgs-paths.nixpkgs}" - "nixos=${self-meta.nixpkgs-paths.nixpkgs}" - "nixpkgs-src=${self-meta.nixpkgs-paths.nixpkgs-src}" - "overlays=${self-meta.nixpkgs-paths.overlays}" + "nixpkgs=${self-meta.nixpkgs}" + "nixos=${self-meta.nixpkgs}" + "nixpkgs-overlays=${self-meta.nixpkgs-overlays}" ]; channel.enable = false; settings = { diff --git a/kat/meta.nix b/kat/meta.nix index e2c9194..d8446a1 100644 --- a/kat/meta.nix +++ b/kat/meta.nix @@ -7,6 +7,7 @@ let inherit (lib) concatStringsSep + mapAttrs mkOption ; inherit (lib.types) @@ -21,23 +22,25 @@ let unspecified ; - patched_lix = let - fetchTree-fix = pkgs.fetchurl { - url = "https://gerrit.lix.systems/changes/lix~2399/revisions/1/patch?download"; - hash = "sha256-ecZOnpQmUYY2uSLwrt8QHkeLW+L5RZWVvi58h4GkGEY="; - name = "fetchTree-fix"; - downloadToTemp = true; - postFetch = '' - base64 -d $downloadedFile > $out - ''; + patched_lix = + let + fetchTree-fix = pkgs.fetchurl { + url = "https://gerrit.lix.systems/changes/lix~2399/revisions/1/patch?download"; + hash = "sha256-ecZOnpQmUYY2uSLwrt8QHkeLW+L5RZWVvi58h4GkGEY="; + name = "fetchTree-fix"; + downloadToTemp = true; + postFetch = '' + base64 -d $downloadedFile > $out + ''; + }; + in + pkgs.applyPatches { + src = sources.lix; + name = "lix"; + patches = [ + fetchTree-fix + ]; }; - in pkgs.applyPatches { - src = sources.lix; - name = "lix"; - patches = [ - fetchTree-fix - ]; - }; default_overlay_paths = [ "${sources.kat-pkgs}/overlay.nix" @@ -46,99 +49,85 @@ let '') ]; - machine_meta = - { config, ... }: - { - options = { - version = mkOption { - type = enum [ - "stable" - "unstable" - ]; - }; - patches = mkOption { - type = listOf path; - default = [ ]; - }; - overlay-paths = mkOption { - type = listOf path; - default = [ ]; - # /!\ Take care of imported files - }; - - wg-key = mkOption { - type = nullOr str; - default = null; - }; - vpn-ip4 = mkOption { - type = nullOr str; - default = null; - }; - vpn-hub = mkOption { - type = bool; - default = false; - description = '' - Peering with a hub should give access to all subnets, - while hubs are the only points with multiple peers. - Non hub peers with all hub, and vice-versa. - TODO: multiple hubs ? - ''; - }; - subnets = mkOption { - type = listOf str; - default = [ ]; - }; - fqdn = mkOption { - type = nullOr str; - default = null; - }; - - node_meta = mkOption { - type = unspecified; - readOnly = true; - }; + machine_meta = { + options = { + version = mkOption { + type = enum [ + "stable" + "unstable" + ]; }; - config.node_meta = rec { - inherit (config) - version - wg-key - vpn-ip4 - vpn-hub - subnets - fqdn - ; - patches = [ - ./nginx-fallback.patch - ./ocamlPackagesExtentions.patch - ] ++ config.patches; - overlay-paths = default_overlay_paths ++ config.overlay-paths; - nixpkgs-paths = { - nixpkgs-src = pkgs.applyPatches { - src = sources."nixpkgs-${version}"; - name = "nixpkgs-${version}-patched"; - inherit patches; - }; - nixpkgs = pkgs.writeText "nixpkgs-entry.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)} - ] - ''; - }; - home-manager = "${sources."home-manager-${version}"}/nixos"; - nixvim = import sources."nixvim-${version}"; + patches = mkOption { + type = listOf path; + default = [ ]; + }; + overlay-paths = mkOption { + type = listOf path; + default = [ ]; + # /!\ Take care of imported files + }; + + wg-key = mkOption { + type = nullOr str; + default = null; + }; + vpn-ip4 = mkOption { + type = nullOr str; + default = null; + }; + vpn-hub = mkOption { + type = bool; + default = false; + description = '' + Peering with a hub should give access to all subnets, + while hubs are the only points with multiple peers. + Non hub peers with all hub, and vice-versa. + TODO: multiple hubs ? + ''; + }; + subnets = mkOption { + type = listOf str; + default = [ ]; + }; + fqdn = mkOption { + type = nullOr str; + default = null; }; }; + }; + node_meta = cfg: rec { + inherit (cfg) + version + wg-key + vpn-ip4 + vpn-hub + subnets + fqdn + ; + patches = [ + ./nginx-fallback.patch + ./ocamlPackagesExtentions.patch + ] ++ cfg.patches; + overlay-paths = default_overlay_paths ++ cfg.overlay-paths; + nixpkgs = pkgs.applyPatches { + src = sources."nixpkgs-${version}"; + name = "nixpkgs-${version}-patched"; + inherit patches; + }; + nixpkgs-overlays = pkgs.writeText "nixpkgs-overlays.nix" '' + [ + ${concatStringsSep "\n " (map (p: "(import ${p})") overlay-paths)} + ] + ''; + home-manager = "${sources."home-manager-${version}"}/nixos"; + nixvim = import sources."nixvim-${version}"; + }; in { options = { machines = mkOption { type = attrsOf (submodule machine_meta); + apply = mapAttrs (_: node_meta); }; general_overlays = mkOption { type = listOf unspecified;