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
1# Shared functions for fleet configuration, available as `fleet` module argument1# Shared functions for fleet configuration, available as `fleet` module argument
2{ nixpkgs, hostNames }: with nixpkgs.lib; rec {2{
3 nixpkgs,
4 hostNames,
5}:
6with nixpkgs.lib; rec {
3 hostsToAttrs = f: listToAttrs (7 hostsToAttrs = f:
34 then "${this}-${other}"
28 else "${other}-${this}";35 else "${other}-${this}";
36
37 # For places, where fleet knows better than nixpkgs defaults
38 mkFleetDefault = mkOverride 999;
29}39}
3040
modifiedmodules/fleet/meta.nixdiffbeforeafterboth
--- a/modules/fleet/meta.nix
+++ b/modules/fleet/meta.nix
@@ -5,9 +5,12 @@
   nixpkgs,
   ...
 }:
-with lib; let
+with lib;
+with fleetLib; let
   hostModule = with types;
-    {...} @ hostConfig: {
+    {...} @ hostConfig: let
+      hostName = hostConfig.config._module.args.name;
+    in {
       options = {
         modules = mkOption {
           type = listOf (mkOptionType {
@@ -32,12 +35,19 @@
           description = "Nixos configuration";
         };
       };
-      config.nixosSystem = nixpkgs.lib.nixosSystem {
-        inherit (hostConfig.config) system modules;
-        specialArgs = {
-          inherit fleetLib;
-          fleet = fleetLib.hostsToAttrs (host: config.hosts.${host}.nixosSystem.config);
+      config = {
+        nixosSystem = nixpkgs.lib.nixosSystem {
+          inherit (hostConfig.config) system modules;
+          specialArgs = {
+            inherit fleetLib;
+            fleet = hostsToAttrs (host: config.hosts.${host}.nixosSystem.config);
+          };
         };
+        modules = [
+          ({...}: {
+            networking.hostName = mkFleetDefault hostName;
+          })
+        ];
       };
     };
   overlayType = mkOptionType {
@@ -69,7 +79,7 @@
     };
   };
   config = {
-    hosts = fleetLib.hostsToAttrs (host: {
+    hosts = hostsToAttrs (host: {
       modules =
         config.globalModules
         ++ [