1 { config, lib, pkgs, ... }:
6 cfg = config.services.rtsp-simple-server;
7 package = pkgs.rtsp-simple-server;
8 format = pkgs.formats.yaml {};
12 services.rtsp-simple-server = {
13 enable = mkEnableOption (lib.mdDoc "RTSP Simple Server");
16 description = lib.mdDoc ''
17 Settings for rtsp-simple-server.
18 Read more at <https://github.com/aler9/rtsp-simple-server/blob/main/rtsp-simple-server.yml>
27 # we set this so when the user uses it, it just works (see LogsDirectory below). but it's not used by default.
28 logFile = "/var/log/rtsp-simple-server/rtsp-simple-server.log";
34 runOnInit = "ffmpeg -f v4l2 -i /dev/video0 -f rtsp rtsp://localhost:$RTSP_PORT/$RTSP_PATH";
35 runOnInitRestart = true;
42 type = with types; attrsOf anything;
43 description = lib.mdDoc "Extra environment variables for RTSP Simple Server";
46 RTSP_CONFKEY = "mykey";
52 config = mkIf (cfg.enable) {
53 # NOTE: rtsp-simple-server watches this file and automatically reloads if it changes
54 environment.etc."rtsp-simple-server.yaml".source = format.generate "rtsp-simple-server.yaml" cfg.settings;
56 systemd.services.rtsp-simple-server = {
57 environment = cfg.env;
59 after = [ "network.target" ];
60 wantedBy = [ "multi-user.target" ];
68 User = "rtsp-simple-server";
69 Group = "rtsp-simple-server";
71 LogsDirectory = "rtsp-simple-server";
73 # user likely may want to stream cameras, can't hurt to add video group
74 SupplementaryGroups = "video";
76 ExecStart = "${package}/bin/rtsp-simple-server /etc/rtsp-simple-server.yaml";