all repos — nixfiles @ b32bf5bbd6ab2d493df866b0e6f7ecc83b731eaa

System and user configuration, managed by nix and home-manager

linde: extract git server setup to own file

Alan Pearce
commit

b32bf5bbd6ab2d493df866b0e6f7ecc83b731eaa

parent

abbb369ade5c2450e85c0803b47dc6808653951c

1 file changed, 47 insertions(+), 0 deletions(-)

changed files
A lib/caddy.nix
@@ -0,0 +1,47 @@
+{ lib +, ... +}: +rec { + subValue = v: + if builtins.isList v + then + builtins.concatStringsSep " " + (builtins.map + (v: + (if lib.strings.hasPrefix "http" v + then v + else "'${v}'")) + v) + else toString v; + + headerValue = sep: val: + if builtins.isAttrs val + then + builtins.concatStringsSep "; " + (lib.attrsets.mapAttrsToList + (k: v: + if builtins.isBool v then k else + "${k}${sep}${subValue v}" + ) + val) + else toString val; + genHeader = header: + let + sep = if header == "content-security-policy" then " " else "="; + in + value: "${header} \"${headerValue sep value}\""; + + headers = matcher: headers: '' + header ${matcher} { + ${builtins.concatStringsSep "\n" + (lib.attrsets.mapAttrsToList genHeader headers)} + } + ''; + security-headers = { matcher ? "", overrides ? { } }: headers matcher ({ + strict-transport-security = { + max-age = 2 * 365 * 24 * 60 * 60; + }; + x-content-type-options = "nosniff"; + x-frame-options = "DENY"; + } // overrides); +}