Merge pull request #171134 from helsinki-systems/feat/make-initrd-ng-strip

makeInitrdNG: Strip more and remove output

authored by Janne Heß and committed by GitHub 2edce508 70c293cf

+27 -12
+1 -1
nixos/modules/system/boot/systemd/shutdown.nix
··· 44 44 ]; 45 45 }; 46 46 47 - path = [pkgs.util-linux pkgs.makeInitrdNGTool pkgs.glibc pkgs.patchelf]; 47 + path = [pkgs.util-linux pkgs.makeInitrdNGTool]; 48 48 serviceConfig.Type = "oneshot"; 49 49 script = '' 50 50 mkdir -p /run/initramfs
+1 -1
nixos/tests/systemd-initrd-simple.nix
··· 1 1 import ./make-test-python.nix ({ lib, pkgs, ... }: { 2 2 name = "systemd-initrd-simple"; 3 3 4 - machine = { pkgs, ... }: { 4 + nodes.machine = { pkgs, ... }: { 5 5 boot.initrd.systemd = { 6 6 enable = true; 7 7 emergencyAccess = true;
+8 -1
pkgs/build-support/kernel/make-initrd-ng-tool.nix
··· 1 - { rustPlatform }: 1 + { rustPlatform, lib, makeWrapper, patchelf, glibc, binutils }: 2 2 3 3 rustPlatform.buildRustPackage { 4 4 pname = "make-initrd-ng"; ··· 6 6 7 7 src = ./make-initrd-ng; 8 8 cargoLock.lockFile = ./make-initrd-ng/Cargo.lock; 9 + 10 + nativeBuildInputs = [ makeWrapper ]; 11 + 12 + postInstall = '' 13 + wrapProgram $out/bin/make-initrd-ng \ 14 + --prefix PATH : ${lib.makeBinPath [ patchelf glibc binutils ]} 15 + ''; 9 16 }
+2 -2
pkgs/build-support/kernel/make-initrd-ng.nix
··· 8 8 # compression type and filename extension. 9 9 compressorName = fullCommand: builtins.elemAt (builtins.match "([^ ]*/)?([^ ]+).*" fullCommand) 1; 10 10 in 11 - { stdenvNoCC, perl, cpio, ubootTools, lib, pkgsBuildHost, makeInitrdNGTool, patchelf, runCommand, glibc 11 + { stdenvNoCC, perl, cpio, ubootTools, lib, pkgsBuildHost, makeInitrdNGTool, patchelf, runCommand 12 12 # Name of the derivation (not of the resulting file!) 13 13 , name ? "initrd" 14 14 ··· 72 72 passAsFile = ["contents"]; 73 73 contents = lib.concatMapStringsSep "\n" ({ object, symlink, ... }: "${object}\n${if symlink == null then "" else symlink}") contents + "\n"; 74 74 75 - nativeBuildInputs = [makeInitrdNGTool patchelf glibc cpio] ++ lib.optional makeUInitrd ubootTools; 75 + nativeBuildInputs = [makeInitrdNGTool patchelf cpio] ++ lib.optional makeUInitrd ubootTools; 76 76 } '' 77 77 mkdir ./root 78 78 make-initrd-ng "$contentsPath" ./root
+15 -7
pkgs/build-support/kernel/make-initrd-ng/src/main.rs
··· 6 6 use std::io::{BufReader, BufRead, Error, ErrorKind}; 7 7 use std::os::unix; 8 8 use std::path::{Component, Path, PathBuf}; 9 - use std::process::{Command, Stdio}; 9 + use std::process::Command; 10 10 11 11 struct NonRepeatingQueue<T> { 12 12 queue: VecDeque<T>, ··· 42 42 let output = Command::new("patchelf") 43 43 .arg(&mode) 44 44 .arg(&path) 45 - .stderr(Stdio::inherit()) 46 45 .output()?; 47 46 if output.status.success() { 48 47 Ok(String::from_utf8(output.stdout).expect("Failed to parse output")) ··· 51 50 } 52 51 } 53 52 54 - fn copy_file<P: AsRef<Path> + AsRef<OsStr>, S: AsRef<Path>>( 53 + fn copy_file<P: AsRef<Path> + AsRef<OsStr>, S: AsRef<Path> + AsRef<OsStr>>( 55 54 source: P, 56 55 target: S, 57 56 queue: &mut NonRepeatingQueue<Box<Path>>, 58 57 ) -> Result<(), Error> { 59 - fs::copy(&source, target)?; 58 + fs::copy(&source, &target)?; 60 59 61 60 if !Command::new("ldd").arg(&source).output()?.status.success() { 62 - //stdout(Stdio::inherit()).stderr(Stdio::inherit()). 63 - println!("{:?} is not dynamically linked. Not recursing.", OsStr::new(&source)); 61 + // Not dynamically linked - no need to recurse 64 62 return Ok(()); 65 63 } 66 64 ··· 90 88 println!("Warning: Couldn't satisfy dependency {} for {:?}", line, OsStr::new(&source)); 91 89 } 92 90 } 91 + 92 + // Make file writable to strip it 93 + let mut permissions = fs::metadata(&target)?.permissions(); 94 + permissions.set_readonly(false); 95 + fs::set_permissions(&target, permissions)?; 96 + 97 + // Strip further than normal 98 + if !Command::new("strip").arg("--strip-all").arg(OsStr::new(&target)).output()?.status.success() { 99 + println!("{:?} was not successfully stripped.", OsStr::new(&target)); 100 + } 101 + 93 102 94 103 Ok(()) 95 104 } ··· 200 209 } 201 210 } 202 211 while let Some(obj) = queue.pop_front() { 203 - println!("{:?}", obj); 204 212 handle_path(out_path, &*obj, &mut queue)?; 205 213 } 206 214