Format with nixfmt
Change-Id: If9839d2c3308538ac8f3e166b69675d3b40bd7d9
diff --git a/modules/nginx.nix b/modules/nginx.nix
index 64ad1ce..9ccf0b2 100644
--- a/modules/nginx.nix
+++ b/modules/nginx.nix
@@ -1,6 +1,5 @@
{ config, lib, pkgs, helpers, base, ... }:
-lib.recursiveUpdate
-{
+lib.recursiveUpdate {
options.clicks = {
nginx = {
services = lib.mkOption {
@@ -14,33 +13,25 @@
type = let
validServiceTypes = {
"redirect" = {
- to = ["string" str];
- permanent = ["bool" bool];
+ to = [ "string" str ];
+ permanent = [ "bool" bool ];
};
- "reverseproxy" = {
- to = ["string" str];
- };
+ "reverseproxy" = { to = [ "string" str ]; };
"php" = {
- root = ["string" str];
- socket = ["string" str];
+ root = [ "string" str ];
+ socket = [ "string" str ];
};
"directory" = {
- private = ["bool" bool];
- root = ["string" str];
+ private = [ "bool" bool ];
+ root = [ "string" str ];
};
- "file" = {
- path = ["string" str];
- };
+ "file" = { path = [ "string" str ]; };
"path" = {
- path = ["string" str];
- service = ["set" serviceType];
+ path = [ "string" str ];
+ service = [ "set" serviceType ];
};
- "compose" = {
- services = ["list" (listOf serviceType)];
- };
- "status" = {
- statusCode = ["int" int];
- };
+ "compose" = { services = [ "list" (listOf serviceType) ]; };
+ "status" = { statusCode = [ "int" int ]; };
};
serviceType = mkOptionType {
@@ -50,25 +41,36 @@
descriptionClass = "noun";
check = (x:
- if (builtins.typeOf x) != "set"
- then lib.warn "clicks nginx services must be sets but ${x} is not a set" false
- else if !(builtins.hasAttr "type" x)
- then lib.warn "clicks nginx services must have a type attribute but ${x} does not" false
- else if !(builtins.hasAttr x.type validServiceTypes)
- then lib.warn "clicks nginx services must have a valid type, but ${x.type} is not one" false
- else (let
- optionTypes =
- (builtins.mapAttrs (n: o: builtins.elemAt o 0) validServiceTypes.${x.type})
- // { type = "string"; };
- in (lib.pipe x [
- (builtins.mapAttrs (n: o: (builtins.hasAttr n optionTypes) && optionTypes.${n} == (builtins.typeOf o)))
- lib.attrValues
- (builtins.all (x: x))
- ]) && (lib.pipe optionTypes [
- (builtins.mapAttrs (n: _: builtins.hasAttr n x))
- lib.attrValues
- (builtins.all (x: x))
- ] )));
+ if (builtins.typeOf x) != "set" then
+ lib.warn
+ "clicks nginx services must be sets but ${x} is not a set"
+ false
+ else if !(builtins.hasAttr "type" x) then
+ lib.warn
+ "clicks nginx services must have a type attribute but ${x} does not"
+ false
+ else if !(builtins.hasAttr x.type validServiceTypes) then
+ lib.warn
+ "clicks nginx services must have a valid type, but ${x.type} is not one"
+ false
+ else
+ (let
+ optionTypes =
+ (builtins.mapAttrs (n: o: builtins.elemAt o 0)
+ validServiceTypes.${x.type}) // {
+ type = "string";
+ };
+ in (lib.pipe x [
+ (builtins.mapAttrs (n: o:
+ (builtins.hasAttr n optionTypes) && optionTypes.${n}
+ == (builtins.typeOf o)))
+ lib.attrValues
+ (builtins.all (x: x))
+ ]) && (lib.pipe optionTypes [
+ (builtins.mapAttrs (n: _: builtins.hasAttr n x))
+ lib.attrValues
+ (builtins.all (x: x))
+ ])));
};
in serviceType;
};
@@ -116,13 +118,14 @@
default = [ ];
};
streams = lib.mkOption {
- type = with lib.types; listOf (submodule {
- options = {
- internal = lib.mkOption { type = str; };
- external = lib.mkOption { type = port; };
- protocol = lib.mkOption { type = strMatching "^(tcp|udp)$"; };
- };
- });
+ type = with lib.types;
+ listOf (submodule {
+ options = {
+ internal = lib.mkOption { type = str; };
+ external = lib.mkOption { type = port; };
+ protocol = lib.mkOption { type = strMatching "^(tcp|udp)$"; };
+ };
+ });
example = lib.literalExpression ''
with helpers.nginx; [
(Stream 1001 "generic:1002" "tcp")
@@ -151,7 +154,9 @@
streamConfig = builtins.concatStringsSep "\n" (map (stream: ''
server {
- listen ${builtins.toString stream.external}${lib.optionalString (stream.protocol == "udp") " udp"};
+ listen ${builtins.toString stream.external}${
+ lib.optionalString (stream.protocol == "udp") " udp"
+ };
proxy_pass ${builtins.toString stream.internal};
}
'') config.clicks.nginx.streams);
@@ -180,8 +185,10 @@
format = "binary";
};
};
-} (
- if base != null
- then {
- config.security.acme.certs = builtins.mapAttrs (_: v: { webroot = null; dnsProvider = "cloudflare"; }) base.config.security.acme.certs;
- } else {})
+} (if base != null then {
+ config.security.acme.certs = builtins.mapAttrs (_: v: {
+ webroot = null;
+ dnsProvider = "cloudflare";
+ }) base.config.security.acme.certs;
+} else
+ { })