summaryrefslogtreecommitdiffstats
path: root/3modules/tv/nginx.nix
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-07-11 19:44:49 +0200
committertv <tv@shackspace.de>2015-07-11 19:44:49 +0200
commitbd65d2be622369d4f4b55a1d5e64aedf58506189 (patch)
tree22ddca93839a9cb9efb03fcc807dc12b1b9ea8a8 /3modules/tv/nginx.nix
parent2bc5c58d85990e483af8fde57ed5f2442351b69c (diff)
parentd213df5c00d3073d2f3bc09471fce466153df881 (diff)
Merge branch 'next'
Diffstat (limited to '3modules/tv/nginx.nix')
-rw-r--r--3modules/tv/nginx.nix83
1 files changed, 83 insertions, 0 deletions
diff --git a/3modules/tv/nginx.nix b/3modules/tv/nginx.nix
new file mode 100644
index 000000000..d9d95be84
--- /dev/null
+++ b/3modules/tv/nginx.nix
@@ -0,0 +1,83 @@
+{ config, pkgs, lib, ... }:
+
+with builtins;
+with lib;
+let
+ cfg = config.tv.nginx;
+
+ out = {
+ options.tv.nginx = api;
+ config = mkIf cfg.enable imp;
+ };
+
+ api = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = "Enable nginx.";
+ };
+
+ retiolum-locations = mkOption {
+ type = with types; listOf (attrsOf str);
+ default = [];
+ };
+ };
+
+ imp = {
+ services.nginx =
+ let
+ name = config.tv.retiolum.name;
+ qname = "${name}.retiolum";
+ in
+ assert config.tv.retiolum.enable;
+ {
+ enable = true;
+ httpConfig = ''
+ include ${pkgs.nginx}/conf/mime.types;
+ default_type application/octet-stream;
+ sendfile on;
+ keepalive_timeout 65;
+ gzip on;
+ server {
+ listen 80 default_server;
+ server_name _;
+ location / {
+ return 404;
+ }
+ }
+ server {
+ listen 80;
+ server_name ${name} ${qname};
+
+ ${indent (concatStrings (map to-location cfg.retiolum-locations))}
+
+ location / {
+ return 404;
+ }
+ }
+ '';
+ };
+ };
+
+
+ indent = replaceChars ["\n"] ["\n "];
+
+ to-location = { name, value }: ''
+ location ${name} {
+ ${indent value}
+ }
+ '';
+
+in
+out
+
+
+#let
+# cfg = config.tv.nginx;
+# arg' = arg // { inherit cfg; };
+#in
+#
+#{
+# options.tv.nginx = import ./options.nix arg';
+# config = lib.mkIf cfg.enable (import ./config.nix arg');
+#}