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;
users = import ./users;
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 = {
nixpkgs = mkNixpkgsSrc {
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;
nodes = mapAttrs' (name: _: {
name = removeSuffix ".nix" name;
value = import ./machines/${name};
}) (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
{
meta = rec {
inherit (unstable) nixpkgs;
meta = {
nixpkgs = pkgs.path;
specialArgs = {
inherit mods users sources;
meta = nodes-meta;
versions = {
inherit unstable stable;
};
inherit
mods
users
sources
meta
;
kat-path = ./kat;
};
nodeNixpkgs = lib.mapAttrs (
_: node:
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;
nodeNixpkgs = mapAttrs (_: node: node.nixpkgs-paths.nixpkgs-src) meta.machines;
nodeSpecialArgs = mapAttrs (_: node: { self-meta = node; }) meta.machines;
};
defaults =
{
name,
kat-path,
...
}:
{
imports = [ ./kat ];
imports = [ kat-path ];
networking.hostName = name;
};
}
// lib.mapAttrs (_: n: n.config) nodes
// mapAttrs (_: n: n.config) nodes

View file

@ -3,7 +3,7 @@
config,
pkgs,
sources,
self-version,
self-meta,
...
}:
with lib;
@ -12,7 +12,7 @@ with lib;
./users
./proxies
./root.nix
self-version.home-manager
self-meta.home-manager
"${sources.disko}/module.nix"
];
options.kat = {
@ -34,7 +34,6 @@ with lib;
(mkIf config.kat.addArgs {
_module.args = {
ssh-keys = import ./ssh-keys { inherit lib; };
kat-path = ./.;
};
})
{
@ -61,10 +60,11 @@ with lib;
};
systemd.network.enable = true;
nixpkgs.overlays = map import self-meta.overlay-paths;
nix = {
nixPath = [
"nixpkgs=${builtins.storePath pkgs.path}"
"nixos=${builtins.storePath pkgs.path}"
"nixpkgs=${self-meta.nixpkgs-paths.nixpkgs}"
"nixos=${self-meta.nixpkgs-paths.nixpkgs}"
];
channel.enable = false;
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
zsh = import ./zsh.nix;
in
@ -9,7 +9,7 @@ in
imports = [
zsh.user
./neovim.nix
self-version.nixvim.homeManagerModules.nixvim
self-meta.nixvim.homeManagerModules.nixvim
];
# options.kat = {
# ssh = mkEnableOption "ssh configuration";

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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