chore: nf-fmt-nix

This commit is contained in:
arcnmx 2024-06-24 19:13:07 -07:00
parent 5f163df9ec
commit 7e82a12236
5 changed files with 126 additions and 104 deletions

View file

@ -1,5 +1,10 @@
let let
tunnelModule = {pkgs, config, lib, ...}: let tunnelModule = {
pkgs,
config,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
settingsFormat = pkgs.formats.json {}; settingsFormat = pkgs.formats.json {};
in { in {
@ -21,7 +26,8 @@ let
}; };
}; };
}; };
in { in
{
pkgs, pkgs,
config, config,
utils, utils,
@ -60,7 +66,8 @@ in {
}; };
config.services.cloudflared = { config.services.cloudflared = {
extraArgs = mkIf (cfg.metricsPort != null) [ extraArgs = mkIf (cfg.metricsPort != null) [
"--metrics" "${cfg.metricsBind}:${toString cfg.metricsPort}" "--metrics"
"${cfg.metricsBind}:${toString cfg.metricsPort}"
]; ];
}; };
config.systemd.services = let config.systemd.services = let
@ -87,10 +94,13 @@ in {
if tunnel.extraTunnel.enable if tunnel.extraTunnel.enable
then "/run/${RuntimeDirectory}/config.yml" then "/run/${RuntimeDirectory}/config.yml"
else pkgs.writeText "cloudflared.yml" (builtins.toJSON settings); else pkgs.writeText "cloudflared.yml" (builtins.toJSON settings);
args = [ args =
[
"--config=${configPath}" "--config=${configPath}"
"--no-autoupdate" "--no-autoupdate"
] ++ cfg.extraArgs ++ tunnel.extraArgs; ]
++ cfg.extraArgs
++ tunnel.extraArgs;
in in
nameValuePair "cloudflared-tunnel-${uuid}" (mkMerge [ nameValuePair "cloudflared-tunnel-${uuid}" (mkMerge [
{ {

View file

@ -1,7 +1,8 @@
let let
xInit = true; xInit = true;
xCloudflared = {virtualHost}: let xCloudflared = {virtualHost}: let
host = if virtualHost.proxied.cloudflared.host == virtualHost.serverName host =
if virtualHost.proxied.cloudflared.host == virtualHost.serverName
then "$server_name" then "$server_name"
else "'${virtualHost.proxied.cloudflared.host}'"; else "'${virtualHost.proxied.cloudflared.host}'";
in '' in ''
@ -42,11 +43,13 @@ let
host = "$proxied_host_cf"; host = "$proxied_host_cf";
}; };
}; };
in { in
{
forwarded_for = "$proxy_add_x_forwarded_for"; forwarded_for = "$proxy_add_x_forwarded_for";
scheme = "$proxied_scheme"; scheme = "$proxied_scheme";
https = "$proxied_https"; https = "$proxied_https";
} // defaults.${cfg.enable}; }
// defaults.${cfg.enable};
locationModule = { locationModule = {
config, config,
virtualHost, virtualHost,

View file

@ -15,7 +15,8 @@ let
defaultValues = filterAttrs (name: value: value != null && value != virtualHost.xvars.defaults.${name} or null) cfg.defaults; defaultValues = filterAttrs (name: value: value != null && value != virtualHost.xvars.defaults.${name} or null) cfg.defaults;
defaults = concatStringsSep "\n" (mapAttrsToList ( defaults = concatStringsSep "\n" (mapAttrsToList (
name: value: "set $x_${name} ${virtualHost.xvars.lib.escapeString value};" name: value: "set $x_${name} ${virtualHost.xvars.lib.escapeString value};"
) defaultValues); )
defaultValues);
in { in {
options.xvars = with lib.types; { options.xvars = with lib.types; {
enable = mkEnableOption "$x_variables"; enable = mkEnableOption "$x_variables";
@ -102,7 +103,8 @@ let
defaultValues = filterAttrs (_: value: value != null) cfg.defaults; defaultValues = filterAttrs (_: value: value != null) cfg.defaults;
defaults = concatStringsSep "\n" (mapAttrsToList ( defaults = concatStringsSep "\n" (mapAttrsToList (
name: value: "set $x_${name} ${escapeString value};" name: value: "set $x_${name} ${escapeString value};"
) defaultValues); )
defaultValues);
parseReferer = '' parseReferer = ''
set $hack_referer $http_referer; set $hack_referer $http_referer;
if ($hack_referer ~ "^(https?)://([^/]+)(/.*)$") { if ($hack_referer ~ "^(https?)://([^/]+)(/.*)$") {

View file

@ -6,7 +6,11 @@
inherit (gensokyo-zone.lib) mkAlmostOptionDefault; inherit (gensokyo-zone.lib) mkAlmostOptionDefault;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
in { in {
config.exports.services.cloudflared = {config, systemConfig, ...}: let config.exports.services.cloudflared = {
config,
systemConfig,
...
}: let
assertMetrics = nixosConfig: let assertMetrics = nixosConfig: let
cfg = nixosConfig.services.cloudflared; cfg = nixosConfig.services.cloudflared;
metricsPort = metricsPort =

View file

@ -39,7 +39,10 @@
src = inputs.nixpkgs; src = inputs.nixpkgs;
inherit patches; inherit patches;
}; };
in if patches != [] then patchedNixpkgs else pkgs; in
if patches != []
then patchedNixpkgs
else pkgs;
deploy-rs = let deploy-rs = let
deployLib = deployLib =
inputs.deploy-rs.lib.${system} inputs.deploy-rs.lib.${system}