diff --git a/data/web.nix b/data/web.nix new file mode 100644 index 0000000..128a85a --- /dev/null +++ b/data/web.nix @@ -0,0 +1,34 @@ +let + lib = import ; + mapFileNameToContent = fileName: { + status = 200; + contentType = "text/html"; + content = builtins.readFile fileName; + }; + findFiles = dir: + let content = builtins.readDir dir; + processEntry = name: type: + if type == "directory" then + findFiles (dir + "/${name}") + else if type == "regular" then + [ (dir + "/${name}") ] + else + []; + in + lib.concatLists (lib.mapAttrsToList processEntry content); + removePrefix = str: prefix: if builtins.substring 0 (builtins.stringLength prefix) str == prefix + then builtins.substring (builtins.stringLength prefix) (builtins.stringLength str - builtins.stringLength prefix) str + else str; + contentFn = basePath: + let + files = findFiles basePath; + baseLength = builtins.stringLength basePath; + files' = builtins.filter (file: builtins.match ".*\\.html$" file != null) files; + in builtins.listToAttrs (map (file: { + name = removePrefix file basePath; + value = mapFileNameToContent file; + }) files'); +in +rec { + "nudelerde.de" = contentFn "/etc/nixos/data/web/"; +} \ No newline at end of file diff --git a/data/web/index.html b/data/web/index.html new file mode 100644 index 0000000..54e1ac2 --- /dev/null +++ b/data/web/index.html @@ -0,0 +1,11 @@ + + + + + Hii :3 + + + + Hiiii :3 + + \ No newline at end of file diff --git a/services/nginx.nix b/services/nginx.nix index c55dbf0..984db97 100644 --- a/services/nginx.nix +++ b/services/nginx.nix @@ -1,6 +1,7 @@ { config, pkgs, lib, ... }: let network = import ../data/network.nix; + web = import ../data/web.nix; virtualHostFn = name: service: let domain = if service ? domainOverride then service.domainOverride @@ -54,6 +55,22 @@ let } // serverAlias // sslConfig // externConnections // myExtraConfig; rproxyServices = builtins.mapAttrs (virtualHostFn) network.reverse_proxy; serviceNamesMessage = builtins.toString (builtins.attrNames network.reverse_proxy); + webHosts = lib.mapAttrs' (name: description: { + name = "${name}.web"; + value = { + serverName = "${name}"; + listen = [ {addr = "0.0.0.0"; port = 80;} {addr = "0.0.0.0"; port = 443; ssl = true;}]; + locations = lib.mapAttrs' (endpointName: endpointValue: { + name = endpointName; + value = { + extraConfig = '' + default_type ${endpointValue.contentType}; + return ${toString endpointValue.status} "${endpointValue.content}"; + ''; + }; + }) description; + }; + }) web; fallback = { serverName = "_"; listen = [ {addr = "0.0.0.0"; port = 80;}]; @@ -77,7 +94,7 @@ in { recommendedOptimisation = true; recommendedGzipSettings = true; - virtualHosts = rproxyServices // {fallback = fallback;}; + virtualHosts = rproxyServices // webHosts // {fallback = fallback;}; }; networking.firewall.allowedTCPPorts = network.usedPorts;