From e28ce4dc9b022451cee3ed27afc9ba4d1659c4ec Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Sun, 2 Jun 2024 00:16:12 +0200 Subject: [PATCH] add linux pkgs --- flake.nix | 20 +++++++++-- pkgs/linux/001-tzdata.patch | 28 +++++++++++++++ pkgs/linux/hare.nix | 70 +++++++++++++++++++++++++++++++++++++ pkgs/linux/harec.nix | 34 ++++++++++++++++++ pkgs/linux/setup-hook.sh | 9 +++++ 5 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 pkgs/linux/001-tzdata.patch create mode 100644 pkgs/linux/hare.nix create mode 100644 pkgs/linux/harec.nix create mode 100644 pkgs/linux/setup-hook.sh diff --git a/flake.nix b/flake.nix index d83d07a..8c053b5 100644 --- a/flake.nix +++ b/flake.nix @@ -14,11 +14,11 @@ outputs = { nixpkgs, harec-src, hare-src, ... }: let - supportedSystems = [ "x86_64-darwin" "aarch64-darwin" ]; - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + darwinSystems = [ "x86_64-darwin" "aarch64-darwin" ]; + linuxSystems = [ "x86_64-linux" "aarch64-linux" ]; in { - devShells = forAllSystems (system: + devShells = nixpkgs.lib.genAttrs darwinSystems (system: let pkgs = nixpkgs.legacyPackages.${system}; hare-as = pkgs.callPackage ./pkgs/darwin/hare-as.nix { }; @@ -27,6 +27,20 @@ harec = pkgs.callPackage ./pkgs/darwin/harec.nix { inherit harec-src hare-as hare-cc hare-ld; }; hare = pkgs.callPackage ./pkgs/darwin/hare.nix { inherit hare-src harec hare-as hare-cc hare-ld; }; in + { + default = pkgs.mkShell { + buildInputs = [ + harec + hare + ]; + }; + }) // + nixpkgs.lib.genAttrs linuxSystems (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + harec = pkgs.callPackage ./pkgs/linux/harec.nix { }; + hare = pkgs.callPackage ./pkgs/linux/hare.nix { inherit harec; }; + in { default = pkgs.mkShell { buildInputs = [ diff --git a/pkgs/linux/001-tzdata.patch b/pkgs/linux/001-tzdata.patch new file mode 100644 index 0000000..11b25e6 --- /dev/null +++ b/pkgs/linux/001-tzdata.patch @@ -0,0 +1,28 @@ +diff --git a/time/chrono/+freebsd.ha b/time/chrono/+freebsd.ha +index 26d78ab1..6861bfe8 100644 +--- a/time/chrono/+freebsd.ha ++++ b/time/chrono/+freebsd.ha +@@ -2,7 +2,7 @@ + // (c) Hare authors + + def LOCALTIME_PATH: str = "/etc/localtime"; +-def ZONEINFO_PREFIX: str = "/usr/share/zoneinfo/"; ++def ZONEINFO_PREFIX: str = "@tzdata@/share/zoneinfo/"; + + // The filepath of the system's "leap-seconds.list" file, which contains UTC/TAI + // leap second data. +diff --git a/time/chrono/+linux.ha b/time/chrono/+linux.ha +index 600f606c..8d5617e2 100644 +--- a/time/chrono/+linux.ha ++++ b/time/chrono/+linux.ha +@@ -2,8 +2,8 @@ + // (c) Hare authors + + def LOCALTIME_PATH: str = "/etc/localtime"; +-def TZDB_PATH: str = "/usr/share/zoneinfo/"; ++def TZDB_PATH: str = "@tzdata@/share/zoneinfo/"; + + // The filepath of the system's "leap-seconds.list" file, which contains UTC/TAI + // leap second data. +-export def UTC_LEAPSECS_FILE: str = "/usr/share/zoneinfo/leap-seconds.list"; ++export def UTC_LEAPSECS_PATH: str = "@tzdata@/share/zoneinfo/leap-seconds.list"; diff --git a/pkgs/linux/hare.nix b/pkgs/linux/hare.nix new file mode 100644 index 0000000..041ce53 --- /dev/null +++ b/pkgs/linux/hare.nix @@ -0,0 +1,70 @@ +{ + stdenv, + lib, + makeWrapper, + scdoc, + substituteAll, + qbe, + harec, + binutils-unwrapped, + tzdata +}: +let + 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/linux/harec.nix b/pkgs/linux/harec.nix new file mode 100644 index 0000000..87678f7 --- /dev/null +++ b/pkgs/linux/harec.nix @@ -0,0 +1,34 @@ +{ lib, stdenv, qbe }: +let + 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 = "https://git.sr.ht/~sircmpwn/harec"; + ref = "master"; + rev = "3be960cf19ecf9528b8b3aaafc135229291e01b1"; + }; + 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/linux.mk config.mk + ''; +}) diff --git a/pkgs/linux/setup-hook.sh b/pkgs/linux/setup-hook.sh new file mode 100644 index 0000000..d2d2c34 --- /dev/null +++ b/pkgs/linux/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