Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runit: Add Darwin Compatibility #89330

Merged
merged 1 commit into from Jun 3, 2020
Merged

Conversation

afontaine
Copy link
Contributor

@afontaine afontaine commented Jun 1, 2020

Not much modification is required to build and run runit on MacOS, all
that was needed was to follow runit's instructions [0] with some
guidance from homebrew's formula. [1]

0: http://smarden.org/runit/install.html
1: https://github.com/Homebrew/homebrew-core/blob/1cf1e61/Formula/runit.rb

I haven't changed the default service directory, although homebrew does. Should I do this for the sake of Catalina users? If so, is there a mechanism similar to homebrew to alert users to this difference?

Motivation for this change

A project at work uses runit to manage services in its dev environment, and I'd love to nixify it.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Not much modification is required to build and run runit on MacOS, all
that was needed was to follow runit's instructions [0] with some
guidance from homebrew's formula. [1]

0: http://smarden.org/runit/install.html
1: https://github.com/Homebrew/homebrew-core/blob/1cf1e61/Formula/runit.rb
@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Jun 1, 2020
@afontaine
Copy link
Contributor Author

I seem to be having an issue testing a sandboxed build. @ggreif would you be able to lend me some advice here?

When attempting a sandboxed build, the following is spat out:

unpacking sources
unpacking source archive /nix/store/2bi81qrzy9xrr87r2bdfw0p6c6f3bk7s-runit-2.1.2.tar.gz
dyld: Library not loaded: @rpath/CoreFoundation.framework/Versions/A/CoreFoundation
  Referenced from: /nix/store/klnm6f690d1raflbpvcr4y8nrp2hzn3p-gettext-0.20.1/lib/libintl.8.dylib
  Reason: no suitable image found.  Did find:
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation: file system sandbox blocked stat()
/nix/store/yd7798v1xb0hf07jrs3y5ypjj37nnylg-stdenv-darwin/setup: line 840: 53314 Abort trap: 6           tar xf "$fn"
do not know how to unpack source archive /nix/store/2bi81qrzy9xrr87r2bdfw0p6c6f3bk7s-runit-2.1.2.tar.gz
builder for '/nix/store/p6qymqvf5r23s4ai0zny6illcrmvhgli-runit-2.1.2.drv' failed with exit code 1
error: build of '/nix/store/p6qymqvf5r23s4ai0zny6illcrmvhgli-runit-2.1.2.drv' failed

I'm not sure if it means I need to add CoreFoundation as a build input, or if my install is broken, or if I need something like __impureHostDeps (#67166)

@afontaine
Copy link
Contributor Author

Attempting to add CoreFoundation as a buildInput didn't seem to help. Diff is

