mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 04:43:09 +03:00
nixos: Multiple service instances, apply to nginx. See #6784
This commit is contained in:
parent
506cbf05a9
commit
7ef59c4fe2
@ -227,4 +227,19 @@ rec {
|
||||
|
||||
};
|
||||
|
||||
mkMultiInstance = path: args: f:
|
||||
let
|
||||
def = f (args // { name = "default"; config = getAttrFromPath path args.config; });
|
||||
in {
|
||||
options = setAttrByPath path (def.options // {
|
||||
instances = mkOption {
|
||||
type = types.attrsOf (types.submodule f);
|
||||
default = {};
|
||||
description = "Additional instances of this service";
|
||||
};
|
||||
});
|
||||
|
||||
config = def.config;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
{ config, lib, pkgs, ... }@args:
|
||||
|
||||
with lib;
|
||||
|
||||
let topconfig = config;
|
||||
in mkMultiInstance [ "services" "nginx" ] args ({ config, name, ... }:
|
||||
|
||||
let
|
||||
cfg = config.services.nginx;
|
||||
cfg = config;
|
||||
nginx = cfg.package;
|
||||
configFile = pkgs.writeText "nginx.conf" ''
|
||||
user ${cfg.user} ${cfg.group};
|
||||
@ -20,7 +23,6 @@ in
|
||||
|
||||
{
|
||||
options = {
|
||||
services.nginx = {
|
||||
enable = mkOption {
|
||||
default = false;
|
||||
type = types.bool;
|
||||
@ -82,15 +84,13 @@ in
|
||||
description = "Group account under which nginx runs.";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
# TODO: test user supplied config file pases syntax test
|
||||
|
||||
systemd.services.nginx = {
|
||||
description = "Nginx Web Server";
|
||||
systemd.services."nginx-${name}" = {
|
||||
description = "Nginx Web Server - ${name}";
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
path = [ nginx ];
|
||||
@ -111,12 +111,12 @@ in
|
||||
users.extraUsers = optionalAttrs (cfg.user == "nginx") (singleton
|
||||
{ name = "nginx";
|
||||
group = cfg.group;
|
||||
uid = config.ids.uids.nginx;
|
||||
uid = topconfig.ids.uids.nginx;
|
||||
});
|
||||
|
||||
users.extraGroups = optionalAttrs (cfg.group == "nginx") (singleton
|
||||
{ name = "nginx";
|
||||
gid = config.ids.gids.nginx;
|
||||
gid = topconfig.ids.gids.nginx;
|
||||
});
|
||||
};
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user