aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/misc/mathics.nix
blob: c588a30d76cd143046e7cef70c0c0bf19902e350 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{ pkgs, lib, config, ... }:

with lib;

let
  cfg = config.services.mathics;

in {
  options = {
    services.mathics = {
      enable = mkEnableOption "Mathics notebook service";

      external = mkOption {
        type = types.bool;
        default = false;
        description = "Listen on all interfaces, rather than just localhost?";
      };

      port = mkOption {
        type = types.int;
        default = 8000;
        description = "TCP port to listen on.";
      };
    };
  };

  config = mkIf cfg.enable {

    users.users.mathics = {
      group = config.users.groups.mathics.name;
      description = "Mathics user";
      home = "/var/lib/mathics";
      createHome = true;
      uid = config.ids.uids.mathics;
    };

    users.groups.mathics.gid = config.ids.gids.mathics;

    systemd.services.mathics = {
      description = "Mathics notebook server";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      serviceConfig = {
        User = config.users.users.mathics.name;
        Group = config.users.groups.mathics.name;
        ExecStart = concatStringsSep " " [
          "${pkgs.mathics}/bin/mathicsserver"
          "--port" (toString cfg.port)
          (if cfg.external then "--external" else "")
        ];
      };
    };
  };
}