@@ -1516,6 +1516,74 @@ in
1516
1516
}
1517
1517
) )
1518
1518
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
+
1519
1587
(
1520
1588
let
1521
1589
name = "cloudflared@" ;
1541
1609
Restart = "always" ;
1542
1610
RestartSteps = 20 ;
1543
1611
RestartMaxDelaySec = 3600 ;
1544
- # It is ok to pass a non-existent key file. Ssh will warn us, but won't panic.
1545
1612
ExecStart = "${ pkgs . cloudflared } /bin/cloudflared tunnel --no-autoupdate run" ;
1546
1613
Environment = [
1547
1614
# INF Cannot determine default origin certificate path. No file cert.pem in [~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp /etc/cloudflared /usr/local/etc/cloudflared] originCertPath=
0 commit comments