mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 04:19:19 -08:00
feat(nginx): etag from root drv path
This commit is contained in:
parent
47d830eaed
commit
0db849b707
1 changed files with 63 additions and 0 deletions
63
modules/nixos/nginx/cache.nix
Normal file
63
modules/nixos/nginx/cache.nix
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
let
|
||||
locationModule = {
|
||||
config,
|
||||
virtualHost,
|
||||
gensokyo-zone,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption;
|
||||
inherit (lib.modules) mkIf mkMerge mkOptionDefault;
|
||||
inherit (lib.strings) hasPrefix removePrefix;
|
||||
cfg = config.cache;
|
||||
in {
|
||||
options.cache = with lib.types; {
|
||||
rootETag = mkOption {
|
||||
type = bool;
|
||||
};
|
||||
};
|
||||
config = let
|
||||
rootStoreDir = removePrefix "${builtins.storeDir}/" config.root;
|
||||
in {
|
||||
cache = {
|
||||
rootETag = mkOptionDefault (config.root != null && hasPrefix builtins.storeDir "${config.root}");
|
||||
};
|
||||
extraConfig = let
|
||||
# TODO: should use ${rootStoreDir} or strip store prefix from $request_filename
|
||||
rootETag = ''
|
||||
etag off;
|
||||
add_header etag '"$request_filename"';
|
||||
'';
|
||||
in
|
||||
mkMerge [
|
||||
(mkIf (cfg.rootETag && config.root != null) rootETag)
|
||||
];
|
||||
};
|
||||
};
|
||||
hostModule = {
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption;
|
||||
in {
|
||||
# TODO: config.root exists too!
|
||||
options = with lib.types; {
|
||||
locations = mkOption {
|
||||
type = attrsOf (submoduleWith {
|
||||
modules = [locationModule];
|
||||
shorthandOnlyDefinesConfig = true;
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{lib, ...}: let
|
||||
inherit (lib.options) mkOption;
|
||||
in {
|
||||
options.services.nginx = with lib.types; {
|
||||
virtualHosts = mkOption {
|
||||
type = attrsOf (submodule [hostModule]);
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue