11 enableCrossCompilation ? (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.is64bit),
13 x86_64PkgsCrossToolchain ? pkgsCross.gnu64,
14 aarch64PkgsCrossToolchain ? pkgsCross.aarch64-multiplatform,
15 riscv64PkgsCrossToolchain ? pkgsCross.riscv64,
18 # There's no support for `aarch64` or `riscv64` for freebsd nor for openbsd on nix.
19 # See `lib.systems.doubles.aarch64` and `lib.systems.doubles.riscv64`.
22 inherit (stdenv.hostPlatform) isLinux is64bit;
23 inherit (lib) intersectLists platforms concatStringsSep;
24 workingPlatforms = intersectLists platforms.linux (with platforms; x86_64 ++ aarch64 ++ riscv64);
26 (enableCrossCompilation -> !(isLinux && is64bit))
28 The cross-compilation toolchains may only be enabled on the following platforms:
29 ${concatStringsSep "\n" workingPlatforms}
34 buildArch = stdenv.buildPlatform.uname.processor;
35 arch = stdenv.hostPlatform.uname.processor;
36 platform = lib.toLower stdenv.hostPlatform.uname.system;
39 x86_64 = "amd64_sysv";
44 embeddedOnBinaryTools =
49 inherit (toolchain.stdenv.cc) targetPrefix;
50 inherit (toolchain.stdenv.targetPlatform.uname) processor;
54 "ld" = lib.getExe' toolchain.buildPackages.binutils "${targetPrefix}ld";
55 "as" = lib.getExe' toolchain.buildPackages.binutils "${targetPrefix}as";
56 "cc" = lib.getExe' toolchain.stdenv.cc "${targetPrefix}cc";
60 builtins.foldl' (acc: elem: acc // (genPaths elem)) { } [
61 x86_64PkgsCrossToolchain
62 aarch64PkgsCrossToolchain
63 riscv64PkgsCrossToolchain
65 crossCompMakeFlags = builtins.filter (x: !(lib.hasPrefix (lib.toUpper buildArch) x)) [
66 "RISCV64_AS=${embeddedOnBinaryTools.riscv64.as}"
67 "RISCV64_CC=${embeddedOnBinaryTools.riscv64.cc}"
68 "RISCV64_LD=${embeddedOnBinaryTools.riscv64.ld}"
69 "AARCH64_AS=${embeddedOnBinaryTools.aarch64.as}"
70 "AARCH64_CC=${embeddedOnBinaryTools.aarch64.cc}"
71 "AARCH64_LD=${embeddedOnBinaryTools.aarch64.ld}"
72 "X86_64_AS=${embeddedOnBinaryTools.x86_64.as}"
73 "X86_64_CC=${embeddedOnBinaryTools.x86_64.cc}"
74 "X86_64_LD=${embeddedOnBinaryTools.x86_64.ld}"
77 stdenv.mkDerivation (finalAttrs: {
86 src = fetchFromSourcehut {
89 rev = finalAttrs.version;
90 hash = "sha256-61lckI0F+Ez5LR/8g6ftS0W7Q/+EU/1flTDFleBg6pc=";
94 # Replace FHS paths with nix store
95 (replaceVars ./001-tzdata.patch {
98 # Don't build haredoc since it uses the build `hare` bin, which breaks
100 ./002-dont-build-haredoc.patch
101 # Hardcode harec and qbe.
102 (replaceVars ./003-hardcode-qbe-and-harec.patch {
103 harec_bin = lib.getExe harec;
104 qbe_bin = lib.getExe qbe;
106 # Use mailcap `/etc/mime.types` for Hare's mime module
107 (replaceVars ./004-use-mailcap-for-mimetypes.patch {
112 nativeBuildInputs = [
124 "HARECACHE=.harecache"
125 "PREFIX=${builtins.placeholder "out"}"
127 "VERSION=${finalAttrs.version}-nixpkgs"
128 "QBEFLAGS=-t${qbePlatform}"
129 "AS=${stdenv.cc.targetPrefix}as"
130 "LD=${stdenv.cc.targetPrefix}ld"
131 "${lib.toUpper buildArch}_AS=${embeddedOnBinaryTools.${buildArch}.as}"
132 "${lib.toUpper buildArch}_CC=${embeddedOnBinaryTools.${buildArch}.cc}"
133 "${lib.toUpper buildArch}_LD=${embeddedOnBinaryTools.${buildArch}.ld}"
134 # Strip the variable of an empty $(SRCDIR)/hare/third-party, since nix does
135 # not follow the FHS.
136 "HAREPATH=$(SRCDIR)/hare/stdlib"
137 ] ++ lib.optionals enableCrossCompilation crossCompMakeFlags;
139 enableParallelBuilding = true;
141 # Append the distribution name to the version
142 env.LOCALVER = "nixpkgs";
149 ln -s configs/${platform}.mk config.mk
154 lib.optionalAttrs enableCrossCompilation {
155 crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; };
157 // lib.optionalAttrs (stdenv.buildPlatform.canExecute stdenv.hostPlatform) {
158 mimeModule = callPackage ./mime-module-test.nix { hare = finalAttrs.finalPackage; };
161 lib.optionalAttrs (enableCrossCompilation && stdenv.buildPlatform.canExecute stdenv.hostPlatform)
163 crossCompilation = callPackage ./cross-compilation-tests.nix { hare = finalAttrs.finalPackage; };
165 # To be propagated by `hareHook`.
170 homepage = "https://harelang.org/";
171 description = "Systems programming language designed to be simple, stable, and robust";
172 license = lib.licenses.gpl3Only;
173 maintainers = with lib.maintainers; [ onemoresuza ];
174 mainProgram = "hare";
175 inherit (harec.meta) platforms badPlatforms;