From c43adc80cb1949879e265c02b8e0895a9702223e Mon Sep 17 00:00:00 2001 From: Yves Dubromelle Date: Tue, 30 May 2017 23:21:33 +0200 Subject: [PATCH] utilisation des profils pour modifier les flags :) --- lib.nix | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib.nix b/lib.nix index a796258..7d907ec 100644 --- a/lib.nix +++ b/lib.nix @@ -14,17 +14,33 @@ let graphical = true; docker = true; }; - isServer = { - }; + #isServer = { + #}; }; in -rec { +with lib; rec{ + # Apply the profiles (pre-defined + custom) to the whole directory applyProfilesToDirectory = customProfiles: directory: lib.mapAttrs (applyProfilesToMachine customProfiles) directory; + # Apply the profiles (pre-defined + custom) to a machine applyProfilesToMachine = customProfiles: machineName: machineOptions: - machineOptions; - #lib.recursiveUpdate {} machineOptions; + { configuration-flags = lib.recursiveUpdate (generateFlagsSet customProfiles machineOptions.profiles) machineOptions.configuration-flags; + ipAddress = machineOptions.ipAddress; + tinc = machineOptions.tinc; + profiles = machineOptions.profiles; + }; + + # Generate a set of configuration flags based on profiles + generateFlagsSet = customProfiles: machineProfiles: + let + allProfiles = recursiveUpdate profiles customProfiles; + conditionalFlags = name: value: + if machineProfiles.${name} + then value + else {}; + in + foldr (a: b: a // b) {} (mapAttrsToList conditionalFlags allProfiles); }