-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Niklas Korz <[email protected]>
- Loading branch information
1 parent
2ac3b27
commit c91093d
Showing
5 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
cfg = config.services.fider; | ||
fiderCmd = lib.getExe cfg.package; | ||
in | ||
{ | ||
options = { | ||
|
||
services.fider = { | ||
enable = lib.mkEnableOption "the Fider server"; | ||
package = lib.mkPackageOption pkgs "fider" { }; | ||
|
||
dataDir = lib.mkOption { | ||
type = lib.types.str; | ||
default = "/var/lib/fider"; | ||
description = "Default data folder for Fider."; | ||
example = "/mnt/fider"; | ||
}; | ||
|
||
database = { | ||
url = lib.mkOption { | ||
type = lib.types.str; | ||
default = "local"; | ||
description = '' | ||
URI to use for the main PostgreSQL database. If this needs to include | ||
credentials that shouldn't be world-readable in the Nix store, set an | ||
environment file on the systemd service and override the | ||
`DATABASE_URL` entry. Pass the string | ||
`local` to setup a database on the local server. | ||
''; | ||
}; | ||
}; | ||
|
||
environment = lib.mkOption { | ||
type = lib.types.attrsOf lib.types.str; | ||
default = { }; | ||
description = '' | ||
Environment variables to set for the service. Secrets should be | ||
specified using {option}`environmentFiles`. | ||
''; | ||
}; | ||
|
||
environmentFiles = lib.mkOption { | ||
type = lib.types.listOf lib.types.path; | ||
default = [ ]; | ||
description = '' | ||
Files to load environment variables from. Loaded variables override | ||
values set in {option}`environment`. | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
services.postgresql = lib.mkIf (cfg.database.url == "local") { | ||
enable = true; | ||
ensureUsers = [ | ||
{ | ||
name = "fider"; | ||
ensureDBOwnership = true; | ||
} | ||
]; | ||
ensureDatabases = [ "fider" ]; | ||
}; | ||
|
||
systemd.services.fider = { | ||
description = "Fider server"; | ||
wantedBy = [ "multi-user.target" ]; | ||
after = [ | ||
"network.target" | ||
] ++ lib.optionals (cfg.database.url == "local") [ "postgresql.service" ]; | ||
requires = lib.optionals (cfg.database.url == "local") [ "postgresql.service" ]; | ||
environment = | ||
let | ||
localPostgresqlUrl = "postgres:///fider?host=/run/postgresql"; | ||
in | ||
{ | ||
DATABASE_URL = if (cfg.database.url == "local") then localPostgresqlUrl else cfg.database.url; | ||
BLOB_STORAGE_FS_PATH = "${cfg.dataDir}"; | ||
} | ||
// cfg.environment; | ||
serviceConfig = { | ||
ExecStartPre = "${fiderCmd} migrate" ; | ||
ExecStart = fiderCmd; | ||
StateDirectory = "fider"; | ||
DynamicUser = true; | ||
PrivateTmp = "yes"; | ||
Restart = "on-failure"; | ||
RuntimeDirectory = "fider"; | ||
RuntimeDirectoryPreserve = true; | ||
CacheDirectory = "fider"; | ||
WorkingDirectory = "${cfg.package}"; | ||
EnvironmentFile = cfg.environmentFiles; | ||
}; | ||
}; | ||
}; | ||
|
||
meta = { | ||
maintainers = with lib.maintainers; [ | ||
drupol | ||
niklaskorz | ||
]; | ||
# doc = ./fider.md; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ lib, ... }: | ||
|
||
{ | ||
name = "fider-server"; | ||
|
||
nodes = { | ||
machine = | ||
{ pkgs, ... }: | ||
{ | ||
services.fider = { | ||
enable = true; | ||
environment = { | ||
JWT_SECRET = "not_so_secret"; | ||
BASE_URL = "/"; | ||
EMAIL_NOREPLY = "[email protected]"; | ||
EMAIL_SMTP_HOST = "mailhog"; | ||
EMAIL_SMTP_PORT = "1025"; | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
testScript = '' | ||
machine.start() | ||
machine.wait_for_unit("fider.service") | ||
machine.wait_for_open_port(3000) | ||
''; | ||
|
||
meta.maintainers = with lib.maintainers; [ | ||
drupol | ||
niklaskorz | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters