Skip to content

Commit a70859d

Browse files
committed
home: add jupyter service
1 parent e40005e commit a70859d

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

nix/home.nix

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,74 @@ in
15161516
}
15171517
))
15181518

1519+
(
1520+
let
1521+
name = "jupyter";
1522+
in
1523+
lib.optionalAttrs prefs.enableHomeManagerJupyter {
1524+
services.${name} = {
1525+
Unit = {
1526+
Description = "jupyter notebooks";
1527+
After = [
1528+
"network-online.target"
1529+
"network.target"
1530+
];
1531+
Wants = [ "network-online.target" ];
1532+
# Disable start limit.
1533+
# https://unix.stackexchange.com/questions/289629/systemd-restart-always-is-not-honored
1534+
StartLimitIntervalSec = 0;
1535+
};
1536+
Install = {
1537+
WantedBy = [ "default.target" ];
1538+
DefaultInstance = "default";
1539+
};
1540+
Service =
1541+
let
1542+
configName = "jupyter_lab_config.py";
1543+
jupyter = pkgs.python3.withPackages (
1544+
ps:
1545+
(with ps; [
1546+
ipykernel
1547+
jupyter-collaboration
1548+
jupyter-lsp
1549+
jupyterlab
1550+
])
1551+
++ (with pkgs; [ bash ])
1552+
);
1553+
jupyterLabConfig = pkgs.writeTextFile {
1554+
name = configName;
1555+
text = ''
1556+
# This config file should be a valid python script
1557+
import os
1558+
import json
1559+
notebooks_dir = os.environ.get('NOTEBOOKS_DIR')
1560+
if notebooks_dir:
1561+
c.NotebookApp.root_dir = notebooks_dir
1562+
if 'ALLOW_REMOTE_ACCESS' in os.environ:
1563+
c.ServerApp.allow_remote_access = json.loads(os.environ['ALLOW_REMOTE_ACCESS'].lower())
1564+
'';
1565+
};
1566+
in
1567+
{
1568+
Restart = "always";
1569+
RestartSteps = 20;
1570+
RestartMaxDelaySec = 3600;
1571+
ExecStart = "${jupyter}/bin/jupyter-lab --no-browser --config ${jupyterLabConfig}";
1572+
Environment = [
1573+
"NOTEBOOKS_DIR=%h/Workspace/notebooks"
1574+
"ALLOW_REMOTE_ACCESS=true"
1575+
# Used by jupyter lab itself
1576+
"JUPYTER_PORT=8899"
1577+
# JUPYTER_TOKEN=mynotebooktoken
1578+
];
1579+
EnvironmentFile = [
1580+
"-%h/.config/${name}/env"
1581+
];
1582+
};
1583+
};
1584+
}
1585+
)
1586+
15191587
(
15201588
let
15211589
name = "cloudflared@";
@@ -1541,7 +1609,6 @@ in
15411609
Restart = "always";
15421610
RestartSteps = 20;
15431611
RestartMaxDelaySec = 3600;
1544-
# It is ok to pass a non-existent key file. Ssh will warn us, but won't panic.
15451612
ExecStart = "${pkgs.cloudflared}/bin/cloudflared tunnel --no-autoupdate run";
15461613
Environment = [
15471614
# INF Cannot determine default origin certificate path. No file cert.pem in [~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp /etc/cloudflared /usr/local/etc/cloudflared] originCertPath=

nix/prefs.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ let
363363
enableHomeManagerTailScale = false;
364364
enableHomeManagerCaddy = false;
365365
enableHomeManagerCodeTunnel = false;
366+
enableHomeManagerJupyter = false;
366367
enableHomeManagerDufs = false;
367368
enableNetbird = !self.isMinimalSystem;
368369
enableX2goServer = false;
@@ -1249,6 +1250,7 @@ let
12491250
enableHomeManagerRcloneSync = true;
12501251
enableHomeManagerRcloneMount = true;
12511252
enableHomeManagerRcloneServe = true;
1253+
enableHomeManagerJupyter = true;
12521254
enableHomeManagerAutossh = true;
12531255
}
12541256
else if hostname == "madbox" then

0 commit comments

Comments
 (0)