nixos/initrd: add compressorArgs, make compressor option public

This commit is contained in:
Dominik Xaver Hörl 2020-08-23 00:12:42 +02:00 committed by Linus Heckemann
parent 14fbf575ec
commit d4ef25db5d
1 changed files with 22 additions and 7 deletions

View File

@ -308,7 +308,7 @@ let
# the initial RAM disk. # the initial RAM disk.
initialRamdisk = pkgs.makeInitrd { initialRamdisk = pkgs.makeInitrd {
name = "initrd-${kernel-name}"; name = "initrd-${kernel-name}";
inherit (config.boot.initrd) compressor prepend; inherit (config.boot.initrd) compressor compressorArgs prepend;
contents = contents =
[ { object = bootStage1; [ { object = bootStage1;
@ -334,7 +334,9 @@ let
# Script to add secret files to the initrd at bootloader update time # Script to add secret files to the initrd at bootloader update time
initialRamdiskSecretAppender = initialRamdiskSecretAppender =
pkgs.writeScriptBin "append-initrd-secrets" let
compressorExe = initialRamdisk.compressorExecutableFunction pkgs;
in pkgs.writeScriptBin "append-initrd-secrets"
'' ''
#!${pkgs.bash}/bin/bash -e #!${pkgs.bash}/bin/bash -e
function usage { function usage {
@ -376,7 +378,7 @@ let
} }
(cd "$tmp" && find . -print0 | sort -z | cpio -o -H newc -R +0:+0 --reproducible --null) | \ (cd "$tmp" && find . -print0 | sort -z | cpio -o -H newc -R +0:+0 --reproducible --null) | \
${config.boot.initrd.compressor} >> "$1" ${compressorExe} ${lib.escapeShellArgs initialRamdisk.compressorArgs} >> "$1"
''; '';
in in
@ -511,13 +513,26 @@ in
}; };
boot.initrd.compressor = mkOption { boot.initrd.compressor = mkOption {
internal = true; default = "gzip";
default = "gzip -9n"; type = types.unspecified; # We don't have a function type...
type = types.str; description = ''
description = "The compressor to use on the initrd image."; The compressor to use on the initrd image. May be any of:
- A string representing a command available in stdenv, e.g. "xz";
- A function which, given the nixpkgs package set, returns the path to a compressor tool, e.g. pkgs: "''${pkgs.pigz}/bin/pigz"
- (not recommended, because it does not work when cross-compiling) the full path to a compressor tool, e.g. "''${pkgs.pigz}/bin/pigz"
The given program should read data from stdin and write it to stdout compressed.
'';
example = "xz"; example = "xz";
}; };
boot.initrd.compressorArgs = mkOption {
default = null;
type = types.nullOr (types.listOf types.str);
description = "Arguments to pass to the compressor for the initrd image, or null to use the compressor's defaults.";
};
boot.initrd.secrets = mkOption boot.initrd.secrets = mkOption
{ default = {}; { default = {};
type = types.attrsOf (types.nullOr types.path); type = types.attrsOf (types.nullOr types.path);