Personal-use NixOS configuration
at main 40 lines 917 B view raw
1{ lib }: 2 3# hosts: 4# [ { name = str; ssl = str; useLocal = bool?; extraConfig = string?; } ]; 5hosts: proxy: 6 7let 8 caddyModulesPath = ../config/server/caddy/modules; 9 10 compressionModules = import (caddyModulesPath + /compression.nix); 11 sslModules = import (caddyModulesPath + /ssl.nix); 12 13 insertLocalSubdomain = 14 host: 15 let 16 domainLevels = lib.splitString "." host; 17 totalLevels = (lib.length domainLevels - 2); 18 in 19 lib.concatStringsSep "." ( 20 lib.take totalLevels domainLevels ++ [ "local" ] ++ lib.drop totalLevels domainLevels 21 ); 22in 23builtins.listToAttrs ( 24 map (host: { 25 name = host.name; 26 27 value = { 28 serverAliases = lib.optional (host.useLocal or false) (insertLocalSubdomain host.name); 29 30 extraConfig = '' 31 ${compressionModules.basic} 32 ${sslModules.${host.ssl}} 33 34 ${proxy} 35 36 ${host.extraConfig or ""} 37 ''; 38 }; 39 }) hosts 40)