Refactored NixOS module
* Admin account configuration * Proxy server configuration
This commit is contained in:
parent
6b016669ec
commit
25b54cd352
@ -147,29 +147,38 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
adminEmail = lib.mkOption {
|
adminAccount = {
|
||||||
type = lib.types.str;
|
createAdmin = lib.mkOption {
|
||||||
default = "example@email.com";
|
type = lib.types.bool;
|
||||||
description = "Email address of the first (admin) account for this Invoice Ninja installation";
|
default = true;
|
||||||
};
|
description = ''
|
||||||
|
When set to `true`, an admin account will be created for Invoice Ninja. If set to `false`
|
||||||
adminPassword = lib.mkOption {
|
Invoice Ninja will run a setup wizard on first use.
|
||||||
type = lib.types.str;
|
'';
|
||||||
default = "example";
|
};
|
||||||
description = "Password of the first (admin) account for this Invoice Ninja installation";
|
email = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "example@email.com";
|
||||||
|
description = "Email address of the first (admin) account for this Invoice Ninja installation";
|
||||||
|
};
|
||||||
|
password = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "example";
|
||||||
|
description = "Password of the first (admin) account for this Invoice Ninja installation";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
database = {
|
database = {
|
||||||
createLocally = lib.mkOption {
|
createLocally = lib.mkOption {
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
description = "A local database using UNIX socket authentication";
|
description = "Installs a local MariaDB server to use with Invoice Ninja.";
|
||||||
};
|
};
|
||||||
|
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "invoiceninja";
|
default = "invoiceninja";
|
||||||
description = "Database name for Invoice Ninja.";
|
description = "Name of the database to use for Invoice Ninja.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -202,62 +211,42 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
webserver = {
|
proxy = {
|
||||||
caddy = {
|
server = lib.mkOption {
|
||||||
enable = lib.mkOption {
|
type = lib.types.enum [ "caddy" "nginx" "none" ];
|
||||||
type = lib.types.bool;
|
default = "nginx";
|
||||||
default = false;
|
example = "caddy";
|
||||||
description = "Whether to enable the Caddy server to serve Invoice Ninja.";
|
description = ''
|
||||||
};
|
Choose the proxy server to serve Invoice Ninja. Setting this to
|
||||||
|
`none` results in no proxy server being installed.
|
||||||
config = lib.mkOption {
|
'';
|
||||||
type = lib.types.submodule (
|
|
||||||
(import (modulesPath + "/services/web-servers/caddy/vhost-options.nix") { cfg = config.services.caddy; }) {
|
|
||||||
inherit lib; config = cfg; name = (if (cfg.hostName == "localhost") then ":80" else cfg.hostName);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
default = { };
|
|
||||||
description = ''
|
|
||||||
Extra configuration for the Caddy virtual host of Invoice Ninja.
|
|
||||||
Set to `{ }` to use the default configuration
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
caddyConfig = lib.mkOption {
|
||||||
nginx = {
|
type = lib.types.submodule (
|
||||||
enable = lib.mkOption {
|
(import (modulesPath + "/services/web-servers/caddy/vhost-options.nix") { cfg = config.services.caddy; }) {
|
||||||
type = lib.types.bool;
|
inherit lib; config = cfg; name = (if (cfg.hostName == "localhost") then ":80" else cfg.hostName);
|
||||||
default = true;
|
}
|
||||||
description = "Whether to enable Nginx server to serve Invoice Ninja.";
|
);
|
||||||
};
|
default = { };
|
||||||
|
description = ''
|
||||||
config = lib.mkOption {
|
Extra configuration for the Caddy virtual host of Invoice Ninja.
|
||||||
type = lib.types.submodule (
|
Set to `{ }` to use the default configuration
|
||||||
(import (modulesPath + "/services/web-servers/nginx/vhost-options.nix") { inherit config lib; })
|
'';
|
||||||
);
|
};
|
||||||
default = { };
|
nginxConfig = lib.mkOption {
|
||||||
description = ''
|
type = lib.types.submodule (
|
||||||
Extra configuration for the Nginx virtual host of Invoice Ninja.
|
(import (modulesPath + "/services/web-servers/nginx/vhost-options.nix") { inherit config lib; })
|
||||||
Set to `{ }` to use the default configuration
|
);
|
||||||
'';
|
default = { };
|
||||||
};
|
description = ''
|
||||||
|
Extra configuration for the Nginx virtual host of Invoice Ninja.
|
||||||
|
Set to `{ }` to use the default configuration
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
# FIXME Caddy and Nginx should be mutually exclusive
|
|
||||||
assertions = [
|
|
||||||
{
|
|
||||||
assertion = ((cfg.webserver.nginx.enable -> !cfg.webserver.caddy.enable)
|
|
||||||
&& (cfg.webserver.caddy.enable -> !cfg.webserver.nginx.enable));
|
|
||||||
message = ''
|
|
||||||
Both Nginx and Caddy webservers cannot be enable together. Check your configuration
|
|
||||||
and ensure you only enabled one.
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
users.users.invoiceninja = lib.mkIf (cfg.user == "invoiceninja") {
|
users.users.invoiceninja = lib.mkIf (cfg.user == "invoiceninja") {
|
||||||
isSystemUser = true;
|
isSystemUser = true;
|
||||||
home = cfg.dataDir;
|
home = cfg.dataDir;
|
||||||
@ -286,7 +275,7 @@ in
|
|||||||
chromium = lib.lists.findSingle (x: x == pkgs.chromium) "none" "multiple" extraPrograms;
|
chromium = lib.lists.findSingle (x: x == pkgs.chromium) "none" "multiple" extraPrograms;
|
||||||
in
|
in
|
||||||
lib.mkMerge [
|
lib.mkMerge [
|
||||||
(rec {
|
({
|
||||||
APP_NAME = lib.mkDefault "\"Invoice Ninja\"";
|
APP_NAME = lib.mkDefault "\"Invoice Ninja\"";
|
||||||
APP_ENV = lib.mkDefault "production";
|
APP_ENV = lib.mkDefault "production";
|
||||||
APP_DEBUG = lib.mkDefault false;
|
APP_DEBUG = lib.mkDefault false;
|
||||||
@ -347,9 +336,9 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users."${config.services.nginx.user}" = lib.mkIf (cfg.webserver.nginx.enable == true) { extraGroups = [ cfg.group ]; };
|
users.users."${config.services.nginx.user}" = lib.mkIf (cfg.proxy.server == "nginx") { extraGroups = [ cfg.group ]; };
|
||||||
services.nginx = lib.mkIf (cfg.webserver.nginx.enable == true) {
|
services.nginx = lib.mkIf (cfg.proxy.server == "nginx") {
|
||||||
inherit (cfg.webserver.nginx) enable;
|
enable = true;
|
||||||
|
|
||||||
recommendedTlsSettings = true;
|
recommendedTlsSettings = true;
|
||||||
recommendedGzipSettings = true;
|
recommendedGzipSettings = true;
|
||||||
@ -359,7 +348,7 @@ in
|
|||||||
clientMaxBodySize = cfg.maxUploadSize;
|
clientMaxBodySize = cfg.maxUploadSize;
|
||||||
|
|
||||||
virtualHosts."${cfg.hostName}" = lib.mkMerge [
|
virtualHosts."${cfg.hostName}" = lib.mkMerge [
|
||||||
cfg.webserver.nginx.config
|
cfg.proxy.nginxConfig
|
||||||
{
|
{
|
||||||
root = lib.mkForce "${invoice-ninja}/public";
|
root = lib.mkForce "${invoice-ninja}/public";
|
||||||
locations = {
|
locations = {
|
||||||
@ -387,16 +376,16 @@ in
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users."${config.services.caddy.user}" = lib.mkIf (cfg.webserver.caddy.enable == true) { extraGroups = [ cfg.group ]; };
|
users.users."${config.services.caddy.user}" = lib.mkIf (cfg.proxy.server == "caddy") { extraGroups = [ cfg.group ]; };
|
||||||
services.caddy = lib.mkIf (cfg.webserver.caddy.enable == true) {
|
services.caddy = lib.mkIf (cfg.proxy.server == "caddy") {
|
||||||
inherit (cfg.webserver.caddy) enable;
|
enable = true;
|
||||||
|
|
||||||
globalConfig = lib.mkIf (cfg.hostName == "localhost") ''
|
globalConfig = lib.mkIf (cfg.hostName == "localhost") ''
|
||||||
auto_https disable_redirects
|
auto_https disable_redirects
|
||||||
'';
|
'';
|
||||||
|
|
||||||
virtualHosts."${cfg.hostName}" = lib.mkMerge [
|
virtualHosts."${cfg.hostName}" = lib.mkMerge [
|
||||||
cfg.webserver.caddy.config
|
cfg.proxy.caddyConfig
|
||||||
{
|
{
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
encode zstd gzip
|
encode zstd gzip
|
||||||
@ -487,8 +476,8 @@ in
|
|||||||
[[ ! -f ${cfg.dataDir}/.db-seeded ]] && invoice-ninja-manage db:seed --force && touch ${cfg.dataDir}/.db-seeded
|
[[ ! -f ${cfg.dataDir}/.db-seeded ]] && invoice-ninja-manage db:seed --force && touch ${cfg.dataDir}/.db-seeded
|
||||||
|
|
||||||
# Create Invoice Ninja admin account
|
# Create Invoice Ninja admin account
|
||||||
[[ ! -f ${cfg.dataDir}/.admin-created ]] \
|
[[ (! -f ${cfg.dataDir}/.admin-created) && (${if cfg.adminAccount.createAdmin then "true" else "false"} == "true") ]] \
|
||||||
&& invoice-ninja-manage ninja:create-account --email=${cfg.adminEmail} --password=${cfg.adminPassword} \
|
&& invoice-ninja-manage ninja:create-account --email=${cfg.adminAccount.email} --password=${cfg.adminAccount.password} \
|
||||||
&& touch ${cfg.dataDir}/.admin-created
|
&& touch ${cfg.dataDir}/.admin-created
|
||||||
|
|
||||||
invoice-ninja-manage route:cache
|
invoice-ninja-manage route:cache
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user