difftreelog
feat apply networking.hostName from fleet attr name
in: trunk
2 files changed
lib/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;
}
modules/fleet/meta.nixdiffbeforeafterboth1{2 lib,3 fleetLib,4 config,5 nixpkgs,6 ...7}:8with lib; let9 hostModule = with types;10 {...} @ hostConfig: {11 options = {12 modules = mkOption {13 type = listOf (mkOptionType {14 name = "submodule";15 inherit (submodule {}) check;16 merge = lib.options.mergeOneOption;17 description = "Nixos modules";18 });19 description = "List of nixos modules";20 default = [];21 };22 system = mkOption {23 type = str;24 description = "Type of system";25 };26 encryptionKey = mkOption {27 type = str;28 description = "Encryption key";29 };30 nixosSystem = mkOption {31 type = unspecified;32 description = "Nixos configuration";33 };34 };35 config.nixosSystem = nixpkgs.lib.nixosSystem {36 inherit (hostConfig.config) system modules;37 specialArgs = {38 inherit fleetLib;39 fleet = fleetLib.hostsToAttrs (host: config.hosts.${host}.nixosSystem.config);40 };41 };42 };43 overlayType = mkOptionType {44 name = "nixpkgs-overlay";45 description = "nixpkgs overlay";46 check = lib.isFunction;47 merge = lib.mergeOneOption;48 };49in {50 options = with types; {51 hosts = mkOption {52 type = attrsOf (submodule hostModule);53 default = {};54 description = "Configurations of individual hosts";55 };56 globalModules = mkOption {57 type = listOf (mkOptionType {58 name = "submodule";59 inherit (submodule {}) check;60 merge = lib.options.mergeOneOption;61 description = "Nixos modules";62 });63 description = "Modules, which should be added to every system";64 default = [];65 };66 overlays = mkOption {67 default = [];68 type = listOf overlayType;69 };70 };71 config = {72 hosts = fleetLib.hostsToAttrs (host: {73 modules =74 config.globalModules75 ++ [76 ({...}: {77 nixpkgs.overlays = config.overlays;78 })79 ];80 });81 globalModules = import ../../nixos/modules/module-list.nix;82 };83}