1{ lib
2, stdenv
3, fetchFromSourcehut
4, fetchurl
5, curl
6, libarchive
7, libpkgconf
8, pkgconf
9, python3
10, samurai
11, scdoc
12, zlib
13, embedSamurai ? false
14, buildDocs ? true
15}:
16
17stdenv.mkDerivation (finalAttrs: {
18 pname = "muon"
19 + lib.optionalString embedSamurai "-embedded-samurai";
20 version = "0.2.0";
21
22 src = fetchFromSourcehut {
23 name = "muon-src";
24 owner = "~lattis";
25 repo = "muon";
26 rev = finalAttrs.version;
27 hash = "sha256-ZHWyUV/BqM3ihauXDqDVkZURDDbBiRcEzptyGQmw94I=";
28 };
29
30 outputs = [ "out" ] ++ lib.optionals buildDocs [ "man" ];
31
32 nativeBuildInputs = [
33 pkgconf
34 samurai
35 ]
36 ++ lib.optionals buildDocs [
37 (python3.withPackages (ps: [ ps.pyyaml ]))
38 scdoc
39 ];
40
41 buildInputs = [
42 curl
43 libarchive
44 libpkgconf
45 samurai
46 zlib
47 ];
48
49 strictDeps = true;
50
51 postUnpack = let
52 # URLs manually extracted from subprojects directory
53 meson-docs-wrap = fetchurl {
54 name = "meson-docs-wrap";
55 url = "https://mochiro.moe/wrap/meson-docs-1.0.1-19-gdd8d4ee22.tar.gz";
56 hash = "sha256-jHSPdLFR5jUeds4e+hLZ6JOblor5iuCV5cIwoc4K9gI=";
57 };
58
59 samurai-wrap = fetchurl {
60 name = "samurai-wrap";
61 url = "https://mochiro.moe/wrap/samurai-1.2-32-g81cef5d.tar.gz";
62 hash = "sha256-aPMAtScqweGljvOLaTuR6B0A0GQQQrVbRviXY4dpCoc=";
63 };
64 in ''
65 pushd $sourceRoot/subprojects
66 ${lib.optionalString buildDocs "tar xvf ${meson-docs-wrap}"}
67 ${lib.optionalString embedSamurai "tar xvf ${samurai-wrap}"}
68 popd
69 '';
70
71 postPatch = ''
72 patchShebangs bootstrap.sh
73 ''
74 + lib.optionalString buildDocs ''
75 patchShebangs subprojects/meson-docs/docs/genrefman.py
76 '';
77
78 # tests try to access "~"
79 postConfigure = ''
80 export HOME=$(mktemp -d)
81 '';
82
83 buildPhase = let
84 muonBool = lib.mesonBool;
85 muonEnable = lib.mesonEnable;
86
87 cmdlineForMuon = lib.concatStringsSep " " [
88 (muonBool "static" stdenv.targetPlatform.isStatic)
89 (muonEnable "docs" buildDocs)
90 (muonEnable "samurai" embedSamurai)
91 ];
92 cmdlineForSamu = "-j$NIX_BUILD_CORES";
93 in ''
94 runHook preBuild
95
96 ./bootstrap.sh stage-1
97
98 ./stage-1/muon setup ${cmdlineForMuon} stage-2
99 samu ${cmdlineForSamu} -C stage-2
100
101 stage-2/muon setup -Dprefix=$out ${cmdlineForMuon} stage-3
102 samu ${cmdlineForSamu} -C stage-3
103
104 runHook postBuild
105 '';
106
107 # tests are failing because they don't find Python
108 doCheck = false;
109
110 checkPhase = ''
111 runHook preCheck
112
113 ./stage-3/muon -C stage-3 test
114
115 runHook postCheck
116 '';
117
118 installPhase = ''
119 runHook preInstall
120
121 stage-3/muon -C stage-3 install
122
123 runHook postInstall
124 '';
125
126 meta = with lib; {
127 homepage = "https://muon.build/";
128 description = "An implementation of Meson build system in C99";
129 license = licenses.gpl3Only;
130 maintainers = with maintainers; [ AndersonTorres ];
131 platforms = platforms.unix;
132 broken = stdenv.isDarwin; # typical `ar failure`
133 };
134})
135# TODO LIST:
136# 1. automate sources acquisition (especially wraps)
137# 2. setup hook
138# 3. tests