From a499113a7a38189e0514860cb8415434a24a3c6c Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 18 Sep 2023 22:51:16 -0700 Subject: [PATCH] initramfs: move most of it into upstream/six-initrd submodule --- .gitmodules | 3 ++ src/default.nix | 9 +++- src/initramfs/default.nix | 96 ++++++--------------------------------- upstream/six-initrd | 1 + 4 files changed, 27 insertions(+), 82 deletions(-) create mode 160000 upstream/six-initrd diff --git a/.gitmodules b/.gitmodules index b50ef89..ce06cbd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,3 +3,6 @@ shallow = true url = https://github.com/nixos/nixpkgs branch = nixos-unstable +[submodule "upstream/six-initrd"] + path = upstream/six-initrd + url = https://git.sr.ht/~amjoseph/six-initrd diff --git a/src/default.nix b/src/default.nix index 8f9fe82..e8c5aa7 100644 --- a/src/default.nix +++ b/src/default.nix @@ -2,6 +2,7 @@ , lib ? import (nixpkgs + "/lib") , pkgsFun ? import nixpkgs , hostPlatform ? null # if left `null` this will be set based on the ./platform/ +, six-initrd ? import ../upstream/six-initrd/default.nix }: let nixpkgsArgs = { config.allowNonSource = false; }; @@ -35,7 +36,13 @@ let coreboot = final.callPackage ./coreboot { }; image = final.callPackage ./image { }; 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 { }; main = final.callPackage ./main { }; scripts = prev.scripts or { diff --git a/src/initramfs/default.nix b/src/initramfs/default.nix index 23047d7..cc8e064 100644 --- a/src/initramfs/default.nix +++ b/src/initramfs/default.nix @@ -5,39 +5,17 @@ { lib , nixpkgsOnBuildForHost , nixpkgsOnBuildForBuild -, kernel , bootScript ? ../boot.sh # symlinked to /init if non-null -# a list of paths (relative to ${kernel}/lib/modules/*/kernel) to modules .ko -# 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. -# +# see six-initrd , contents ? {} +, kernel ? null +, modules ? [] +, symlinkUsrToRoot ? true +, symlinkSbinToBin ? true -# cause usr/{bin,sbin} to be symlinks to {bin/sbin} -, withMergedUsr ? true - -# cause sbin to be a symlink to bin -, withMergedBinSbin ? true +, six-initrd -, withBusybox ? true , withSignify ? true # Inclusion of these is temporarily disabled. I had a bunch of # ugly space-saving hacks that were removed during the pre-release @@ -51,21 +29,18 @@ }: let - inherit (nixpkgsOnBuildForBuild) findutils cpio; - inherit (nixpkgsOnBuildForHost.pkgsStatic) stdenv busybox signify lvm2 cryptsetup kexec-tools; + inherit (nixpkgsOnBuildForHost.pkgsStatic) signify lvm2 cryptsetup kexec-tools; nvramtool = nixpkgsOnBuildForHost.pkgsStatic.nvramtool.overrideAttrs(a: { NIX_CFLAGS_COMPILE = "-D__GLIBC__"; }); - contents' = (lib.pipe modules [ - (map (m: let name = "${kernel.version}/kernel/${m}"; - in { - name = "lib/modules/${name}"; # dest - value = "${kernel}/lib/modules/${name}"; # source - })) - lib.listToAttrs - ]) // lib.optionalAttrs withBusybox { - "bin" = "${busybox}/bin/"; - } // lib.optionalAttrs withSignify { + +in +six-initrd.override { + inherit lib; + pkgsForBuild = nixpkgsOnBuildForBuild; + pkgsForHost = nixpkgsOnBuildForHost; + inherit kernel modules; + contents = lib.optionalAttrs withSignify { "bin/signify" = "${signify}/bin/signify"; } // lib.optionalAttrs withLvm { "bin/lvm" = "${lib.getBin lvm2}/bin/lvm"; @@ -79,45 +54,4 @@ let } // lib.optionalAttrs (bootScript != null) { "sbin/init" = "${bootScript}"; } // 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; - }; } diff --git a/upstream/six-initrd b/upstream/six-initrd new file mode 160000 index 0000000..01a9114 --- /dev/null +++ b/upstream/six-initrd @@ -0,0 +1 @@ +Subproject commit 01a91149307d7a128a4e63f9ae8186e6331397f8