about summary refs log tree commit diff
path: root/modules/server/ftp/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/server/ftp/default.nix')
-rw-r--r--modules/server/ftp/default.nix49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/server/ftp/default.nix b/modules/server/ftp/default.nix
new file mode 100644
index 000000000000..5fbf3f82877c
--- /dev/null
+++ b/modules/server/ftp/default.nix
@@ -0,0 +1,49 @@
+{ pkgs, lib, config, ... }:
+
+with lib;
+
+let
+  cfg = config.ftp;
+in
+
+{
+  options = {
+    ftp = {
+      files = mkOption {
+        default = {};
+        type = with types; attrsOf path;
+        description = mdDoc ''
+          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" ];
+  };
+}