From e9ee0ff4b0c71b8787b3f70d97a2748ed8f67bf0 Mon Sep 17 00:00:00 2001 From: Coutinho de Souza Date: Tue, 14 May 2024 13:09:57 -0300 Subject: 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 --- .../ha/hare/003-use-mailcap-for-mimetypes.patch | 13 ++++++++++ pkgs/by-name/ha/hare/mime-module-test.nix | 28 ++++++++++++++++++++++ pkgs/by-name/ha/hare/package.nix | 16 ++++++++++--- 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 pkgs/by-name/ha/hare/003-use-mailcap-for-mimetypes.patch create mode 100644 pkgs/by-name/ha/hare/mime-module-test.nix (limited to 'pkgs/by-name/ha') diff --git a/pkgs/by-name/ha/hare/003-use-mailcap-for-mimetypes.patch b/pkgs/by-name/ha/hare/003-use-mailcap-for-mimetypes.patch new file mode 100644 index 0000000000000..fad17d12cb9e3 --- /dev/null +++ b/pkgs/by-name/ha/hare/003-use-mailcap-for-mimetypes.patch @@ -0,0 +1,13 @@ +diff --git a/mime/system.ha b/mime/system.ha +index 73ff3496..42e7b640 100644 +--- a/mime/system.ha ++++ b/mime/system.ha +@@ -11,7 +11,7 @@ use strings; + use types; + + // Path to the system MIME database. +-export def SYSTEM_DB: str = "/etc/mime.types"; ++export def SYSTEM_DB: str = "@mailcap@/etc/mime.types"; + + @init fn init() void = { + // Done in a separate function so we can discard errors here diff --git a/pkgs/by-name/ha/hare/mime-module-test.nix b/pkgs/by-name/ha/hare/mime-module-test.nix new file mode 100644 index 0000000000000..073ae09e35570 --- /dev/null +++ b/pkgs/by-name/ha/hare/mime-module-test.nix @@ -0,0 +1,28 @@ +{ + hare, + runCommandNoCC, + writeText, +}: +let + mainDotHare = writeText "main.ha" '' + use fmt; + use mime; + export fn main() void = { + const ext = "json"; + match(mime::lookup_ext(ext)) { + case let mime: const *mime::mimetype => + fmt::printfln("Found mimetype for extension `{}`: {}", ext, mime.mime)!; + case null => + fmt::fatalf("Could not find mimetype for `{}`", ext); + }; + }; + ''; +in +runCommandNoCC "mime-module-test" { nativeBuildInputs = [ hare ]; } '' + HARECACHE="$(mktemp -d)" + export HARECACHE + readonly binout="test-bin" + hare build -qRo "$binout" ${mainDotHare} + ./$binout + : 1>$out +'' diff --git a/pkgs/by-name/ha/hare/package.nix b/pkgs/by-name/ha/hare/package.nix index 3cf37e33109b1..5c8a80520937e 100644 --- a/pkgs/by-name/ha/hare/package.nix +++ b/pkgs/by-name/ha/hare/package.nix @@ -7,6 +7,7 @@ gitUpdater, scdoc, tzdata, + mailcap, substituteAll, fetchpatch, callPackage, @@ -116,6 +117,11 @@ stdenv.mkDerivation (finalAttrs: { url = "https://git.sr.ht/~sircmpwn/hare/commit/e35f2284774436f422e06f0e8d290b173ced1677.patch"; hash = "sha256-A59bGO/9tOghV8/MomTxd8xRExkHVdoMom2d+HTfQGg="; }) + # Use mailcap `/etc/mime.types` for Hare's mime module + (substituteAll { + src = ./003-use-mailcap-for-mimetypes.patch; + inherit mailcap; + }) ]; nativeBuildInputs = [ @@ -169,9 +175,13 @@ stdenv.mkDerivation (finalAttrs: { passthru = { updateScript = gitUpdater { }; - tests = lib.optionalAttrs enableCrossCompilation { - crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; }; - }; + tests = + lib.optionalAttrs enableCrossCompilation { + crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; }; + } + // lib.optionalAttrs (stdenv.buildPlatform.canExecute stdenv.hostPlatform) { + mimeModule = callPackage ./mime-module-test.nix { hare = finalAttrs.finalPackage; }; + }; }; meta = { -- cgit 1.4.1