makeInitrdNG: Strip more and remove output

This strips all elf files as far as possible and removes a lot of
unnecessary output. Also wrap in the binaries instead of relying on
$PATH.

Changed files
+25 -10
pkgs
build-support
+8 -1
pkgs/build-support/kernel/make-initrd-ng-tool.nix
···
-
{ rustPlatform }:
+
{ rustPlatform, lib, makeWrapper, patchelf, glibc, binutils }:
rustPlatform.buildRustPackage {
pname = "make-initrd-ng";
···
src = ./make-initrd-ng;
cargoLock.lockFile = ./make-initrd-ng/Cargo.lock;
+
+
nativeBuildInputs = [ makeWrapper ];
+
+
postInstall = ''
+
wrapProgram $out/bin/make-initrd-ng \
+
--prefix PATH : ${lib.makeBinPath [ patchelf glibc binutils ]}
+
'';
}
+2 -2
pkgs/build-support/kernel/make-initrd-ng.nix
···
# compression type and filename extension.
compressorName = fullCommand: builtins.elemAt (builtins.match "([^ ]*/)?([^ ]+).*" fullCommand) 1;
in
-
{ stdenvNoCC, perl, cpio, ubootTools, lib, pkgsBuildHost, makeInitrdNGTool, patchelf, runCommand, glibc
+
{ stdenvNoCC, perl, cpio, ubootTools, lib, pkgsBuildHost, makeInitrdNGTool, patchelf, runCommand
# Name of the derivation (not of the resulting file!)
, name ? "initrd"
···
passAsFile = ["contents"];
contents = lib.concatMapStringsSep "\n" ({ object, symlink, ... }: "${object}\n${if symlink == null then "" else symlink}") contents + "\n";
-
nativeBuildInputs = [makeInitrdNGTool patchelf glibc cpio] ++ lib.optional makeUInitrd ubootTools;
+
nativeBuildInputs = [makeInitrdNGTool patchelf cpio] ++ lib.optional makeUInitrd ubootTools;
} ''
mkdir ./root
make-initrd-ng "$contentsPath" ./root
+15 -7
pkgs/build-support/kernel/make-initrd-ng/src/main.rs
···
use std::io::{BufReader, BufRead, Error, ErrorKind};
use std::os::unix;
use std::path::{Component, Path, PathBuf};
-
use std::process::{Command, Stdio};
+
use std::process::Command;
struct NonRepeatingQueue<T> {
queue: VecDeque<T>,
···
let output = Command::new("patchelf")
.arg(&mode)
.arg(&path)
-
.stderr(Stdio::inherit())
.output()?;
if output.status.success() {
Ok(String::from_utf8(output.stdout).expect("Failed to parse output"))
···
}
}
-
fn copy_file<P: AsRef<Path> + AsRef<OsStr>, S: AsRef<Path>>(
+
fn copy_file<P: AsRef<Path> + AsRef<OsStr>, S: AsRef<Path> + AsRef<OsStr>>(
source: P,
target: S,
queue: &mut NonRepeatingQueue<Box<Path>>,
) -> Result<(), Error> {
-
fs::copy(&source, target)?;
+
fs::copy(&source, &target)?;
if !Command::new("ldd").arg(&source).output()?.status.success() {
-
//stdout(Stdio::inherit()).stderr(Stdio::inherit()).
-
println!("{:?} is not dynamically linked. Not recursing.", OsStr::new(&source));
+
// Not dynamically linked - no need to recurse
return Ok(());
}
···
println!("Warning: Couldn't satisfy dependency {} for {:?}", line, OsStr::new(&source));
}
}
+
+
// Make file writable to strip it
+
let mut permissions = fs::metadata(&target)?.permissions();
+
permissions.set_readonly(false);
+
fs::set_permissions(&target, permissions)?;
+
+
// Strip further than normal
+
if !Command::new("strip").arg("--strip-all").arg(OsStr::new(&target)).output()?.status.success() {
+
println!("{:?} was not successfully stripped.", OsStr::new(&target));
+
}
+
Ok(())
}
···
}
}
while let Some(obj) = queue.pop_front() {
-
println!("{:?}", obj);
handle_path(out_path, &*obj, &mut queue)?;
}