summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanne Heß <janne@hess.ooo>2022-05-03 09:41:22 +0200
committerGitHub <noreply@github.com>2022-05-03 09:41:22 +0200
commit2edce508477b461f26bc40e01c54171ec6d4392d (patch)
tree241f3e31fe6f9fbdb0d3613fd548c7e8ae17eab0
parent70c293cf8165dd124ce6b54cfc4e2b17c90cbb2e (diff)
parent31b23a1725b81010241dc783a9f46320aa238e3b (diff)
Merge pull request #171134 from helsinki-systems/feat/make-initrd-ng-strip
makeInitrdNG: Strip more and remove output
-rw-r--r--nixos/modules/system/boot/systemd/shutdown.nix2
-rw-r--r--nixos/tests/systemd-initrd-simple.nix2
-rw-r--r--pkgs/build-support/kernel/make-initrd-ng-tool.nix9
-rw-r--r--pkgs/build-support/kernel/make-initrd-ng.nix4
-rw-r--r--pkgs/build-support/kernel/make-initrd-ng/src/main.rs22
5 files changed, 27 insertions, 12 deletions
diff --git a/nixos/modules/system/boot/systemd/shutdown.nix b/nixos/modules/system/boot/systemd/shutdown.nix
index 63e1751f9b41..ca4cdf827d95 100644
--- a/nixos/modules/system/boot/systemd/shutdown.nix
+++ b/nixos/modules/system/boot/systemd/shutdown.nix
@@ -44,7 +44,7 @@ in {
];
};
- path = [pkgs.util-linux pkgs.makeInitrdNGTool pkgs.glibc pkgs.patchelf];
+ path = [pkgs.util-linux pkgs.makeInitrdNGTool];
serviceConfig.Type = "oneshot";
script = ''
mkdir -p /run/initramfs
diff --git a/nixos/tests/systemd-initrd-simple.nix b/nixos/tests/systemd-initrd-simple.nix
index 959cc87c0f26..5d98114304b7 100644
--- a/nixos/tests/systemd-initrd-simple.nix
+++ b/nixos/tests/systemd-initrd-simple.nix
@@ -1,7 +1,7 @@
import ./make-test-python.nix ({ lib, pkgs, ... }: {
name = "systemd-initrd-simple";
- machine = { pkgs, ... }: {
+ nodes.machine = { pkgs, ... }: {
boot.initrd.systemd = {
enable = true;
emergencyAccess = true;
diff --git a/pkgs/build-support/kernel/make-initrd-ng-tool.nix b/pkgs/build-support/kernel/make-initrd-ng-tool.nix
index 66ffc09d43cf..654b10367812 100644
--- a/pkgs/build-support/kernel/make-initrd-ng-tool.nix
+++ b/pkgs/build-support/kernel/make-initrd-ng-tool.nix
@@ -1,4 +1,4 @@
-{ rustPlatform }:
+{ rustPlatform, lib, makeWrapper, patchelf, glibc, binutils }:
rustPlatform.buildRustPackage {
pname = "make-initrd-ng";
@@ -6,4 +6,11 @@ rustPlatform.buildRustPackage {
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 ]}
+ '';
}
diff --git a/pkgs/build-support/kernel/make-initrd-ng.nix b/pkgs/build-support/kernel/make-initrd-ng.nix
index 1890bbcd173a..5f0a70f8a969 100644
--- a/pkgs/build-support/kernel/make-initrd-ng.nix
+++ b/pkgs/build-support/kernel/make-initrd-ng.nix
@@ -8,7 +8,7 @@ let
# 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"
@@ -72,7 +72,7 @@ in
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
diff --git a/pkgs/build-support/kernel/make-initrd-ng/src/main.rs b/pkgs/build-support/kernel/make-initrd-ng/src/main.rs
index 1342734590f7..294c570a3741 100644
--- a/pkgs/build-support/kernel/make-initrd-ng/src/main.rs
+++ b/pkgs/build-support/kernel/make-initrd-ng/src/main.rs
@@ -6,7 +6,7 @@ use std::hash::Hash;
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>,
@@ -42,7 +42,6 @@ fn patch_elf<S: AsRef<OsStr>, P: AsRef<OsStr>>(mode: S, path: P) -> Result<Strin
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"))
@@ -51,16 +50,15 @@ fn patch_elf<S: AsRef<OsStr>, P: AsRef<OsStr>>(mode: S, path: P) -> Result<Strin
}
}
-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(());
}
@@ -91,6 +89,17 @@ fn copy_file<P: AsRef<Path> + AsRef<OsStr>, S: AsRef<Path>>(
}
}
+ // 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(())
}
@@ -200,7 +209,6 @@ fn main() -> Result<(), Error> {
}
}
while let Some(obj) = queue.pop_front() {
- println!("{:?}", obj);
handle_path(out_path, &*obj, &mut queue)?;
}