1 { config, lib, pkgs, ... }:
5 cfg = config.services.livebook;
8 options.services.livebook = {
9 # Since livebook doesn't have a granular permission system (a user
10 # either has access to all the data or none at all), the decision
11 # was made to run this as a user service. If that changes in the
12 # future, this can be changed to a system service.
13 enableUserService = mkEnableOption "a user service for Livebook";
15 environmentFile = mkOption {
17 description = lib.mdDoc ''
18 Environment file as defined in {manpage}`systemd.exec(5)` passed to the service.
20 This must contain at least `LIVEBOOK_PASSWORD` or
21 `LIVEBOOK_TOKEN_ENABLED=false`. See `livebook server --help`
25 erlang_node_short_name = mkOption {
26 type = with types; nullOr str;
29 description = "A short name for the distributed node.";
32 erlang_node_name = mkOption {
33 type = with types; nullOr str;
35 example = "livebook@127.0.0.1";
36 description = "The name for the app distributed node.";
42 description = "The port to start the web application on.";
47 default = "127.0.0.1";
48 description = lib.mdDoc ''
49 The address to start the web application on. Must be a valid IPv4 or
55 type = with types; attrsOf str;
57 description = lib.mdDoc ''
58 Additional options to pass as command-line arguments to the server.
60 example = literalExpression ''
62 cookie = "a value shared by all nodes in this cluster";
68 config = mkIf cfg.enableUserService {
69 systemd.user.services.livebook = {
72 EnvironmentFile = cfg.environmentFile;
75 args = lib.cli.toGNUCommandLineShell { } ({
78 name = cfg.erlang_node_name;
79 sname = cfg.erlang_node_short_name;
82 "${pkgs.livebook}/bin/livebook server ${args}";
85 wantedBy = [ "default.target" ];
89 meta.doc = ./livebook.md;