1 { lib, pkgs, config, ... }:
4 cfg = config.services.peertube;
6 uid = config.ids.uids.peertube;
7 gid = config.ids.gids.peertube;
10 options.services.peertube = {
11 enable = lib.mkEnableOption "Enable Peertube’s service";
15 description = "User account under which Peertube runs";
17 group = lib.mkOption {
20 description = "Group under which Peertube runs";
22 dataDir = lib.mkOption {
23 type = lib.types.path;
24 default = "/var/lib/${name}";
26 The directory where Peertube stores its data.
29 configFile = lib.mkOption {
30 type = lib.types.path;
32 The configuration file path for Peertube.
35 package = lib.mkOption {
36 type = lib.types.package;
37 default = pkgs.webapps.peertube;
39 Peertube package to use.
44 config = lib.mkIf cfg.enable {
45 users.users = lib.optionalAttrs (cfg.user == name) (lib.singleton {
49 description = "Peertube user";
51 useDefaultShell = true;
53 users.groups = lib.optionalAttrs (cfg.group == name) (lib.singleton {
58 systemd.services.peertube = {
59 description = "Peertube";
60 wantedBy = [ "multi-user.target" ];
61 after = [ "network.target" "postgresql.service" ];
62 wants = [ "postgresql.service" ];
64 environment.NODE_CONFIG_DIR = "${cfg.dataDir}/config";
65 environment.NODE_ENV = "production";
66 environment.HOME = cfg.package;
68 path = [ pkgs.nodejs pkgs.bashInteractive pkgs.ffmpeg pkgs.openssl ];
77 WorkingDirectory = cfg.package;
80 ProtectControlGroups = true;
86 unitConfig.RequiresMountsFor = cfg.dataDir;
89 system.activationScripts.peertube = {
92 install -m 0750 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}
93 install -m 0750 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}/config
94 ln -sf ${cfg.configFile} ${cfg.dataDir}/config/production.yaml