2 description = "A free software to take back control of your videos";
4 url = "path:../myuids";
6 inputs.flake-utils.url = "github:numtide/flake-utils";
7 inputs.nixpkgs.url = "github:NixOS/nixpkgs";
9 url = "github:Chocobozzz/PeerTube/v3.0.1";
13 outputs = { self, myuids, nixpkgs, peertube, flake-utils }: flake-utils.lib.eachSystem ["x86_64-linux"] (system:
15 pkgs = import nixpkgs { inherit system; overlays = [
16 (self: super: { nodejs = self.nodejs-12_x; })
18 inherit (pkgs) callPackage stdenv jq youtube-dl fetchurl nodePackages yarn2nix-moretea;
20 patchedSource = stdenv.mkDerivation {
22 version = peertube.rev;
24 phases = [ "unpackPhase" "patchPhase" "installPhase" ];
25 patches = [ ./fix_yarn_lock.patch ];
33 buildInputs = [ nodePackages.node-pre-gyp ];
35 bcrypt_version = "5.0.0";
36 bcrypt_lib = fetchurl {
37 url = "https://github.com/kelektiv/node.bcrypt.js/releases/download/v${bcrypt_version}/bcrypt_lib-v${bcrypt_version}-napi-v3-linux-x64-glibc.tar.gz";
38 sha256 = "0j3p2px1xb17sw3gpm8l4apljajxxfflal1yy552mhpzhi21wccn";
42 if [ "${bcrypt_version}" != "$(cat package.json | ${jq}/bin/jq -r .version)" ]; then
43 echo "Mismatching version please update bcrypt in derivation"
46 mkdir -p lib/binding && tar -C lib/binding -xf ${bcrypt_lib}
47 patchShebangs ../node-pre-gyp
52 buildInputs = [ nodePackages.node-gyp-build ];
57 ln -s ${youtube-dl}/bin/youtube-dl bin/youtube-dl
58 cat > bin/details <<EOF
59 {"version":"${youtube-dl.version}","path":null,"exec":"youtube-dl"}
64 mkYarnModules' = args: (yarn2nix-moretea.mkYarnModules args).overrideAttrs(old: {
65 # This hack permits to workaround the fact that the yarn.lock
66 # file doesn't respect the semver requirements
67 buildPhase = builtins.replaceStrings [" ./package.json"] [" /dev/null; cp deps/*/package.json ."] old.buildPhase;
70 server = callPackage ./server.nix {
71 inherit yarnModulesConfig mkYarnModules';
72 sources = patchedSource;
74 client = callPackage ./client.nix {
75 inherit server yarnModulesConfig mkYarnModules';
76 sources = patchedSource;
80 packages.peertube = callPackage ./. { inherit server client; src = patchedSource; };
81 defaultPackage = packages.peertube;
82 legacyPackages.peertube = packages.peertube;
84 build = defaultPackage;
85 } // pkgs.lib.optionalAttrs (builtins.elem system pkgs.lib.systems.doubles.linux) {
87 let testing = import (nixpkgs + "/nixos/lib/testing-python.nix") { inherit system; };
90 client = { pkgs, ... }: {};
92 server = { pkgs, ... }: {
93 imports = [ self.nixosModule ];
94 config.networking.firewall.allowedTCPPorts = [ 8888 ];
95 config.services.redis.enable = true;
96 config.services.postgresql = {
98 initialScript = pkgs.writeText "peertube.sql" ''
99 CREATE ROLE "peertube" WITH LOGIN PASSWORD 'peertube';
100 CREATE DATABASE "peertube_prod" WITH OWNER "peertube"
105 CREATE EXTENSION unaccent;
106 CREATE EXTENSION pg_trgm;
109 config.services.peertube.enable = true;
110 config.services.peertube.configFile = pkgs.writeText "peertube.conf" ''
116 hostname: 'localhost.tld'
119 hostname: 'localhost'
131 tmp: '/var/lib/peertube/storage/tmp/'
132 avatars: '/var/lib/peertube/storage/avatars/'
133 videos: '/var/lib/peertube/storage/videos/'
134 streaming_playlists: '/var/lib/peertube/storage/streaming-playlists/'
135 redundancy: '/var/lib/peertube/storage/videos/'
136 logs: '/var/lib/peertube/storage/logs/'
137 previews: '/var/lib/peertube/storage/previews/'
138 thumbnails: '/var/lib/peertube/storage/thumbnails/'
139 torrents: '/var/lib/peertube/storage/torrents/'
140 captions: '/var/lib/peertube/storage/captions/'
141 cache: '/var/lib/peertube/storage/cache/'
142 plugins: '/var/lib/peertube/storage/plugins/'
143 client_overrides: '/var/lib/peertube/storage/client-overrides/'
149 server.wait_for_unit("peertube.service")
150 server.wait_for_open_port(8888)
151 client.succeed("curl http://server:8888")
152 client.succeed("curl http://server:8888/client/fr-FR/index.html")
159 peertube = final: prev: {
160 peertube = self.defaultPackage."${final.system}";
163 overlay = overlays.peertube;
164 nixosModule = { lib, pkgs, config, ... }:
167 cfg = config.immaeServices.peertube;
170 options.immaeServices.peertube = {
171 enable = lib.mkEnableOption "Enable Peertube’s service";
172 user = lib.mkOption {
173 type = lib.types.str;
175 description = "User account under which Peertube runs";
177 group = lib.mkOption {
178 type = lib.types.str;
180 description = "Group under which Peertube runs";
182 dataDir = lib.mkOption {
183 type = lib.types.path;
184 default = "/var/lib/${name}";
186 The directory where Peertube stores its data.
189 configFile = lib.mkOption {
190 type = lib.types.path;
192 The configuration file path for Peertube.
195 package = lib.mkOption {
196 type = lib.types.package;
197 default = pkgs.peertube;
199 Peertube package to use.
203 systemdStateDirectory = lib.mkOption {
204 type = lib.types.str;
205 # Use ReadWritePaths= instead if varDir is outside of /var/lib
206 default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
207 lib.strings.removePrefix "/var/lib/" cfg.dataDir;
209 Adjusted Peertube data directory for systemd
215 config = lib.mkIf cfg.enable {
216 nixpkgs.overlays = [ self.overlay ];
217 users.users = lib.optionalAttrs (cfg.user == name) {
219 uid = myuids.lib.uids.peertube;
221 description = "Peertube user";
223 useDefaultShell = true;
226 users.groups = lib.optionalAttrs (cfg.group == name) {
228 gid = myuids.lib.gids.peertube;
232 systemd.services.peertube = {
233 description = "Peertube";
234 wantedBy = [ "multi-user.target" ];
235 after = [ "network.target" "postgresql.service" ];
236 wants = [ "postgresql.service" ];
238 environment.NODE_CONFIG_DIR = "${cfg.dataDir}/config";
239 environment.NODE_ENV = "production";
240 environment.NPM_CONFIG_LOGS_DIR = "${cfg.dataDir}/npm_logs";
241 environment.NPM_CONFIG_CACHE = "${cfg.dataDir}/npm_cache";
242 environment.HOME = cfg.package;
244 path = [ pkgs.nodejs pkgs.yarn pkgs.bashInteractive pkgs.ffmpeg pkgs.openssl ];
247 install -m 0750 -d ${cfg.dataDir}/config
248 ln -sf ${cfg.configFile} ${cfg.dataDir}/config/production.yaml
249 ln -sf ${cfg.package}/config/default.yaml ${cfg.dataDir}/config/default.yaml
256 WorkingDirectory = cfg.package;
257 StateDirectory = cfg.systemdStateDirectory;
258 StateDirectoryMode = 0750;
261 ProtectControlGroups = true;
267 unitConfig.RequiresMountsFor = cfg.dataDir;