diff --git a/pkgs/tools/system/runit/default.nix b/pkgs/tools/system/runit/default.nix
index acca0acf3ef..65abeb25bc3 100644
--- a/pkgs/tools/system/runit/default.nix
+++ b/pkgs/tools/system/runit/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, darwin
+{ stdenv, fetchurl, darwin, CoreFoundation
 
 # Build runit-init as a static binary
 , static ? false
@@ -8,6 +8,7 @@ stdenv.mkDerivation rec {
   pname = "runit";
   version = "2.1.2";
 
+
   src = fetchurl {
     url = "http://smarden.org/runit/${pname}-${version}.tar.gz";
     sha256 = "065s8w62r6chjjs6m9hapcagy33m75nlnxb69vg0f4ngn061dl3g";
@@ -24,7 +25,7 @@ stdenv.mkDerivation rec {
   doCheck = true;
 
   buildInputs = stdenv.lib.optionals static [ stdenv.cc.libc stdenv.cc.libc.static ] ++
-    stdenv.lib.optional stdenv.isDarwin darwin.apple_sdk.libs.utmp;
+                stdenv.lib.optionals stdenv.isDarwin [ CoreFoundation darwin.apple_sdk.libs.utmp ];
 
   postPatch = ''
     sed -i "s,\(#define RUNIT\) .*,\1 \"$out/bin/runit\"," src/runit.h
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index cfff8addf61..e294db1b5a6 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -26067,7 +26067,9 @@ in
 
   run-scaled = callPackage ../tools/X11/run-scaled { };
 
-  runit = callPackage ../tools/system/runit { };
+  runit = callPackage ../tools/system/runit {
+    inherit (darwin.apple_sdk.frameworks) CoreFoundation;
+  };
 
   refind = callPackage ../tools/bootloaders/refind { };
 

and the same error is produced

unpacking source archive /nix/store/2bi81qrzy9xrr87r2bdfw0p6c6f3bk7s-runit-2.1.2.tar.gz
dyld: Library not loaded: @rpath/CoreFoundation.framework/Versions/A/CoreFoundation
  Referenced from: /nix/store/klnm6f690d1raflbpvcr4y8nrp2hzn3p-gettext-0.20.1/lib/libintl.8.dylib
  Reason: no suitable image found.  Did find:
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation: file system sandbox blocked stat()
/nix/store/yd7798v1xb0hf07jrs3y5ypjj37nnylg-stdenv-darwin/setup: line 840: 55330 Abort trap: 6           tar xf "$fn"
do not know how to unpack source archive /nix/store/2bi81qrzy9xrr87r2bdfw0p6c6f3bk7s-runit-2.1.2.tar.gz
builder for '/nix/store/y81yh38m0yf2ql78w3kl0pi6q0h2ddmy-runit-2.1.2.drv' failed with exit code 1

@afontaine
Copy link
Contributor Author

I see other packages (screen) calling inherit (darwin.apple_sdk.libs) utmp

diff --git a/pkgs/tools/system/runit/default.nix b/pkgs/tools/system/runit/default.nix
index acca0acf3ef..0e7674906d7 100644
--- a/pkgs/tools/system/runit/default.nix
+++ b/pkgs/tools/system/runit/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, darwin
+{ stdenv, fetchurl, darwin, utmp
 
 # Build runit-init as a static binary
 , static ? false
@@ -8,6 +8,7 @@ stdenv.mkDerivation rec {
   pname = "runit";
   version = "2.1.2";
 
+
   src = fetchurl {
     url = "http://smarden.org/runit/${pname}-${version}.tar.gz";
     sha256 = "065s8w62r6chjjs6m9hapcagy33m75nlnxb69vg0f4ngn061dl3g";
@@ -24,7 +25,7 @@ stdenv.mkDerivation rec {
   doCheck = true;
 
   buildInputs = stdenv.lib.optionals static [ stdenv.cc.libc stdenv.cc.libc.static ] ++
-    stdenv.lib.optional stdenv.isDarwin darwin.apple_sdk.libs.utmp;
+                stdenv.lib.optional stdenv.isDarwin utmp;
 
   postPatch = ''
     sed -i "s,\(#define RUNIT\) .*,\1 \"$out/bin/runit\"," src/runit.h
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index cfff8addf61..4ad68ebed2a 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -26067,7 +26067,9 @@ in
 
   run-scaled = callPackage ../tools/X11/run-scaled { };
 
-  runit = callPackage ../tools/system/runit { };
+  runit = callPackage ../tools/system/runit {
+    inherit (darwin.apple_sdk.libs) utmp;
+  };
 
   refind = callPackage ../tools/bootloaders/refind { };
 

the same error though 🤔

unpacking sources
unpacking source archive /nix/store/2bi81qrzy9xrr87r2bdfw0p6c6f3bk7s-runit-2.1.2.tar.gz
dyld: Library not loaded: @rpath/CoreFoundation.framework/Versions/A/CoreFoundation
  Referenced from: /nix/store/klnm6f690d1raflbpvcr4y8nrp2hzn3p-gettext-0.20.1/lib/libintl.8.dylib
  Reason: no suitable image found.  Did find:
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation: file system sandbox blocked stat()
/nix/store/yd7798v1xb0hf07jrs3y5ypjj37nnylg-stdenv-darwin/setup: line 840: 55647 Abort trap: 6           tar xf "$fn"
do not know how to unpack source archive /nix/store/2bi81qrzy9xrr87r2bdfw0p6c6f3bk7s-runit-2.1.2.tar.gz
builder for '/nix/store/p6qymqvf5r23s4ai0zny6illcrmvhgli-runit-2.1.2.drv' failed with exit code 1
error: build of '/nix/store/p6qymqvf5r23s4ai0zny6illcrmvhgli-runit-2.1.2.drv' failed

@ggreif
Copy link
Contributor

ggreif commented Jun 1, 2020

Sorry, I fear this is way out of my knowledge of nix.

@afontaine
Copy link
Contributor Author

oh no ok, maybe @lilyball, author of the linked issue, has an idea? 🤞

@Mic92
Copy link
Member

Mic92 commented Jun 2, 2020

@GrahamcOfBorg build runit

@lilyball
Copy link
Member

lilyball commented Jun 2, 2020

Nix 2.3.5 added /System/Library/Frameworks to the default sandbox paths on macOS so it should work there. This basically obsoletes #67166 though at the cost of allowing access to frameworks that aren't included anywhere in the dependency list.

@lilyball
Copy link
Member

lilyball commented Jun 2, 2020

FWIW prior to Nix 2.3.5 I just had my nix.conf declare extra-sandbox-paths with pretty much the exact set of paths that Nix 2.3.5 now includes. Building in the macOS sandbox wasn't usable otherwise.

@Mic92
Copy link
Member

Mic92 commented Jun 3, 2020

The package builds now, ready to merge?

@afontaine
Copy link
Contributor Author

@Mic92 I think so, if it all looks good to the team.

Thank you for the insight @lilyball. Glad to see that is improving going forward 😁

@Mic92 Mic92 merged commit 977c6ac into NixOS:master Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants