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.
43 systemdStateDirectory = lib.mkOption {
45 # Use ReadWritePaths= instead if varDir is outside of /var/lib
46 default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
47 lib.strings.removePrefix "/var/lib/" cfg.dataDir;
49 Adjusted Peertube data directory for systemd
55 config = lib.mkIf cfg.enable {
56 users.users = lib.optionalAttrs (cfg.user == name) (lib.singleton {
60 description = "Peertube user";
62 useDefaultShell = true;
64 users.groups = lib.optionalAttrs (cfg.group == name) (lib.singleton {
69 systemd.services.peertube = {
70 description = "Peertube";
71 wantedBy = [ "multi-user.target" ];
72 after = [ "network.target" "postgresql.service" ];
73 wants = [ "postgresql.service" ];
75 environment.NODE_CONFIG_DIR = "${cfg.dataDir}/config";
76 environment.NODE_ENV = "production";
77 environment.HOME = cfg.package;
79 path = [ pkgs.nodejs pkgs.bashInteractive pkgs.ffmpeg pkgs.openssl ];
82 install -m 0750 -d ${cfg.dataDir}/config
83 ln -sf ${cfg.configFile} ${cfg.dataDir}/config/production.yaml
90 WorkingDirectory = cfg.package;
91 StateDirectory = cfg.systemdStateDirectory;
92 StateDirectoryMode = 0750;
95 ProtectControlGroups = true;
101 unitConfig.RequiresMountsFor = cfg.dataDir;