about summary refs log tree commit diff
path: root/modules/server/ftp/default.nix
blob: 32b080d3bd8cee4c739ff493620d4e662e5b68be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{ pkgs, lib, config, ... }:

with lib;

let
  cfg = config.ftp;
in

{
  options = {
    ftp = {
      files = mkOption {
        default = {};
        type = with types; attrsOf path;
        description = ''
          Files to serve on https://ftp.qyliss.net/
        '';
        example = literalExample ''
          {
            "foo/bar.txt" = pkgs.writeText "bar.txt" ''''
              Hello, world!
            '''';
          }
        '';
      };
    };
  };

  config = {
    services.nginx.virtualHosts."ftp.qyliss.net" = {
      forceSSL = true;
      useACMEHost = "qyliss.net";

      root = pkgs.runCommand "ftp.qyliss.net" {} ''
        mkdir $out
        ${concatStrings (mapAttrsToList (httpPath: diskPath: ''
          mkdir -p "$out/$(dirname ${escapeShellArg httpPath})"
          ln -s ${escapeShellArg diskPath} $out/${escapeShellArg httpPath}
        '') cfg.files)}
      '';

      extraConfig = ''
        autoindex on;
      '';
    };

    security.acme.certs."qyliss.net".extraDomainNames = [ "ftp.qyliss.net" ];
  };
}