docker-webdev.nix (1086B)
1 { config, lib, username, ... }: 2 3 let 4 5 webdevDir = "/home/${username}/vault/src/webdev"; 6 domainExtensions = [ ".com" ".net" ".org" ".co.uk" ".dev" ]; 7 8 domains = builtins.attrNames ( 9 lib.filterAttrs 10 (name: type: 11 type == "directory" && 12 builtins.any (ext: lib.hasSuffix ext name) domainExtensions) 13 (builtins.readDir webdevDir)); 14 15 containerName = domain: "hugo-${lib.replaceStrings ["."] ["-"] domain}"; 16 17 makeHugoContainer = domain: { 18 name = containerName domain; 19 value = { 20 autoStart = true; 21 dependsOn = [ "caddy" ]; 22 image = "klakegg/hugo"; 23 cmd = [ "server" "--watch=true" "--disableLiveReload" "--minify" "--source=/src" "--baseURL=https://${domain}" "--bind=0.0.0.0" "--appendPort=false" "--buildFuture" ]; 24 labels = { "caddy" = "${domain}, www.${domain}"; "caddy.reverse_proxy" = "{{upstreams 1313}}"; }; 25 networks = [ "proxy" ]; 26 volumes = [ "${webdevDir}/${domain}:/src" ]; 27 }; 28 }; 29 30 in { 31 virtualisation.oci-containers.containers = 32 builtins.listToAttrs (map makeHugoContainer domains); 33 }