-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
195 lines (173 loc) · 6.93 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# SPDX-FileCopyrightText: 2021 Serokell <https://serokell.io/>
#
# SPDX-License-Identifier: CC0-1.0
{
description = "Playground to run haskell code in Telegram";
inputs = {
nixpkgs2023-04-17.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs2024-04-20.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs2024-04-25.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs2023-04-17, nixpkgs2024-04-20, nixpkgs2024-04-25, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs2023-04-17 = nixpkgs2023-04-17.legacyPackages.${system};
pkgs2024-04-20 = nixpkgs2024-04-20.legacyPackages.${system};
pkgs2024-04-25 = nixpkgs2024-04-25.legacyPackages.${system};
globalPkgs = pkgs2024-04-20;
overrideHaskellPackages = hp:
hp.override { overrides = self: super:
{ mkDerivation = args: super.mkDerivation
(args // { doCheck = false; doHaddock = false; });
}; };
intercalate = globalPkgs.lib.concatStringsSep;
haskellPackages = globalPkgs.haskell.packages.ghc964.override {
overrides = self: super: {
telegram-bot-simple = super.callHackageDirect {
pkg = "telegram-bot-simple";
ver = "0.14";
sha256 = "sha256-aNIVStEznuXEGpaOOTyvBo9zzmXK1CsrtQzaxTlIecc=";
} {};
telegram-bot-api = super.callHackageDirect {
pkg = "telegram-bot-api";
ver = "7.3";
sha256 = "sha256-4f1KHcdQLdo0pMLFE486R85w9qQRARmzxMALQDfcNCA=";
} {};
};
};
packageName = "playground-hs";
genericPackages = pkgs: with pkgs;
[ lens
effectful
conduit
streaming
aeson
lens-aeson
megaparsec
typed-process
foldl
massiv
generic-lens
vector-algorithms
vinyl
wreq
servant
];
mkGhcFromScratchWith = pkgs: ghcVer: packageList:
let hp = overrideHaskellPackages (pkgs.haskell.packages.${ghcVer});
in hp.ghcWithPackages packageList;
mkGhcSimple = pkgs: ghcVer:
pkgs.haskell.packages.${ghcVer}.ghcWithPackages genericPackages;
mkGhcFromScratch = pkgs: ghcVer:
mkGhcFromScratchWith pkgs ghcVer genericPackages;
ghcs = {
ghc8107 = mkGhcFromScratch pkgs2023-04-17 "ghc8107";
ghc902 = mkGhcSimple pkgs2023-04-17 "ghc902";
ghc927 = mkGhcSimple pkgs2023-04-17 "ghc927";
ghc944 = mkGhcFromScratch pkgs2023-04-17 "ghc944";
ghc964 = mkGhcSimple pkgs2024-04-20 "ghc964";
ghc982 = mkGhcFromScratchWith pkgs2024-04-20 "ghc982" (_: []);
ghc9101 = mkGhcFromScratchWith pkgs2024-04-25 "ghc9101" (_: []);
};
ghcDeps = builtins.attrValues ghcs ++ [globalPkgs.bash globalPkgs.coreutils];
envVars = {workers ? 8, timeout ? defaultTO, workDir ? "$HOME/.local/share/plaground-hs" }:
with globalPkgs;
( builtins.mapAttrs (key: val: "${val}/bin/ghc" ) ghcs ) //
{
GHCS = intercalate "," (builtins.attrNames ghcs);
DEFAULT_GHC = "${ghcs.ghc964}/bin/ghc";
BWRAP = "${bubblewrap}/bin/bwrap";
GHC_DEPS = "${closureInfo { rootPaths = ghcDeps; }}/store-paths";
SCRIPTS_DIR = ./scripts;
WORK_DIR = workDir;
WORKERS_COUNT = toString workers;
TIMEOUT = intercalate "," (map (x: toString x) (timeoutToList timeout));
TIMEOUT_PROG = "${coreutils}/bin/timeout";
};
timeoutToList = timeout:
[ timeout.compiler.term timeout.compiler.kill timeout.prog.term timeout.prog.kill ];
defaultTO = {compiler = {term = 2; kill = 3;}; prog = {term = 1; kill = 2;};};
in {
packages.${packageName} =
haskellPackages.callCabal2nix packageName self rec {
};
packages.${"${packageName}-full"} =
globalPkgs.writeShellScriptBin "playground-hs" ''
${intercalate " " (
globalPkgs.lib.mapAttrsToList (name: value: name + "=" + value)
(envVars {}))
} ${self.packages.${system}.${packageName}}/bin/playground-hs
'';
legacyPackages = globalPkgs;
defaultPackage = self.packages.${system}.${packageName};
nixosModules.default = with globalPkgs.lib; { config, ... }:
let cfg = config.services.playground-hs;
in
{
options.services.playground-hs = {
enable = mkEnableOption "playground-hs bot for Telegram";
envFile = mkOption {
type = types.str;
default = "/etc/playground-hs.env";
};
workersCount = mkOption {
type = types.int;
default = 8;
};
workDir = mkOption {
type = types.str;
default = "/usr/share/playground-hs";
};
timeout = {
compiler = {
term = mkOption {
type = types.int;
default = 2;
};
kill = mkOption {
type = types.int;
default = 3;
};
};
prog = {
term = mkOption {
type = types.int;
default = 1;
};
kill = mkOption {
type = types.int;
default = 2;
};
};
};
};
config = mkIf cfg.enable {
systemd.services.playground-hs = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${self.defaultPackage.${system}}/bin/playground-hs";
EnvironmentFile = cfg.envFile;
Environment = intercalate " "
(mapAttrsToList (name: value: name + "=" + value)
(envVars
{ workers = cfg.workersCount;
timeout = cfg.timeout;
workDir = cfg.workDir;
}));
};
};
};
};
devShell = globalPkgs.mkShell ({
buildInputs = with globalPkgs; [
haskellPackages.haskell-language-server # you must build it with your ghc to work
ghc
cabal-install
lzma
zlib
];
inputsFrom = [ self.packages.${system}.${packageName}.env ];
} // envVars { workDir = "id-storage"; });
});
}