lol

hare: fix mime module

The mime module relies on the `/etc/mime.types` file. We may hardcode it
like the Golang recipe[0].

Also add a `passthru.tests.mimeModule` so that we can be certain that
the module is working.

[0]: https://github.com/NixOS/nixpkgs/blob/f1010e0469db743d14519a1efd37e23f8513d714/pkgs/development/compilers/go/1.22.nix#L79

+54 -3
+13
pkgs/by-name/ha/hare/003-use-mailcap-for-mimetypes.patch
··· 1 + diff --git a/mime/system.ha b/mime/system.ha 2 + index 73ff3496..42e7b640 100644 3 + --- a/mime/system.ha 4 + +++ b/mime/system.ha 5 + @@ -11,7 +11,7 @@ use strings; 6 + use types; 7 + 8 + // Path to the system MIME database. 9 + -export def SYSTEM_DB: str = "/etc/mime.types"; 10 + +export def SYSTEM_DB: str = "@mailcap@/etc/mime.types"; 11 + 12 + @init fn init() void = { 13 + // Done in a separate function so we can discard errors here
+28
pkgs/by-name/ha/hare/mime-module-test.nix
··· 1 + { 2 + hare, 3 + runCommandNoCC, 4 + writeText, 5 + }: 6 + let 7 + mainDotHare = writeText "main.ha" '' 8 + use fmt; 9 + use mime; 10 + export fn main() void = { 11 + const ext = "json"; 12 + match(mime::lookup_ext(ext)) { 13 + case let mime: const *mime::mimetype => 14 + fmt::printfln("Found mimetype for extension `{}`: {}", ext, mime.mime)!; 15 + case null => 16 + fmt::fatalf("Could not find mimetype for `{}`", ext); 17 + }; 18 + }; 19 + ''; 20 + in 21 + runCommandNoCC "mime-module-test" { nativeBuildInputs = [ hare ]; } '' 22 + HARECACHE="$(mktemp -d)" 23 + export HARECACHE 24 + readonly binout="test-bin" 25 + hare build -qRo "$binout" ${mainDotHare} 26 + ./$binout 27 + : 1>$out 28 + ''
+13 -3
pkgs/by-name/ha/hare/package.nix
··· 7 7 gitUpdater, 8 8 scdoc, 9 9 tzdata, 10 + mailcap, 10 11 substituteAll, 11 12 fetchpatch, 12 13 callPackage, ··· 116 117 url = "https://git.sr.ht/~sircmpwn/hare/commit/e35f2284774436f422e06f0e8d290b173ced1677.patch"; 117 118 hash = "sha256-A59bGO/9tOghV8/MomTxd8xRExkHVdoMom2d+HTfQGg="; 118 119 }) 120 + # Use mailcap `/etc/mime.types` for Hare's mime module 121 + (substituteAll { 122 + src = ./003-use-mailcap-for-mimetypes.patch; 123 + inherit mailcap; 124 + }) 119 125 ]; 120 126 121 127 nativeBuildInputs = [ ··· 169 175 170 176 passthru = { 171 177 updateScript = gitUpdater { }; 172 - tests = lib.optionalAttrs enableCrossCompilation { 173 - crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; }; 174 - }; 178 + tests = 179 + lib.optionalAttrs enableCrossCompilation { 180 + crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; }; 181 + } 182 + // lib.optionalAttrs (stdenv.buildPlatform.canExecute stdenv.hostPlatform) { 183 + mimeModule = callPackage ./mime-module-test.nix { hare = finalAttrs.finalPackage; }; 184 + }; 175 185 }; 176 186 177 187 meta = {