commit 4e22a4885467d1782905be91a9c14d356f1722d5 Author: Jan-Erik Rediger Date: Tue May 14 21:02:43 2024 +0200 init diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bbfe7ea --- /dev/null +++ b/flake.nix @@ -0,0 +1,24 @@ +{ + description = "Hare for mac"; + + outputs = { self, nixpkgs, ... }: + let + supportedSystems = [ "x86_64-darwin" "aarch64-darwin" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + in + { + devShells = forAllSystems (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + harec = pkgs.callPackage ./pkgs/harec.nix { }; + #hare = pkgs.callPackage ./pkgs/hare.nix { inherit harec; }; + in + { + default = pkgs.mkShell { + buildInputs = [ + harec + ]; + }; + }); + }; +} diff --git a/pkgs/hare.nix b/pkgs/hare.nix new file mode 100644 index 0000000..b6b9803 --- /dev/null +++ b/pkgs/hare.nix @@ -0,0 +1,71 @@ +{ + stdenv, + lib, + makeWrapper, + scdoc, + substituteAll, + qbe, + harec, + binutils-unwrapped, + tzdata +}: +let + platform = lib.toLower stdenv.hostPlatform.uname.system; + arch = stdenv.hostPlatform.uname.processor; + qbePlatform = { + x86_64 = "amd64_sysv"; + aarch64 = "arm64"; + riscv64 = "rv64"; + }.${arch}; +in +stdenv.mkDerivation (finalAttrs: { + pname = "hare"; + version = "0.24"; + src = builtins.fetchGit { + url = "https://git.sr.ht/~sircmpwn/hare"; + ref = "master"; + rev = "0cd51184a7acdfd4ef20195d1648622b04477293"; + }; + + patches = [ + ]; + + nativeBuildInputs = [ + harec + makeWrapper + qbe + scdoc + ]; + + buildInputs = [ + binutils-unwrapped + harec + qbe + tzdata + ]; + + makeFlags = [ + "HARECACHE=.harecache" + "PREFIX=${builtins.placeholder "out"}" + "ARCH=${arch}" + "VERSION=${finalAttrs.version}-nixpkgs" + "QBEFLAGS=-t${qbePlatform}" + "CC=${stdenv.cc.targetPrefix}cc" + "AS=${stdenv.cc.targetPrefix}as" + "LD=${stdenv.cc.targetPrefix}ld" + # Strip the variable of an empty $(SRCDIR)/hare/third-party, since nix does + # not follow the FHS. + "HAREPATH=$(SRCDIR)/hare/stdlib" + ]; + + postConfigure = '' + ln -s configs/linux.mk config.mk + ''; + + postFixup = '' + wrapProgram $out/bin/hare \ + --prefix PATH : ${lib.makeBinPath [binutils-unwrapped harec qbe]} + ''; + + setupHook = ./setup-hook.sh; +}) diff --git a/pkgs/harec.nix b/pkgs/harec.nix new file mode 100644 index 0000000..889b7d3 --- /dev/null +++ b/pkgs/harec.nix @@ -0,0 +1,35 @@ +{ lib, stdenv, qbe }: +let + platform = lib.toLower stdenv.hostPlatform.uname.system; + arch = stdenv.hostPlatform.uname.processor; + qbePlatform = { + x86_64 = "amd64_sysv"; + aarch64 = "arm64"; + riscv64 = "rv64"; + }.${arch}; +in +stdenv.mkDerivation (finalAttrs: { + pname = "harec"; + version = "0.24"; + src = builtins.fetchGit { + url = "github.com/hshq/harelang-harec"; + ref = "master"; + rev = "51446fdef8b39df1fbf4fa2644d3f51f020f974a"; + }; + buildInputs = [ qbe ]; + nativeBuildInputs = [ qbe ]; + + makeFlags = [ + "PREFIX=${builtins.placeholder "out"}" + "ARCH=${arch}" + "VERSION=${finalAttrs.version}-nixpkgs" + "QBEFLAGS=-t${qbePlatform}" + "CC=${stdenv.cc.targetPrefix}cc" + "AS=${stdenv.cc.targetPrefix}as" + "LD=${stdenv.cc.targetPrefix}ld" + ]; + + postConfigure = '' + ln -s configs/darwin.mk config.mk + ''; +}) diff --git a/pkgs/setup-hook.sh b/pkgs/setup-hook.sh new file mode 100644 index 0000000..d2d2c34 --- /dev/null +++ b/pkgs/setup-hook.sh @@ -0,0 +1,9 @@ +addHarepath () { + for haredir in third-party stdlib; do + if [[ -d "$1/src/hare/$haredir" ]]; then + addToSearchPath HAREPATH "$1/src/hare/$haredir" + fi + done +} + +addEnvHooks "$hostOffset" addHarepath