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