1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
| | { pkgs ? import <nixpkgs> {} }: pkgs.callPackage (
{ lib, stdenv, runCommand, writeReferencesToFile, pkgsStatic
, busybox, cpio, cryptsetup, linux, lvm2
}:
let
cryptsetup' = cryptsetup;
in
let
inherit (lib) cleanSource cleanSourceWith concatMapStringsSep;
cryptsetup = cryptsetup'.override { lvm2 = lvm2.override { udev = null; }; };
packages = [
cryptsetup pkgsStatic.mdevd pkgsStatic.execline
(busybox.override {
enableStatic = true;
extraConfig = ''
CONFIG_FINDFS n
'';
})
];
packagesSysroot = runCommand "packages-sysroot" {} ''
mkdir -p $out/bin
ln -s ${concatMapStringsSep " " (p: "${p}/bin/*") packages} $out/bin
cp -R ${linux}/lib $out
ln -s /bin $out/sbin
# TODO: this is a hack and we should just build the util-linux
# programs we want.
# https://lore.kernel.org/util-linux/87zgrl6ufb.fsf@alyssa.is/
cp ${pkgsStatic.util-linux.override { systemd = null; }}/bin/{findfs,lsblk} $out/bin
'';
packagesCpio = runCommand "packages.cpio" {
nativeBuildInputs = [ cpio ];
storePaths = writeReferencesToFile packagesSysroot;
} ''
cd ${packagesSysroot}
(printf "/nix\n/nix/store\n" && find . $(< $storePaths)) |
cpio -o -H newc -R +0:+0 --reproducible > $out
'';
in
stdenv.mkDerivation {
name = "initramfs";
src = cleanSourceWith {
filter = name: _type: name != "${toString ./.}/build" && name != "${toString ./.}/spectrum-live";
src = cleanSource ./.;
};
PACKAGES_CPIO = packagesCpio;
nativeBuildInputs = [ cpio ];
installPhase = ''
cp build/initramfs $out
'';
enableParallelBuilding = true;
}
) {}
|