feat: add nixos modules
This commit is contained in:
parent
77dfa25c7f
commit
02a11fadab
1 changed files with 66 additions and 0 deletions
66
modules/nixos/default.nix
Normal file
66
modules/nixos/default.nix
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
{ config, lib, perSystem, ... }:
|
||||
|
||||
let
|
||||
cfg = config.services.calapi;
|
||||
types = lib.types;
|
||||
in
|
||||
{
|
||||
options.services.calapi = {
|
||||
enable = lib.mkEnableOption "calapi";
|
||||
|
||||
port = lib.mkOption {
|
||||
type = types.int;
|
||||
default = 8434;
|
||||
};
|
||||
|
||||
proxy = lib.mkOption {
|
||||
type = types.enum [
|
||||
"nginx"
|
||||
];
|
||||
default = null;
|
||||
example = "nginx";
|
||||
};
|
||||
|
||||
nginx.virtualHost = lib.mkOption {
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
serverName = "survey.example.org";
|
||||
forceSSL = true;
|
||||
enableACME = true;
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
users = {
|
||||
groups."calapi" = {};
|
||||
users."calapi" = {
|
||||
group = "calapi";
|
||||
isSystemUser = true;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.calapi = {
|
||||
enable = true;
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
ExecStart = "${perSystem.calapi.default}/bin/calapi --port ${toString cfg.port}";
|
||||
Type = "exec";
|
||||
User = "calapi";
|
||||
};
|
||||
};
|
||||
|
||||
services.nginx.virtualHosts = lib.mkIf (cfg.proxy == "nginx") {
|
||||
"${cfg.nginx.virtualHost.serverName}" = lib.mkMerge [
|
||||
cfg.nginx.virtualHost
|
||||
{
|
||||
locations."/" = {
|
||||
proxyPass = "http://127.0.0.1:${toString cfg.port}/";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue