nixos/systemd-initrd: deprecate strip

It only saved ~1MiB of initramfs size, but caused a few issues
like unloadable kernel modules.
This commit is contained in:
Gerg-L 2025-05-05 19:07:58 -04:00
parent c3cedc4177
commit 98313e2b81
No known key found for this signature in database
4 changed files with 12 additions and 55 deletions

View file

@ -132,13 +132,20 @@ let
initialRamdisk = pkgs.makeInitrdNG {
name = "initrd-${kernel-name}";
inherit (config.boot.initrd) compressor compressorArgs prepend;
inherit (cfg) strip;
contents = lib.filter ({ source, ... }: !lib.elem source cfg.suppressedStorePaths) cfg.storePaths;
};
in
{
imports = [
(lib.mkRemovedOptionModule [ "boot" "initrd" "systemd" "strip" ] ''
The option to strip ELF files in initrd has been removed.
It only saved ~1MiB of initramfs size, but caused a few issues
like unloadable kernel modules.
'')
];
options.boot.initrd.systemd = {
enable = mkEnableOption "systemd in initrd" // {
description = ''
@ -208,19 +215,6 @@ in
default = [ ];
};
strip = mkOption {
description = ''
Whether to completely strip executables and libraries copied to the initramfs.
Setting this to false may save on the order of 30MiB on the
machine building the system (by avoiding a binutils
reference), at the cost of ~1MiB of initramfs size. This puts
this option firmly in the territory of micro-optimisation.
'';
type = types.bool;
default = true;
};
extraBin = mkOption {
description = ''
Tools to add to /bin

View file

@ -1,10 +1,6 @@
{
rustPlatform,
lib,
makeWrapper,
patchelf,
glibc,
binutils,
}:
rustPlatform.buildRustPackage {

View file

@ -20,8 +20,6 @@ in
# Name of the derivation (not of the resulting file!)
name ? "initrd",
strip ? true,
# Program used to compress the cpio archive; use "cat" for no compression.
# This can also be a function which takes a package set and returns the path to the compressor,
# such as `pkgs: "${pkgs.lzop}/bin/lzop"`.
@ -95,15 +93,10 @@ runCommand name
passAsFile = [ "contents" ];
contents = builtins.toJSON contents;
nativeBuildInputs =
[
makeInitrdNGTool
cpio
]
++ lib.optional makeUInitrd ubootTools
++ lib.optional strip binutils;
STRIP = if strip then "${pkgsBuildHost.binutils.targetPrefix}strip" else null;
nativeBuildInputs = [
makeInitrdNGTool
cpio
] ++ lib.optional makeUInitrd ubootTools;
})
''
mkdir -p ./root/var/empty

View file

@ -189,32 +189,6 @@ fn copy_file<
if let Ok(Object::Elf(e)) = Object::parse(&contents) {
add_dependencies(source, e, &contents, &dlopen, queue)?;
// Make file writable to strip it
let mut permissions = fs::metadata(&target)
.wrap_err_with(|| format!("failed to get metadata for {:?}", target))?
.permissions();
permissions.set_mode(permissions.mode() | 0o200);
fs::set_permissions(&target, permissions.clone())
.wrap_err_with(|| format!("failed to set read-write permissions for {:?}", target))?;
// Strip further than normal
if let Ok(strip) = env::var("STRIP") {
if !Command::new(strip)
.arg("--strip-all")
.arg(OsStr::new(&target))
.output()?
.status
.success()
{
println!("{:?} was not successfully stripped.", OsStr::new(&target));
}
}
// Remove writable permissions
permissions.set_mode(permissions.mode() & 0o555);
fs::set_permissions(&target, permissions)
.wrap_err_with(|| format!("failed to remove writable permissions for {:?}", target))?;
};
Ok(())