initrd: Allows wrapping init with strace
That wrapper script may be used with other helpers in the future.
@@ -8,7 +8,14 @@ let
runCommandNoCC
udev
;
- inherit (lib) flatten optionals;
+ inherit (lib) flatten optionals optionalString;
+
+ initWrapperRealInit = "/actual-init";
+
+ # TODO: define as an option
+ withStrace = false;
+
+ initWrapperEnabled = withStrace;
device_config = config.mobile.device;
device_name = device_config.name;
@@ -18,6 +25,24 @@ let
mobile-nixos-init = pkgs.pkgsStatic.callPackage ../boot/init {};
init = "${mobile-nixos-init}/bin/init";
+ shell = "${extraUtils}/bin/sh";
+ debugInit = pkgs.writeScript "debug-init" ''
+ #!${shell}
+
+ echo
+ echo "***************************************"
+ echo "* Mobile NixOS stage-0 script wrapper *"
+ echo "***************************************"
+ echo
+
+ PS4="=> "
+ set -x
+
+ export LD_LIBRARY_PATH="${extraUtils}/lib"
+
+ exec ${optionalString withStrace "${extraUtils}/bin/strace -f"} ${initWrapperRealInit}
+ '';
+
contents =
(optionals (stage-1 ? contents) (flatten stage-1.contents))
++ [
@@ -27,8 +52,14 @@ let
# FIXME: udev/udevRules module.
{ object = udevRules; symlink = "/etc/udev/rules.d"; }
+ ]
+ ++ optionals (!initWrapperEnabled) [
{ object = init; symlink = "/init"; }
]
+ ++ optionals initWrapperEnabled [
+ { object = init; symlink = initWrapperRealInit; }
+ { object = debugInit; symlink = "/init"; }
+ ]
;
udevRules = runCommandNoCC "udev-rules" {
@@ -97,6 +128,15 @@ let
''
;
}]
+ ++ optionals withStrace [
+ {
+ package = runCommandNoCC "empty" {} "mkdir -p $out";
+ extraCommand = with pkgs; ''
+ copy_bin_and_libs ${strace}/bin/strace
+ cp -fpv ${glibc.out}/lib/libgcc_s.so* $out/lib
+ '';
+ }
+ ]
;
};
