git.delta.rocks / jrsonnet / refs/commits / a31940c2af82

difftreelog

feat apply networking.hostName from fleet attr name

Yaroslav Bolyukin2024-01-07parent: #0dbf004.patch.diff
in: trunk

2 files changed

modifiedlib/fleetLib.nixdiffbeforeafterboth
--- a/lib/fleetLib.nix
+++ b/lib/fleetLib.nix
@@ -1,29 +1,39 @@
 # Shared functions for fleet configuration, available as `fleet` module argument
-{ nixpkgs, hostNames }: with nixpkgs.lib; rec {
-  hostsToAttrs = f: listToAttrs (
-    map (name: { inherit name; value = f name; }) hostNames
-  );
+{
+  nixpkgs,
+  hostNames,
+}:
+with nixpkgs.lib; rec {
+  hostsToAttrs = f:
+    listToAttrs (
+      map (name: {
+        inherit name;
+        value = f name;
+      })
+      hostNames
+    );
   hostsCartesian = remove null (
     unique (
       crossLists
-        (
-          a: b:
-            if a == b then
-              null
-            else
-              hostsPair a b
-        ) [ hostNames hostNames ]
+      (
+        a: b:
+          if a == b
+          then null
+          else hostsPair a b
+      ) [hostNames hostNames]
     )
   );
-  hostsPair = this: other:
-    let
-      sorted = sort (a: b: a < b) [ this other ];
-    in
-    {
-      a = elemAt sorted 0;
-      b = elemAt sorted 1;
-    };
+  hostsPair = this: other: let
+    sorted = sort (a: b: a < b) [this other];
+  in {
+    a = elemAt sorted 0;
+    b = elemAt sorted 1;
+  };
   hostPairName = this: other:
-    if this < other then "${this}-${other}"
+    if this < other
+    then "${this}-${other}"
     else "${other}-${this}";
+
+  # For places, where fleet knows better than nixpkgs defaults
+  mkFleetDefault = mkOverride 999;
 }
modifiedmodules/fleet/meta.nixdiffbeforeafterboth
6 ...6 ...
7}:7}:
8with lib; let8with lib;
9with fleetLib; let
9 hostModule = with types;10 hostModule = with types;
10 {...} @ hostConfig: {11 {...} @ hostConfig: let
12 hostName = hostConfig.config._module.args.name;
13 in {
11 options = {14 options = {
12 modules = mkOption {15 modules = mkOption {
13 type = listOf (mkOptionType {16 type = listOf (mkOptionType {
32 description = "Nixos configuration";35 description = "Nixos configuration";
33 };36 };
34 };37 };
35 config.nixosSystem = nixpkgs.lib.nixosSystem {38 config = {
39 nixosSystem = nixpkgs.lib.nixosSystem {
36 inherit (hostConfig.config) system modules;40 inherit (hostConfig.config) system modules;
37 specialArgs = {41 specialArgs = {
38 inherit fleetLib;42 inherit fleetLib;
39 fleet = fleetLib.hostsToAttrs (host: config.hosts.${host}.nixosSystem.config);43 fleet = hostsToAttrs (host: config.hosts.${host}.nixosSystem.config);
40 };44 };
41 };45 };
46 modules = [
47 ({...}: {
48 networking.hostName = mkFleetDefault hostName;
49 })
50 ];
51 };
42 };52 };
43 overlayType = mkOptionType {53 overlayType = mkOptionType {
44 name = "nixpkgs-overlay";54 name = "nixpkgs-overlay";
69 };79 };
70 };80 };
71 config = {81 config = {
72 hosts = fleetLib.hostsToAttrs (host: {82 hosts = hostsToAttrs (host: {
73 modules =83 modules =
74 config.globalModules84 config.globalModules
75 ++ [85 ++ [