refactor(hive/meta): meta module

This commit is contained in:
catvayor 2024-12-15 16:19:19 +01:00
parent cd2ef49dd9
commit d27db1e3ca
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
20 changed files with 136 additions and 95 deletions

View file

@ -2,68 +2,57 @@ let
mods = import ./modules; mods = import ./modules;
users = import ./users; users = import ./users;
sources = import ./npins; sources = import ./npins;
inherit (import sources.nix-patches { patchFile = ./patches; }) mkNixpkgsSrc; pkgs = import sources.nixpkgs-unstable { };
inherit (pkgs) lib;
inherit (lib)
mapAttrs
mapAttrs'
removeSuffix
evalModules
;
unstable = { nodes = mapAttrs' (name: _: {
nixpkgs = mkNixpkgsSrc { name = removeSuffix ".nix" name;
src = sources.nixpkgs-unstable;
version = "unstable";
};
home-manager = "${sources.home-manager-unstable}/nixos";
nixvim = import sources.nixvim-unstable;
};
stable = {
nixpkgs = mkNixpkgsSrc {
src = sources.nixpkgs-stable;
version = "stable";
};
home-manager = "${sources.home-manager-stable}/nixos";
nixvim = import sources.nixvim-stable;
};
inherit (import unstable.nixpkgs { }) lib;
nodes = lib.mapAttrs' (name: _: {
name = lib.removeSuffix ".nix" name;
value = import ./machines/${name}; value = import ./machines/${name};
}) (builtins.readDir ./machines); }) (builtins.readDir ./machines);
nodes-meta = lib.mapAttrs (_: n: n.meta) nodes; 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;
};
in in
{ {
meta = rec { meta = {
inherit (unstable) nixpkgs; nixpkgs = pkgs.path;
specialArgs = { specialArgs = {
inherit mods users sources; inherit
meta = nodes-meta; mods
versions = { users
inherit unstable stable; sources
}; meta
;
kat-path = ./kat;
}; };
nodeNixpkgs = lib.mapAttrs ( nodeNixpkgs = mapAttrs (_: node: node.nixpkgs-paths.nixpkgs-src) meta.machines;
_: node: nodeSpecialArgs = mapAttrs (_: node: { self-meta = node; }) meta.machines;
lib.foldl (
pkgs: patch:
mkNixpkgsSrc {
src = pkgs;
version = patch;
}
) (if node.unstable then unstable else stable).nixpkgs (node.nixPatches or [ ])
) nodes-meta;
nodeSpecialArgs = lib.mapAttrs (name: node: {
inherit (node) unstable;
self-version = (if node.unstable then unstable else stable) // {
nixpkgs = nodeNixpkgs.${name};
};
}) nodes-meta;
}; };
defaults = defaults =
{ {
name, name,
kat-path,
... ...
}: }:
{ {
imports = [ ./kat ]; imports = [ kat-path ];
networking.hostName = name; networking.hostName = name;
}; };
} }
// lib.mapAttrs (_: n: n.config) nodes // mapAttrs (_: n: n.config) nodes

View file

@ -3,7 +3,7 @@
config, config,
pkgs, pkgs,
sources, sources,
self-version, self-meta,
... ...
}: }:
with lib; with lib;
@ -12,7 +12,7 @@ with lib;
./users ./users
./proxies ./proxies
./root.nix ./root.nix
self-version.home-manager self-meta.home-manager
"${sources.disko}/module.nix" "${sources.disko}/module.nix"
]; ];
options.kat = { options.kat = {
@ -34,7 +34,6 @@ with lib;
(mkIf config.kat.addArgs { (mkIf config.kat.addArgs {
_module.args = { _module.args = {
ssh-keys = import ./ssh-keys { inherit lib; }; ssh-keys = import ./ssh-keys { inherit lib; };
kat-path = ./.;
}; };
}) })
{ {
@ -61,10 +60,11 @@ with lib;
}; };
systemd.network.enable = true; systemd.network.enable = true;
nixpkgs.overlays = map import self-meta.overlay-paths;
nix = { nix = {
nixPath = [ nixPath = [
"nixpkgs=${builtins.storePath pkgs.path}" "nixpkgs=${self-meta.nixpkgs-paths.nixpkgs}"
"nixos=${builtins.storePath pkgs.path}" "nixos=${self-meta.nixpkgs-paths.nixpkgs}"
]; ];
channel.enable = false; channel.enable = false;
settings.nix-path = config.nix.nixPath; settings.nix-path = config.nix.nixPath;

73
kat/meta.nix Normal file
View file

@ -0,0 +1,73 @@
{
lib,
sources,
pkgs,
...
}:
let
inherit (lib)
mkOption
concatStringsSep
;
inherit (lib.types)
attrsOf
listOf
submodule
enum
path
unspecified
;
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
};
node_meta = mkOption {
type = unspecified;
readOnly = true;
};
};
config.node_meta = rec {
inherit (config) version;
patches = [ ./nginx-fallback.patch ] ++ config.patches;
overlay-paths = [ "${sources.kat-pkgs}/overlay.nix" ] ++ 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 = [
${concatStringsSep "\n " (map (p: "(import ${p})") overlay-paths)}
] ++ overlays;
})
'';
};
home-manager = "${sources."home-manager-${version}"}/nixos";
nixvim = import sources."nixvim-${version}";
};
};
in
{
options.machines = mkOption {
type = attrsOf (submodule machine_meta);
};
}

