mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-29 23:07:36 +03:00
29027fd1e1
Using pkgs.lib on the spine of module evaluation is problematic because the pkgs argument depends on the result of module evaluation. To prevent an infinite recursion, pkgs and some of the modules are evaluated twice, which is inefficient. Using ‘with lib’ prevents this problem.
64 lines
1.4 KiB
Nix
64 lines
1.4 KiB
Nix
{ config, lib, pkgs, ...}:
|
|
let
|
|
cfg = config.services.varnish;
|
|
|
|
in
|
|
with lib;
|
|
{
|
|
options = {
|
|
services.varnish = {
|
|
enable = mkOption {
|
|
default = false;
|
|
description = "
|
|
Enable the Varnish Server.
|
|
";
|
|
};
|
|
|
|
http_address = mkOption {
|
|
default = "*:6081";
|
|
description = "
|
|
HTTP listen address and port.
|
|
";
|
|
};
|
|
|
|
config = mkOption {
|
|
description = "
|
|
Verbatim default.vcl configuration.
|
|
";
|
|
};
|
|
|
|
stateDir = mkOption {
|
|
default = "/var/spool/varnish";
|
|
description = "
|
|
Directory holding all state for Varnish to run.
|
|
";
|
|
};
|
|
};
|
|
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.varnish = {
|
|
description = "Varnish";
|
|
wantedBy = [ "multi-user.target" ];
|
|
preStart = ''
|
|
mkdir -p ${cfg.stateDir}
|
|
chown -R varnish:varnish ${cfg.stateDir}
|
|
'';
|
|
path = [ pkgs.gcc ];
|
|
serviceConfig.ExecStart = "${pkgs.varnish}/sbin/varnishd -a ${cfg.http_address} -f ${pkgs.writeText "default.vcl" cfg.config} -n ${cfg.stateDir} -u varnish";
|
|
serviceConfig.Type = "forking";
|
|
};
|
|
|
|
environment.systemPackages = [ pkgs.varnish ];
|
|
|
|
users.extraUsers.varnish = {
|
|
group = "varnish";
|
|
uid = config.ids.uids.varnish;
|
|
};
|
|
|
|
users.extraGroups.varnish.gid = config.ids.uids.varnish;
|
|
};
|
|
}
|