Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib
2, stdenv
3, stdenvNoLibs
4, fetchFromGitea
5, runtimeShell
6, doCheck ? withLibc && stdenv.hostPlatform == stdenv.buildPlatform
7, withLibc ? true
8}:
9
10let
11 # k itself can be compiled with -ffreestanding, but tests require a libc;
12 # if we want to build k-libc we need a libc obviously
13 useStdenv = if withLibc || doCheck then stdenv else stdenvNoLibs;
14in
15
16useStdenv.mkDerivation {
17 pname = "ngn-k";
18 version = "unstable-2022-11-28";
19
20 src = fetchFromGitea {
21 domain = "codeberg.org";
22 owner = "ngn";
23 repo = "k";
24 rev = "e5138f182a8ced07dd240e3fe58274130842a85d";
25 sha256 = "1pn416znrdndb8iccprzx4zicmsx8c6i9dm3wq5z3jg8nan53p69";
26 };
27
28 patches = [
29 ./repl-license-path.patch
30 ];
31
32 postPatch = ''
33 patchShebangs --build a19/a.sh a20/a.sh a21/a.sh dy/a.sh e/a.sh
34
35 # don't use hardcoded /bin/sh
36 for f in repl.k repl-bg.k m.c;do
37 substituteInPlace "$f" --replace "/bin/sh" "${runtimeShell}"
38 done
39 '';
40
41 makeFlags = [ "-e" ];
42 buildFlags = [
43 (if withLibc then "k-libc" else "k")
44 "libk.so"
45 ];
46 checkTarget = "t";
47 inherit doCheck;
48
49 outputs = [ "out" "dev" "lib" ];
50
51 # TODO(@sternenseemann): package bulgarian translation
52 installPhase = ''
53 runHook preInstall
54 install -Dm755 k "$out/bin/k"
55 install -Dm755 repl.k "$out/bin/k-repl"
56 install -Dm755 libk.so "$lib/lib/libk.so"
57 install -Dm644 k.h "$dev/include/k.h"
58 install -Dm644 LICENSE -t "$out/share/ngn-k"
59 substituteInPlace "$out/bin/k-repl" --replace "#!k" "#!$out/bin/k"
60 runHook postInstall
61 '';
62
63 meta = {
64 description = "A simple fast vector programming language";
65 homepage = "https://codeberg.org/ngn/k";
66 license = lib.licenses.agpl3Only;
67 maintainers = [ lib.maintainers.sternenseemann ];
68 platforms = [ "x86_64-linux" "x86_64-freebsd13" ];
69 };
70}