nix-config/hosts/uranus/stateful-jupyter.nix

90 lines
2.2 KiB
Nix
Raw Normal View History

2023-06-09 22:32:39 +02:00
{ pkgs, config, lib, ... }:
let
jupyterUsers = [
{
username = "0xa";
userPasswordFile = config.sops.secrets.hashed-password-0xa.path;
isAdmin = true;
}
2023-06-10 23:35:13 +02:00
{
username = "tassilo";
userPasswordFile = config.sops.secrets.hashed-password-tassilo.path;
isAdmin = true;
}
{
username = "marenz";
userPasswordFile = config.sops.secrets.hashed-password-marenz.path;
isAdmin = true;
}
2023-06-09 22:32:39 +02:00
];
2023-06-09 23:37:18 +02:00
# move the secrets to the volume
2023-06-10 13:43:46 +02:00
secret-setup = (lib.strings.concatStringsSep "\n" (builtins.map (u: "cp --force --dereference ${u.userPasswordFile} /var/lib/pw/") jupyterUsers));
2023-06-09 22:32:39 +02:00
in
2023-05-30 16:00:35 +02:00
{
2023-06-10 23:35:13 +02:00
sops.secrets = {
hashed-password-0xa = { };
hashed-password-tassilo = { };
hashed-password-marenz = { };
};
2023-06-09 22:32:39 +02:00
2023-05-30 16:00:35 +02:00
virtualisation.docker = {
enable = true;
# magic from marenz to make it work on ceph
storageDriver = "devicemapper";
extraOptions = "--storage-opt dm.basesize=40G --storage-opt dm.fs=xfs";
};
systemd.enableUnifiedCgroupHierarchy = false;
# user to run the thing
# jupyterlab container
virtualisation.oci-containers = {
backend = "docker";
containers."jupyterlab-stateful" = {
autoStart = true;
ports = [ "8080:8080" ];
2023-05-30 17:44:15 +02:00
volumes = [
"/var/lib/jupyter-volume:/workdir"
"/var/lib/root-home:/root"
2023-06-09 22:39:38 +02:00
"/var/lib/pw:/pw"
2023-05-30 17:44:15 +02:00
];
2023-05-30 20:10:59 +02:00
imageFile =
let
2023-06-09 19:47:15 +02:00
packages = lib.concatStringsSep " " [
2023-05-30 20:10:59 +02:00
# alphabetically `:sort`ed plz
2023-06-01 12:43:29 +02:00
"geojson"
2023-05-30 20:10:59 +02:00
"matplotlib"
"numpy"
"pandas"
2023-06-01 12:43:29 +02:00
"pip"
"psycopg"
2023-05-30 20:10:59 +02:00
"scipy"
"seaborn"
2023-06-08 19:12:52 +02:00
"bitstring"
2023-05-30 20:10:59 +02:00
];
in
(import ./jupyter-container.nix {
2023-06-09 19:47:15 +02:00
inherit pkgs lib jupyterUsers packages;
2023-05-30 20:10:59 +02:00
});
2023-05-30 16:00:35 +02:00
image = "stateful-jupyterlab";
};
};
2023-06-10 23:27:19 +02:00
systemd.services = {
setup-docker-pws = {
description = "copy the user passwords to docker volume";
wantedBy = [ "jupyterlab-stateful.service" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = secret-setup;
};
docker-jupyterlab-stateful = {
2023-06-10 23:28:49 +02:00
after = [ "setup-docker-pws.service" ];
requires = [ "setup-docker-pws.service" ];
2023-06-10 23:27:19 +02:00
};
2023-06-09 23:37:18 +02:00
};
2023-05-30 16:00:35 +02:00
}