2023-10-24 18:53:12 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.livebook;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.livebook = {
|
|
|
|
# Since livebook doesn't have a granular permission system (a user
|
|
|
|
# either has access to all the data or none at all), the decision
|
|
|
|
# was made to run this as a user service. If that changes in the
|
|
|
|
# future, this can be changed to a system service.
|
|
|
|
enableUserService = mkEnableOption "a user service for Livebook";
|
|
|
|
|
2023-12-24 19:45:12 +01:00
|
|
|
package = mkPackageOption pkgs "livebook" { };
|
|
|
|
|
2024-01-23 22:36:52 +01:00
|
|
|
environment = mkOption {
|
|
|
|
type = with types; attrsOf (nullOr (oneOf [ bool int str ]));
|
|
|
|
default = { };
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2024-01-23 22:36:52 +01:00
|
|
|
Environment variables to set.
|
2023-10-24 18:53:12 +02:00
|
|
|
|
2024-01-23 22:36:52 +01:00
|
|
|
Livebook is configured through the use of environment variables. The
|
|
|
|
available configuration options can be found in the [Livebook
|
|
|
|
documentation](https://hexdocs.pm/livebook/readme.html#environment-variables).
|
2023-10-24 18:53:12 +02:00
|
|
|
|
2024-01-23 22:36:52 +01:00
|
|
|
Note that all environment variables set through this configuration
|
|
|
|
parameter will be readable by anyone with access to the host
|
|
|
|
machine. Therefore, sensitive information like {env}`LIVEBOOK_PASSWORD`
|
|
|
|
or {env}`LIVEBOOK_COOKIE` should never be set using this configuration
|
|
|
|
option, but should instead use
|
|
|
|
[](#opt-services.livebook.environmentFile). See the documentation for
|
|
|
|
that option for more information.
|
2023-10-24 18:53:12 +02:00
|
|
|
|
2024-01-23 22:36:52 +01:00
|
|
|
Any environment variables specified in the
|
|
|
|
[](#opt-services.livebook.environmentFile) will supersede environment
|
|
|
|
variables specified in this option.
|
2023-10-24 18:53:12 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
2024-01-23 22:36:52 +01:00
|
|
|
LIVEBOOK_PORT = 8080;
|
2023-10-24 18:53:12 +02:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2023-12-24 19:45:12 +01:00
|
|
|
|
2024-01-23 22:36:52 +01:00
|
|
|
environmentFile = mkOption {
|
|
|
|
type = with types; nullOr types.path;
|
|
|
|
default = null;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2024-01-23 22:36:52 +01:00
|
|
|
Additional dnvironment file as defined in {manpage}`systemd.exec(5)`.
|
|
|
|
|
|
|
|
Secrets like {env}`LIVEBOOK_PASSWORD` (which is used to specify the
|
|
|
|
password needed to access the livebook site) or {env}`LIVEBOOK_COOKIE`
|
|
|
|
(which is used to specify the
|
|
|
|
[cookie](https://www.erlang.org/doc/reference_manual/distributed.html#security)
|
|
|
|
used to connect to the running Elixir system) may be passed to the
|
|
|
|
service without making them readable to everyone with access to
|
|
|
|
systemctl by using this configuration parameter.
|
|
|
|
|
|
|
|
Note that this file needs to be available on the host on which
|
|
|
|
`livebook` is running.
|
|
|
|
|
|
|
|
For security purposes, this file should contain at least
|
|
|
|
{env}`LIVEBOOK_PASSWORD` or {env}`LIVEBOOK_TOKEN_ENABLED=false`.
|
|
|
|
|
|
|
|
See the [Livebook
|
|
|
|
documentation](https://hexdocs.pm/livebook/readme.html#environment-variables)
|
|
|
|
and the [](#opt-services.livebook.environment) configuration parameter
|
|
|
|
for further options.
|
|
|
|
'';
|
|
|
|
example = "/var/lib/livebook.env";
|
|
|
|
};
|
|
|
|
|
2023-12-24 19:45:12 +01:00
|
|
|
extraPackages = mkOption {
|
|
|
|
type = with types; listOf package;
|
|
|
|
default = [ ];
|
2024-04-13 14:54:15 +02:00
|
|
|
description = ''
|
2023-12-24 19:45:12 +01:00
|
|
|
Extra packages to make available to the Livebook service.
|
|
|
|
'';
|
|
|
|
example = literalExpression "with pkgs; [ gcc gnumake ]";
|
|
|
|
};
|
2023-10-24 18:53:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enableUserService {
|
|
|
|
systemd.user.services.livebook = {
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "always";
|
|
|
|
EnvironmentFile = cfg.environmentFile;
|
2024-01-23 22:36:52 +01:00
|
|
|
ExecStart = "${cfg.package}/bin/livebook start";
|
2024-01-24 10:26:00 +01:00
|
|
|
KillMode = "mixed";
|
2023-10-24 18:53:12 +02:00
|
|
|
};
|
2024-01-23 22:36:52 +01:00
|
|
|
environment = mapAttrs (name: value:
|
|
|
|
if isBool value then boolToString value else toString value)
|
|
|
|
cfg.environment;
|
2023-12-24 19:45:12 +01:00
|
|
|
path = [ pkgs.bash ] ++ cfg.extraPackages;
|
2023-10-24 18:53:12 +02:00
|
|
|
wantedBy = [ "default.target" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.doc = ./livebook.md;
|
|
|
|
}
|