tsuki/jupyter: set up tmpdirs for notebooks

This commit is contained in:
Oystein Kristoffer Tveit 2024-01-23 05:35:58 +01:00
parent 1ea23dc42e
commit ce5c3666b9
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
1 changed files with 16 additions and 6 deletions

View File

@ -40,6 +40,19 @@ in {
}; };
}; };
systemd.tmpfiles.settings."10-jupyter" = {
"/var/lib/jupyter/notebooks".d = {
mode = "0700";
user = "jupyter";
group = "jupyter";
};
"/var/lib/jupyter/data".d = {
mode = "0700";
user = "jupyter";
group = "jupyter";
};
};
systemd.services.jupyter = let systemd.services.jupyter = let
notebookConfig = pkgs.writeText "jupyter_config.py" '' notebookConfig = pkgs.writeText "jupyter_config.py" ''
c.NotebookApp.notebook_dir = 'notebooks' c.NotebookApp.notebook_dir = 'notebooks'
@ -57,8 +70,8 @@ in {
''; '';
in { in {
environment = { environment = {
JUPYTER_DATA_DIR = "$STATE_DIRECTORY/data"; JUPYTER_DATA_DIR = "%S/${config.systemd.services.jupyter.serviceConfig.StateDirectory}/data";
JUPYTER_RUNTIME_DIR = "$RUNTIME_DIRECTORY"; JUPYTER_RUNTIME_DIR = "%t/${config.systemd.services.jupyter.serviceConfig.RuntimeDirectory}";
}; };
serviceConfig = { serviceConfig = {
RuntimeDirectory = "jupyter"; RuntimeDirectory = "jupyter";
@ -86,9 +99,6 @@ in {
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ]; RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
SystemCallArchitectures = "native"; SystemCallArchitectures = "native";
ExecStartPre = ''
${pkgs.coreutils}/bin/mkdir -p /var/lib/jupyter/{notebooks,data}
'';
ExecStart = lib.mkForce '' ExecStart = lib.mkForce ''
${cfg.package}/bin/${cfg.command} --NotebookApp.config_file=${notebookConfig} ${cfg.package}/bin/${cfg.command} --NotebookApp.config_file=${notebookConfig}
''; '';