about summary refs log tree commit diff
path: root/pkgs/tools/system/s6-rc
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-08-18 17:15:47 +0000
committerAlyssa Ross <hi@alyssa.is>2021-08-18 20:09:19 +0000
commit6e6c8b733815d809cba84421bb88647f37bf8cb6 (patch)
tree649434cb5a9daddf3c7653f0a6a7e142a87c59c2 /pkgs/tools/system/s6-rc
parent158d92cbb2a715bc444f94e19bebed23decbc46d (diff)
downloadnixlib-6e6c8b733815d809cba84421bb88647f37bf8cb6.tar
nixlib-6e6c8b733815d809cba84421bb88647f37bf8cb6.tar.gz
nixlib-6e6c8b733815d809cba84421bb88647f37bf8cb6.tar.bz2
nixlib-6e6c8b733815d809cba84421bb88647f37bf8cb6.tar.lz
nixlib-6e6c8b733815d809cba84421bb88647f37bf8cb6.tar.xz
nixlib-6e6c8b733815d809cba84421bb88647f37bf8cb6.tar.zst
nixlib-6e6c8b733815d809cba84421bb88647f37bf8cb6.zip
s6-rc: fix cross builds that run s6-rc-compile
The reason for this change is explained in the long comment I added.

Here's a simple example of the problem:

	let
	  pkgs = import <nixpkgs> { crossSystem.system = "aarch64-linux"; };
	in

	pkgs.callPackage ({ stdenv, s6-rc }: stdenv.mkDerivation {
	  name = "s6-rc-compiled";

	  nativeBuildInputs = [ s6-rc ];

	  buildCommand = ''
	    mkdir in
	    s6-rc-compile $out in
	  '';
	}) {}

We're cross compiling for aarch64 here, so we'd expect the scripts
generated by this derivation to be things we could run on aarch64.
But when I build this on my x86_64 machine, without this change
applied, $out/servicedirs/s6rc-oneshot-runner/run gets generated full
of references to x86_64 non-cross store paths for execline, s6, and
s6-rc.

With this change applied, the scripts generated by the above
expression now refer to the cross-compiled aarch64 store paths for
execline, s6, and s6-rc.
Diffstat (limited to 'pkgs/tools/system/s6-rc')
-rw-r--r--pkgs/tools/system/s6-rc/default.nix21
1 files changed, 20 insertions, 1 deletions
diff --git a/pkgs/tools/system/s6-rc/default.nix b/pkgs/tools/system/s6-rc/default.nix
index df2058f43a40..31b9c14257af 100644
--- a/pkgs/tools/system/s6-rc/default.nix
+++ b/pkgs/tools/system/s6-rc/default.nix
@@ -1,4 +1,4 @@
-{ lib, skawarePackages }:
+{ lib, stdenv, skawarePackages, targetPackages }:
 
 with skawarePackages;
 
@@ -30,6 +30,25 @@ buildPackage {
     "--with-dynlib=${s6.out}/lib"
   ];
 
+  # s6-rc-compile generates built-in service definitions containing
+  # absolute paths to execline, s6, and s6-rc programs.  If we're
+  # running s6-rc-compile as part of a Nix derivation, and we want to
+  # cross-compile that derivation, those paths will be wrong --
+  # they'll be for execline, s6, and s6-rc on the platform we're
+  # running s6-rc-compile on, not the platform we're targeting.
+  #
+  # We can detect this special case of s6-rc being used at build time
+  # in a derivation that's being cross-compiled, because that's the
+  # only time hostPlatform != targetPlatform.  When that happens we
+  # modify s6-rc-compile to use the configuration headers for the
+  # system we're cross-compiling for.
+  postConfigure = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) ''
+    substituteInPlace src/s6-rc/s6-rc-compile.c \
+        --replace '<execline/config.h>' '"${targetPackages.execline.dev}/include/execline/config.h"' \
+        --replace '<s6/config.h>' '"${targetPackages.s6.dev}/include/s6/config.h"' \
+        --replace '<s6-rc/config.h>' '"${targetPackages.s6-rc.dev}/include/s6-rc/config.h"'
+  '';
+
   postInstall = ''
     # remove all s6 executables from build directory
     rm $(find -name "s6-rc-*" -type f -mindepth 1 -maxdepth 1 -executable)