about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/by-name/ha/hare/003-use-mailcap-for-mimetypes.patch13
-rw-r--r--pkgs/by-name/ha/hare/mime-module-test.nix28
-rw-r--r--pkgs/by-name/ha/hare/package.nix16
3 files changed, 54 insertions, 3 deletions
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 = {