-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
170 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,169 @@ | ||
{ | ||
lib, | ||
pkgs, | ||
config, | ||
... | ||
}: | ||
let | ||
cfg = config.services.pds; | ||
|
||
inherit (lib) | ||
boolToString | ||
getExe | ||
mkEnableOption | ||
mkIf | ||
mkOption | ||
mkPackageOption | ||
optional | ||
types | ||
; | ||
in | ||
# All defaults are from https://github.com/bluesky-social/pds/blob/8b9fc24cec5f30066b0d0b86d2b0ba3d66c2b532/installer.sh | ||
{ | ||
options.services.pds = { | ||
enable = mkEnableOption "pds"; | ||
|
||
package = mkPackageOption pkgs "pds" { }; | ||
|
||
environment = mkOption { | ||
type = types.attrsOf types.str; | ||
default = { }; | ||
description = '' | ||
Environment variables to set for the service. Secrets should be | ||
specified using {option}`environmentFile`. | ||
Refer to <https://github.com/bluesky-social/atproto/blob/92cd7a84ad207278c241afce8c8491e73b0a24e0/packages/pds/src/config/env.ts> for available environment variables. | ||
''; | ||
}; | ||
|
||
environmentFiles = mkOption { | ||
type = types.listOf types.path; | ||
default = [ ]; | ||
description = '' | ||
File to load environment variables from. Loaded variables override | ||
values set in {option}`environment`. | ||
Use it to set values of `PDS_JWT_SECRET`, `PDS_ADMIN_PASSWORD`, | ||
and `PDS_PLC_ROTATION_KEY_K256_PRIVATE_KEY_HEX` secrets. | ||
You can generate initial values with | ||
``` | ||
nix-build -A pds.passthru.generateSecrets | ||
./result/bin/generate-pds-secrets > secrets.env | ||
``` | ||
''; | ||
}; | ||
|
||
port = mkOption { | ||
type = types.port; | ||
default = 3000; | ||
description = "Port to listen on"; | ||
}; | ||
|
||
hostname = mkOption { | ||
type = types.str; | ||
example = "pds.example.com"; | ||
description = "Instance hostname (base domain name)"; | ||
}; | ||
|
||
blobstorageOnDisk = mkOption { | ||
type = types.bool; | ||
default = true; | ||
description = "Store blobs on disk rather than e.g. S3"; | ||
}; | ||
|
||
blobUploadLimit = mkOption { | ||
type = types.int; | ||
default = 52428800; | ||
description = "Size limit of uploaded blobs"; | ||
}; | ||
|
||
plcUrl = mkOption { | ||
type = types.str; | ||
default = "https://plc.directory"; | ||
description = "URL of DID PLC directory"; | ||
}; | ||
|
||
bskyAppViewUrl = mkOption { | ||
type = types.str; | ||
default = "https://api.bsky.app"; | ||
description = "URL of bsky frontend"; | ||
}; | ||
|
||
bskyAppViewDid = mkOption { | ||
type = types.str; | ||
default = "did:web:api.bsky.app"; | ||
description = "DID of bsky frontend"; | ||
}; | ||
|
||
reportServiceUrl = mkOption { | ||
type = types.str; | ||
default = "https://mod.bsky.app"; | ||
description = "URL of mod service"; | ||
}; | ||
|
||
reportServiceDid = mkOption { | ||
type = types.str; | ||
default = "did:plc:ar7c4by46qjdydhdevvrndac"; | ||
description = "DID of mod service"; | ||
}; | ||
|
||
crawlers = mkOption { | ||
type = types.str; | ||
default = "https://bsky.network"; | ||
description = "URL of crawlers"; | ||
}; | ||
|
||
log.enable = mkOption { | ||
type = types.bool; | ||
default = true; | ||
description = "Enable logging"; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
systemd.services.pds = { | ||
description = "pds"; | ||
wants = [ "network-online.target" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
|
||
serviceConfig = rec { | ||
ExecStart = getExe cfg.package; | ||
Environment = | ||
[ | ||
"NODE_ENV=production" | ||
"PDS_PORT=${toString cfg.port}" | ||
"PDS_HOSTNAME=${cfg.hostname}" | ||
"PDS_DATA_DIRECTORY=/var/lib/${StateDirectory}" | ||
"PDS_BLOB_UPLOAD_LIMIT=${toString cfg.blobUploadLimit}" | ||
"PDS_DID_PLC_URL=${cfg.plcUrl}" | ||
"PDS_BSKY_APP_VIEW_URL=${cfg.bskyAppViewUrl}" | ||
"PDS_BSKY_APP_VIEW_DID=${cfg.bskyAppViewDid}" | ||
"PDS_REPORT_SERVICE_URL=${cfg.reportServiceUrl}" | ||
"PDS_REPORT_SERVICE_DID=${cfg.reportServiceDid}" | ||
"PDS_CRAWLERS=${cfg.crawlers}" | ||
"LOG_ENABLED=${boolToString cfg.log.enable}" | ||
] | ||
++ (optional cfg.blobstorageOnDisk "PDS_BLOBSTORE_DISK_LOCATION=/var/lib/${StateDirectory}/blocks"); | ||
|
||
EnvironmentFile = cfg.environmentFiles; | ||
User = "pds"; | ||
Group = "pds"; | ||
StateDirectory = "pds"; | ||
StateDirectoryMode = "0755"; | ||
Restart = "always"; | ||
}; | ||
}; | ||
|
||
users = { | ||
users.pds = { | ||
group = "pds"; | ||
createHome = false; | ||
isSystemUser = true; | ||
}; | ||
groups.pds = { }; | ||
}; | ||
|
||
}; | ||
|
||
meta.maintainers = with lib.maintainers; [ t4ccer ]; | ||
} |