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,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 // {

View file

@ -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 = {

View file

@ -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;