From 98f20775683d70003fd1dbe28bacf074d9ff1601 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sun, 23 Jul 2023 21:46:53 +0200 Subject: [PATCH] machines: Add boilerplate for enabling modules and services --- lib/trivial.nix | 5 ++++ machines/compute01/_configuration.nix | 27 ++++++++++++++++++---- machines/storage01/_configuration.nix | 28 ++++++++++++++++++----- machines/web01/_configuration.nix | 33 +++++++++++++++++---------- 4 files changed, 71 insertions(+), 22 deletions(-) diff --git a/lib/trivial.nix b/lib/trivial.nix index 075a99f..cd848c0 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -25,6 +25,11 @@ rec { */ singleAttr = name: value: { ${name} = value; }; + /* Enables a list of modules. */ + enableAttrs' = enable: mapFuse (m: { ${m}.${enable} = true; }); + + enableModules = enableAttrs' "enable"; + mapSingleFuse = f: mapFuse (x: singleAttr x (f x)); setDefault = default: mapFuse (name: { ${name} = default; }); diff --git a/machines/compute01/_configuration.nix b/machines/compute01/_configuration.nix index 6f592f2..c9c4f3d 100644 --- a/machines/compute01/_configuration.nix +++ b/machines/compute01/_configuration.nix @@ -1,6 +1,25 @@ -{ ... }: +{ dgn-lib, ... }: -{ - dgn-dns.enable = true; +let + inherit (dgn-lib) + enableModules + mkImports + recursiveFuse; -} + # List of modules to enable + enabledModules = [ + "dgn-dns" + ]; + + # List of services to enable + enabledServices = [ + ]; +in + +recursiveFuse [ + (enableModules enabledModules) + + { + imports = mkImports ./. enabledServices; + } +] diff --git a/machines/storage01/_configuration.nix b/machines/storage01/_configuration.nix index 81428ad..f9ff469 100644 --- a/machines/storage01/_configuration.nix +++ b/machines/storage01/_configuration.nix @@ -1,8 +1,24 @@ -# Edit this configuration file to define what should be installed on -# your system. Help is available in the configuration.nix(5) man page -# and in the NixOS manual (accessible by running `nixos-help`). +{ dgn-lib, ... }: -{ config, pkgs, ... }: +let + inherit (dgn-lib) + enableModules + mkImports + recursiveFuse; -{ -} + # List of modules to enable + enabledModules = [ + ]; + + # List of services to enable + enabledServices = [ + ]; +in + +recursiveFuse [ + (enableModules enabledModules) + + { + imports = mkImports ./. enabledServices; + } +] diff --git a/machines/web01/_configuration.nix b/machines/web01/_configuration.nix index b1ee27a..2410d92 100644 --- a/machines/web01/_configuration.nix +++ b/machines/web01/_configuration.nix @@ -1,17 +1,26 @@ -# Edit this configuration file to define what should be installed on -# your system. Help is available in the configuration.nix(5) man page -# and in the NixOS manual (accessible by running ‘nixos-help’). +{ dgn-lib, ... }: -{ name, ... }: +let + inherit (dgn-lib) + enableModules + mkImports + recursiveFuse; -{ - imports = - [ - ./plausible.nix - # ./wordpress - ]; + # List of modules to enable + enabledModules = [ + ]; - networking.hostName = name; + # List of services to enable + enabledServices = [ + "plausible" + # "wordpress" + ]; +in +recursiveFuse [ + (enableModules enabledModules) -} + { + imports = mkImports ./. enabledServices; + } +]