Unable to package runit on Macos

Runit runs fine on MacOS, but the nix package definition declares that it only works on Linux.

I figured I could modify it to allow for the MacOS directions (which I did follow and worked fine).

My changes, below:

diff --git a/pkgs/tools/system/runit/default.nix b/pkgs/tools/system/runit/default.nix
index a4319fd5749..6db3b22c3b6 100644
--- a/pkgs/tools/system/runit/default.nix
+++ b/pkgs/tools/system/runit/default.nix
@@ -1,8 +1,7 @@
 { stdenv, fetchurl
 
 # Build runit-init as a static binary
-, static ? false
-}:
+, static ? false }:
 
 stdenv.mkDerivation rec {
   pname = "runit";
@@ -13,9 +12,7 @@ stdenv.mkDerivation rec {
     sha256 = "065s8w62r6chjjs6m9hapcagy33m75nlnxb69vg0f4ngn061dl3g";
   };
 
-  patches = [
-    ./fix-ar-ranlib.patch
-  ];
+  patches = [ ./fix-ar-ranlib.patch ];
 
   outputs = [ "out" "man" ];
 
@@ -23,9 +20,10 @@ stdenv.mkDerivation rec {
 
   doCheck = true;
 
-  buildInputs = stdenv.lib.optionals static [ stdenv.cc.libc stdenv.cc.libc.static ];
+  buildInputs =
+    stdenv.lib.optionals static [ stdenv.cc.libc stdenv.cc.libc.static ];
 
-  postPatch = ''
+  postPatch = "" + stdenv.lib.optionalString stdenv.isLinux ''
     sed -i "s,\(#define RUNIT\) .*,\1 \"$out/bin/runit\"," src/runit.h
     # usernamespace sandbox of nix seems to conflict with runit's assumptions
     # about unix users. Therefor skip the check
@@ -39,8 +37,8 @@ stdenv.mkDerivation rec {
 
     # Both of these are originally hard-coded to gcc
     echo ${stdenv.cc.targetPrefix}cc > conf-cc
-    echo ${stdenv.cc.targetPrefix}cc > conf-ld
-  '';
+    echo ${stdenv.cc.targetPrefix}cc''
+    + stdenv.lib.optionalString stdenv.isDarwin " -Xlinker -x" + " > conf-ld";
 
   installPhase = ''
     mkdir -p $out/bin
@@ -55,6 +53,6 @@ stdenv.mkDerivation rec {
     license = licenses.bsd3;
     homepage = "http://smarden.org/runit";
     maintainers = with maintainers; [ joachifm ];
-    platforms = platforms.linux;
+    platforms = platforms.linux ++ platforms.darwin;
   };
 }

Compilation, however, fails upon trying to compile tryuwtmpx.c, shown below:

[nix-shell:../src]$ ./compile ./tryuwtmpx.c
./tryuwtmpx.c:7:14: error: incomplete definition of type 'struct futmpx'
  char *s =ut.ut_name;
           ~~^
./tryuwtmpx.c:4:8: note: forward declaration of 'struct futmpx'
struct futmpx ut;
       ^
./tryuwtmpx.c:4:15: error: tentative definition has type 'struct futmpx' that is never completed
struct futmpx ut;
              ^
./tryuwtmpx.c:4:8: note: forward declaration of 'struct futmpx'
struct futmpx ut;
       ^
2 errors generated.

The output of cc-conf is just cc.

cc --version puts out

clang version 7.1.0 (tags/RELEASE_710/final)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /nix/store/r9rg4hqk1lga7w3dcxnkdg6c88cm8lfr-clang-7.1.0/bin

By default, runit uses gcc to compile. gcc --version puts out

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

So I guess my question is what exactly is the difference between cc and gcc here? Is it just a version issue? is it the IncludeDir flag on gcc? How would I go about fixing this?

I work on a project that utilizes runit to run it, and am slowly trying to build out a nix-shell to manage it. Any tips or assistance would be greatly appreciated!

Update: turns out I need to explicitly add darwin.apple_sdk.libs.utmp as a buildInput

Which, ultimately, makes sense.