summary refs log tree commit diff
path: root/nixos/modules/services/misc/ihaskell.nix
blob: 684a242d7385b1cfbf6227dd0eb84a9b57ef655a (plain) (blame)
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
55
56
57
58
59
60
61
62
63
{ pkgs, lib, config, ... }:

with lib;

let

  cfg = config.services.ihaskell;
  ihaskell = pkgs.ihaskell.override {
    packages = self: cfg.extraPackages self;
  };

in

{
  options = {
    services.ihaskell = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Autostart an IHaskell notebook service.";
      };

      extraPackages = mkOption {
        default = self: [];
        example = literalExample ''
          haskellPackages: [
            haskellPackages.wreq
            haskellPackages.lens
          ]
        '';
        description = ''
          Extra packages available to ghc when running ihaskell. The
          value must be a function which receives the attrset defined
          in <varname>haskellPackages</varname> as the sole argument.
        '';
      };
    };
  };

  config = mkIf cfg.enable {

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

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

    systemd.services.ihaskell = {
      description = "IHaskell notebook instance";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      serviceConfig = {
        User = config.users.users.ihaskell.name;
        Group = config.users.groups.ihaskell.name;
        ExecStart = "${pkgs.runtimeShell} -c \"cd $HOME;${ihaskell}/bin/ihaskell-notebook\"";
      };
    };
  };
}