1{ pkgs, lib, config, ... }:
2
3with lib;
4
5let
6 cfg = config.services.mathics;
7
8in {
9 options = {
10 services.mathics = {
11 enable = mkEnableOption "Mathics notebook service";
12
13 external = mkOption {
14 type = types.bool;
15 default = false;
16 description = "Listen on all interfaces, rather than just localhost?";
17 };
18
19 port = mkOption {
20 type = types.int;
21 default = 8000;
22 description = "TCP port to listen on.";
23 };
24 };
25 };
26
27 config = mkIf cfg.enable {
28
29 users.extraUsers.mathics = {
30 group = config.users.extraGroups.mathics.name;
31 description = "Mathics user";
32 home = "/var/lib/mathics";
33 createHome = true;
34 uid = config.ids.uids.mathics;
35 };
36
37 users.extraGroups.mathics.gid = config.ids.gids.mathics;
38
39 systemd.services.mathics = {
40 description = "Mathics notebook server";
41 wantedBy = [ "multi-user.target" ];
42 after = [ "network.target" ];
43 serviceConfig = {
44 User = config.users.extraUsers.mathics.name;
45 Group = config.users.extraGroups.mathics.name;
46 ExecStart = concatStringsSep " " [
47 "${pkgs.mathics}/bin/mathicsserver"
48 "--port" (toString cfg.port)
49 (if cfg.external then "--external" else "")
50 ];
51 };
52 };
53 };
54}