aboutsummaryrefslogblamecommitdiff
path: root/modules/private/websites/tools/assets/default.nix
blob: 0eb476d6746071e5c6d5a5702e8296a513486338 (plain) (tree)






































                                                                                 
{ lib, pkgs, config, ... }:
let
  cfg = config.myServices.websites.tools.assets;
  assets_urls = lib.mapAttrs (k: v: pkgs.fetchurl v) config.myEnv.tools.assets;
  assets = pkgs.runCommand "assets" {} (''
    mkdir -p $out
    cp -a ${./static}/* $out/
  '' + builtins.concatStringsSep "\n"
    (lib.mapAttrsToList (k: v: ''
      install -D -m644 -T ${v} $out/${k}
    '') assets_urls));
in
{
  options.myServices.websites.tools.assets = {
    enable = lib.mkEnableOption "Enable assets website";
  };
  config = lib.mkIf cfg.enable {
    services.websites.env.tools.vhostConfs.assets = {
      certName = "eldiron";
      addToCerts = true;
      hosts = [ "assets.immae.eu" ];
      root = assets;
      extraConfig = [
        ''
          Use Apaxy "${assets}" "title"
          <Directory "${assets}">
            Options Indexes FollowSymlinks
            AllowOverride None
            Require all granted
            Header always set Last-Modified "Tue, 01 Jan 2020 00:00:00 GMT"
            Header always set Cache-Control "public, max-age=31536000, immutable"
            Header always set Access-Control-Allow-Origin "*"
            Header always set Access-Control-Expose-Headers "*"
          </Directory>
        ''
      ];
    };
  };
}