refactor: small meta changes
This commit is contained in:
parent
7717a942e3
commit
4561728cfc
3 changed files with 112 additions and 124 deletions
36
hive.nix
36
hive.nix
|
@ -17,18 +17,16 @@ let
|
||||||
value = import ./machines/${name};
|
value = import ./machines/${name};
|
||||||
}) (builtins.readDir ./machines);
|
}) (builtins.readDir ./machines);
|
||||||
|
|
||||||
meta' = evalModules {
|
meta =
|
||||||
modules = [
|
(evalModules {
|
||||||
./kat/meta.nix
|
modules = [
|
||||||
{ machines = mapAttrs (_: n: n.meta) nodes; }
|
./kat/meta.nix
|
||||||
];
|
{ machines = mapAttrs (_: n: n.meta) nodes; }
|
||||||
specialArgs = {
|
];
|
||||||
inherit pkgs sources;
|
specialArgs = {
|
||||||
};
|
inherit pkgs sources;
|
||||||
};
|
};
|
||||||
meta = meta'.config // {
|
}).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 (
|
||||||
hubs
|
map (mapAttrsToList (_: node: node.subnets)) [
|
||||||
non-hubs
|
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 // {
|
||||||
|
|
|
@ -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 = {
|
||||||
|
|
191
kat/meta.nix
191
kat/meta.nix
|
@ -7,6 +7,7 @@
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
concatStringsSep
|
concatStringsSep
|
||||||
|
mapAttrs
|
||||||
mkOption
|
mkOption
|
||||||
;
|
;
|
||||||
inherit (lib.types)
|
inherit (lib.types)
|
||||||
|
@ -21,23 +22,25 @@ let
|
||||||
unspecified
|
unspecified
|
||||||
;
|
;
|
||||||
|
|
||||||
patched_lix = let
|
patched_lix =
|
||||||
fetchTree-fix = pkgs.fetchurl {
|
let
|
||||||
url = "https://gerrit.lix.systems/changes/lix~2399/revisions/1/patch?download";
|
fetchTree-fix = pkgs.fetchurl {
|
||||||
hash = "sha256-ecZOnpQmUYY2uSLwrt8QHkeLW+L5RZWVvi58h4GkGEY=";
|
url = "https://gerrit.lix.systems/changes/lix~2399/revisions/1/patch?download";
|
||||||
name = "fetchTree-fix";
|
hash = "sha256-ecZOnpQmUYY2uSLwrt8QHkeLW+L5RZWVvi58h4GkGEY=";
|
||||||
downloadToTemp = true;
|
name = "fetchTree-fix";
|
||||||
postFetch = ''
|
downloadToTemp = true;
|
||||||
base64 -d $downloadedFile > $out
|
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 = [
|
default_overlay_paths = [
|
||||||
"${sources.kat-pkgs}/overlay.nix"
|
"${sources.kat-pkgs}/overlay.nix"
|
||||||
|
@ -46,99 +49,85 @@ let
|
||||||
'')
|
'')
|
||||||
];
|
];
|
||||||
|
|
||||||
machine_meta =
|
machine_meta = {
|
||||||
{ config, ... }:
|
options = {
|
||||||
{
|
version = mkOption {
|
||||||
options = {
|
type = enum [
|
||||||
version = mkOption {
|
"stable"
|
||||||
type = enum [
|
"unstable"
|
||||||
"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;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
config.node_meta = rec {
|
patches = mkOption {
|
||||||
inherit (config)
|
type = listOf path;
|
||||||
version
|
default = [ ];
|
||||||
wg-key
|
};
|
||||||
vpn-ip4
|
overlay-paths = mkOption {
|
||||||
vpn-hub
|
type = listOf path;
|
||||||
subnets
|
default = [ ];
|
||||||
fqdn
|
# /!\ Take care of imported files
|
||||||
;
|
};
|
||||||
patches = [
|
|
||||||
./nginx-fallback.patch
|
wg-key = mkOption {
|
||||||
./ocamlPackagesExtentions.patch
|
type = nullOr str;
|
||||||
] ++ config.patches;
|
default = null;
|
||||||
overlay-paths = default_overlay_paths ++ config.overlay-paths;
|
};
|
||||||
nixpkgs-paths = {
|
vpn-ip4 = mkOption {
|
||||||
nixpkgs-src = pkgs.applyPatches {
|
type = nullOr str;
|
||||||
src = sources."nixpkgs-${version}";
|
default = null;
|
||||||
name = "nixpkgs-${version}-patched";
|
};
|
||||||
inherit patches;
|
vpn-hub = mkOption {
|
||||||
};
|
type = bool;
|
||||||
nixpkgs = pkgs.writeText "nixpkgs-entry.nix" ''
|
default = false;
|
||||||
{ overlays ? [ ], ... }@args:
|
description = ''
|
||||||
import ${nixpkgs-paths.nixpkgs-src} (args // {
|
Peering with a hub should give access to all subnets,
|
||||||
overlays = import ${nixpkgs-paths.overlays} ++ overlays;
|
while hubs are the only points with multiple peers.
|
||||||
})
|
Non hub peers with all hub, and vice-versa.
|
||||||
'';
|
TODO: multiple hubs ?
|
||||||
overlays = pkgs.writeText "nixpkgs-overlays.nix" ''
|
'';
|
||||||
[
|
};
|
||||||
${concatStringsSep "\n " (map (p: "(import ${p})") overlay-paths)}
|
subnets = mkOption {
|
||||||
]
|
type = listOf str;
|
||||||
'';
|
default = [ ];
|
||||||
};
|
};
|
||||||
home-manager = "${sources."home-manager-${version}"}/nixos";
|
fqdn = mkOption {
|
||||||
nixvim = import sources."nixvim-${version}";
|
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
|
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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue