stockholm/krebs/3modules/nginx.nix

73 lines
1.5 KiB
Nix
Raw Normal View History

2015-07-11 14:55:22 +00:00
{ config, pkgs, lib, ... }:
with builtins;
with lib;
let
2015-07-24 09:50:23 +00:00
cfg = config.krebs.nginx;
2015-07-11 14:55:22 +00:00
out = {
2015-07-24 09:50:23 +00:00
options.krebs.nginx = api;
2015-07-11 14:55:22 +00:00
config = mkIf cfg.enable imp;
};
api = {
2015-07-24 09:50:23 +00:00
enable = mkEnableOption "krebs.nginx";
2015-07-11 14:55:22 +00:00
servers = mkOption {
type = with types; attrsOf optionSet;
options = singleton {
server-names = mkOption {
type = with types; listOf str;
2015-07-24 09:50:23 +00:00
# TODO use identity
default = [
"${config.networking.hostName}"
"${config.networking.hostName}.retiolum"
];
};
locations = mkOption {
type = with types; listOf (attrsOf str);
};
};
default = {};
2015-07-11 14:55:22 +00:00
};
};
imp = {
services.nginx = {
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 _;
return 404;
}
${concatStrings (mapAttrsToList (_: to-server) cfg.servers)}
'';
};
2015-07-11 14:55:22 +00:00
};
indent = replaceChars ["\n"] ["\n "];
to-location = { name, value }: ''
location ${name} {
${indent value}
}
'';
to-server = { server-names, locations, ... }: ''
server {
listen 80;
server_name ${toString server-names};
${indent (concatStrings (map to-location locations))}
}
'';
2015-07-11 14:55:22 +00:00
in
out