-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
120 lines (101 loc) · 3.48 KB
/
flake.nix
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
{
description = "jassbot - jass cli util";
inputs = {
# nixpkgs.url = "github:NixOS/nixpkgs";
commonj.url = "github:lep/common-j";
commonj.inputs.nixpkgs.follows = "nixpkgs";
commonj.inputs.flake-utils.follows = "flake-utils";
flake-utils.url = "github:numtide/flake-utils";
# flake-utils.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils, commonj }:
flake-utils.lib.eachDefaultSystem (system:
let
cj = commonj.packages.${system}.common-j;
pkgs = import nixpkgs { inherit system; };
ghcPackages = pkgs.haskellPackages.ghcWithPackages (ps: [
ps.optparse-applicative
ps.megaparsec
ps.utf8-string
ps.network
ps.warp
ps.wai
ps.HostAndPort
ps.aeson
ps.http-types
# ps.snap
]);
j = pkgs.stdenv.mkDerivation {
name = "j";
src = self;
buildPhase = ''
${ghcPackages}/bin/ghc -O j
'';
installPhase = ''
install -Dt $out/bin j
'';
};
web = pkgs.stdenv.mkDerivation {
name = "web";
src = self;
buildPhase = ''
${ghcPackages}/bin/ghc -O web
'';
installPhase = ''
install -Dt $out/bin web
'';
};
docker = pkgs.dockerTools.buildLayeredImage {
name = "jassbot-api";
tag = "latest";
config = { Entrypoint = [ "${web}/bin/web" "${cj}/common.j" ]; };
};
nixosModule = { config, lib, pkgs, ... }:
let cfg = config.jassbot.services.api;
in {
options.jassbot.services.api = {
enable = lib.mkEnableOption "Enable jassbot web API";
num-results = lib.mkOption {
description = "How many results to show at most";
type = lib.types.ints.positive;
default = 40;
};
threshold = lib.mkOption {
description = "Minimum score to be displayed";
type = lib.types.numbers.between 0 1;
default = 0.4;
};
address = lib.mkOption {
description = "Connection string";
default = "127.0.0.1:3000";
example = "/var/run/unix.sock";
type = lib.types.str;
};
jass-files = lib.mkOption {
description = "List of jass files to parse";
default = [ "${cj}/common.j" ];
type = lib.types.listOf lib.types.path;
};
};
config = lib.mkIf cfg.enable {
systemd.services."jassbot.api" = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${web}/bin/web --threshold ${toString cfg.threshold} --num-results ${toString cfg.num-results} --address ${toString cfg.address} ${toString cfg.jass-files}";
};
};
};
};
in {
packages.j = j;
packages.web = web;
packages.docker = docker;
defaultPackage = j;
# TODO: this is scoped under system
nixosModules.default = nixosModule;
devShell = pkgs.mkShell {
buildInputs = [ ghcPackages pkgs.cabal-install ];
inputsFrom = builtins.attrValues self.packages.${system};
};
});
}