View file

@ -1,4 +1,4 @@
{ config, pkgs, self-version, ... }: { config, pkgs, self-meta, ... }:
let let
zsh = import ./zsh.nix; zsh = import ./zsh.nix;
in in
@ -9,7 +9,7 @@ in
imports = [ imports = [
zsh.user zsh.user
./neovim.nix ./neovim.nix
self-version.nixvim.homeManagerModules.nixvim self-meta.nixvim.homeManagerModules.nixvim
]; ];
# options.kat = { # options.kat = {
# ssh = mkEnableOption "ssh configuration"; # ssh = mkEnableOption "ssh configuration";

View file

@ -1,7 +1,7 @@
{ {
meta = { meta = {
unstable = false; version = "unstable";
pkgsPatches = [ "betamail" ]; patches = [ ./procmail_322.patch ];
}; };
config = import ./configuration.nix; config = import ./configuration.nix;
} }

View file

@ -1,4 +1,4 @@
{ {
meta.unstable = true; meta.version = "unstable";
config = import ./configuration.nix; config = import ./configuration.nix;
} }

View file

@ -1,4 +1,4 @@
{ {
meta.unstable = false; meta.version = "stable";
config = import ./configuration.nix; config = import ./configuration.nix;
} }

View file

@ -1,5 +1,5 @@
{ {
meta.unstable = true; meta.version = "unstable";
config = config =
{ {
pkgs, pkgs,

View file

@ -1,5 +1,5 @@
{ {
meta.unstable = true; meta.version = "unstable";
config = config =
{ {
pkgs, pkgs,

View file

@ -1,4 +1,4 @@
{ {
meta.unstable = true; meta.version = "unstable";
config = import ./configuration.nix; config = import ./configuration.nix;
} }

View file

@ -5,7 +5,7 @@
kat-path, kat-path,
ssh-keys, ssh-keys,
sources, sources,
self-version, self-meta,
... ...
}: }:
{ {
@ -137,7 +137,7 @@
localAddress = "192.168.123.2"; localAddress = "192.168.123.2";
autoStart = true; autoStart = true;
specialArgs = { specialArgs = {
inherit kat-path ssh-keys sources self-version; inherit kat-path ssh-keys sources self-meta;
}; };
config = { config = {
imports = [ kat-path ]; imports = [ kat-path ];

View file

@ -1,4 +1,4 @@
{ {
meta.unstable = false; meta.version = "stable";
config = import ./configuration.nix; config = import ./configuration.nix;
} }

View file

@ -1,4 +1,4 @@
{ {
meta.unstable = true; meta.version = "unstable";
config = import ./configuration.nix; config = import ./configuration.nix;
} }

View file

@ -1,4 +1,4 @@
{ {
meta.unstable = true; meta.version = "unstable";
config = import ./configuration.nix; config = import ./configuration.nix;
} }

View file

@ -1,4 +1,4 @@
{ {
meta.unstable = true; meta.version = "unstable";
config = import ./configuration.nix; config = import ./configuration.nix;
} }

View file

@ -1,4 +1,4 @@
{ {
meta.unstable = false; meta.version = "stable";
config = import ./configuration.nix; config = import ./configuration.nix;
} }

View file

@ -39,19 +39,16 @@
"url": "https://github.com/nix-community/home-manager/archive/65912bc6841cf420eb8c0a20e03df7cbbff5963f.tar.gz", "url": "https://github.com/nix-community/home-manager/archive/65912bc6841cf420eb8c0a20e03df7cbbff5963f.tar.gz",
"hash": "026hmc30kkyd9ihpjd6cm1b22galdi164ardhmj5x5jcszhjx4r9" "hash": "026hmc30kkyd9ihpjd6cm1b22galdi164ardhmj5x5jcszhjx4r9"
}, },
"nix-patches": { "kat-pkgs": {
"type": "GitRelease", "type": "Git",
"repository": { "repository": {
"type": "Git", "type": "Git",
"url": "https://git.hubrecht.ovh/hubrecht/nix-patches" "url": "https://git.dgnum.eu/lbailly/kat-pkgs.git"
}, },
"pre_releases": false, "branch": "master",
"version_upper_bound": null, "revision": "6d804d5e17f7f6363fc300388b6cd6972810fc7c",
"release_prefix": null,
"version": "v0.5.0",
"revision": "e11ba20945f4a867f09d84343c37328288f274b4",
"url": null, "url": null,
"hash": "1c6cc44pwlg3ky6cnwhkml8ci77fw3sgjhwvqg0f6igxxf2fqv9v" "hash": "1scfmdvm81b1ayi78k0kpg573vhxcvbzqvamzrs0g7xq5gv96imk"
}, },
"nixos-images": { "nixos-images": {
"type": "Git", "type": "Git",

View file

@ -1,18 +0,0 @@
let
general = [
{
_type = "static";
path = ./nginx-fallback.patch;
}
];
in
{
unstable = general;
stable = general;
betamail = [
{
_type = "static";
path = ./procmail_322.patch;
}
];
}