initramfs: move most of it into upstream/six-initrd submodule

master
Adam Joseph 1 year ago
parent 76f0bcd2ca
commit a499113a7a

3
.gitmodules vendored

@ -3,3 +3,6 @@
shallow = true shallow = true
url = https://github.com/nixos/nixpkgs url = https://github.com/nixos/nixpkgs
branch = nixos-unstable branch = nixos-unstable
[submodule "upstream/six-initrd"]
path = upstream/six-initrd
url = https://git.sr.ht/~amjoseph/six-initrd

@ -2,6 +2,7 @@
, lib ? import (nixpkgs + "/lib") , lib ? import (nixpkgs + "/lib")
, pkgsFun ? import nixpkgs , pkgsFun ? import nixpkgs
, hostPlatform ? null # if left `null` this will be set based on the ./platform/ , hostPlatform ? null # if left `null` this will be set based on the ./platform/
, six-initrd ? import ../upstream/six-initrd/default.nix
}: }:
let let
nixpkgsArgs = { config.allowNonSource = false; }; nixpkgsArgs = { config.allowNonSource = false; };
@ -35,7 +36,13 @@ let
coreboot = final.callPackage ./coreboot { }; coreboot = final.callPackage ./coreboot { };
image = final.callPackage ./image { }; image = final.callPackage ./image { };
kernel = final.callPackage ./kernel { }; kernel = final.callPackage ./kernel { };
initramfs = final.callPackage ./initramfs { }; initramfs = final.callPackage ./initramfs {
six-initrd = (six-initrd {
inherit (final) lib;
pkgsForHost = final.nixpkgsOnBuildForHost;
pkgsForBuild = final.nixpkgsOnBuildForBuild;
}).minimal;
};
flashrom = final.nixpkgsOnBuildForHost.callPackage ./util/flashrom { }; flashrom = final.nixpkgsOnBuildForHost.callPackage ./util/flashrom { };
main = final.callPackage ./main { }; main = final.callPackage ./main { };
scripts = prev.scripts or { scripts = prev.scripts or {

@ -5,39 +5,17 @@
{ lib { lib
, nixpkgsOnBuildForHost , nixpkgsOnBuildForHost
, nixpkgsOnBuildForBuild , nixpkgsOnBuildForBuild
, kernel
, bootScript ? ../boot.sh # symlinked to /init if non-null , bootScript ? ../boot.sh # symlinked to /init if non-null
# a list of paths (relative to ${kernel}/lib/modules/*/kernel) to modules .ko # see six-initrd
# files which should be included in the initrd
, modules ? [ ]
# An attrset containing additional files to include in the initramfs
# image. Each attrname in this set is a path relative to the root
# of the initramfs (e.g. "bin/signify") and the corresponding value is
# the file to be copied to that location (e.g. "${signify}/bin/signify).
#
# - If the attrvalue has a trailing "/" then both the source and
# destination are considered to be directories; the source will be
# copied recursively, and symbolic links therein will be preserved
# (i.e. not dereferenced). See `withBusybox` below for an example.
#
# - If the attrvalue does NOT have a trailing "/" then both the
# source and destination are considered to be files. If the
# source is a symbolic link it will be dereferenced before copying.
#
# After copying, `chmod -R u+w` is performed, since the contents are
# likely to be coming from /nix/store where Nix clears the u-w bit.
#
, contents ? {} , contents ? {}
, kernel ? null
, modules ? []
, symlinkUsrToRoot ? true
, symlinkSbinToBin ? true
# cause usr/{bin,sbin} to be symlinks to {bin/sbin} , six-initrd
, withMergedUsr ? true
# cause sbin to be a symlink to bin
, withMergedBinSbin ? true
, withBusybox ? true
, withSignify ? true , withSignify ? true
# Inclusion of these is temporarily disabled. I had a bunch of # Inclusion of these is temporarily disabled. I had a bunch of
# ugly space-saving hacks that were removed during the pre-release # ugly space-saving hacks that were removed during the pre-release
@ -51,21 +29,18 @@
}: }:
let let
inherit (nixpkgsOnBuildForBuild) findutils cpio; inherit (nixpkgsOnBuildForHost.pkgsStatic) signify lvm2 cryptsetup kexec-tools;
inherit (nixpkgsOnBuildForHost.pkgsStatic) stdenv busybox signify lvm2 cryptsetup kexec-tools;
nvramtool = nixpkgsOnBuildForHost.pkgsStatic.nvramtool.overrideAttrs(a: { nvramtool = nixpkgsOnBuildForHost.pkgsStatic.nvramtool.overrideAttrs(a: {
NIX_CFLAGS_COMPILE = "-D__GLIBC__"; NIX_CFLAGS_COMPILE = "-D__GLIBC__";
}); });
contents' = (lib.pipe modules [
(map (m: let name = "${kernel.version}/kernel/${m}"; in
in { six-initrd.override {
name = "lib/modules/${name}"; # dest inherit lib;
value = "${kernel}/lib/modules/${name}"; # source pkgsForBuild = nixpkgsOnBuildForBuild;
})) pkgsForHost = nixpkgsOnBuildForHost;
lib.listToAttrs inherit kernel modules;
]) // lib.optionalAttrs withBusybox { contents = lib.optionalAttrs withSignify {
"bin" = "${busybox}/bin/";
} // lib.optionalAttrs withSignify {
"bin/signify" = "${signify}/bin/signify"; "bin/signify" = "${signify}/bin/signify";
} // lib.optionalAttrs withLvm { } // lib.optionalAttrs withLvm {
"bin/lvm" = "${lib.getBin lvm2}/bin/lvm"; "bin/lvm" = "${lib.getBin lvm2}/bin/lvm";
@ -79,45 +54,4 @@ let
} // lib.optionalAttrs (bootScript != null) { } // lib.optionalAttrs (bootScript != null) {
"sbin/init" = "${bootScript}"; "sbin/init" = "${bootScript}";
} // contents; } // contents;
in stdenv.mkDerivation {
name = "initramfs.cpio";
dontUnpack = true;
dontFixup = true;
buildPhase = ''
runHook preBuild
'' + lib.optionalString withMergedBinSbin ''
ln -s bin sbin
'' + lib.optionalString withMergedUsr ''
mkdir -p usr
ln -s ../bin usr/bin
ln -s ../sbin usr/sbin
'' + (lib.pipe contents' [
(lib.mapAttrsToList (dest: src:
if lib.hasSuffix "/" src then ''
mkdir -p ${lib.escapeShellArg (builtins.dirOf dest)}
cp -Tr ${lib.escapeShellArg src} ${lib.escapeShellArg dest}
chmod -R u+w ${lib.escapeShellArg dest}
'' else ''
install -vDT ${lib.escapeShellArg src} ${lib.escapeShellArg dest}
''))
lib.concatStrings
]) +
''
runHook postBuild
'';
installPhase = ''
runHook preInstall
chmod -R u+w $NIX_BUILD_TOP
pushd $NIX_BUILD_TOP
${findutils}/bin/find . | ${cpio}/bin/cpio --create -H newc -R +0:+0 > $out
popd
runHook postInstall
'';
passthru = {
inherit modules;
};
} }

@ -0,0 +1 @@
Subproject commit 01a91149307d7a128a4e63f9ae8186e6331397f8
Loading…
Cancel
Save