patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 91e598fd23d2eeccf6962f35fa182289c31917a9 2529 bytes (raw)
name: host/initramfs/default.nix 	 # note: path name is non-authoritative(*)

 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 
{ pkgs ? import <nixpkgs> {} }: pkgs.callPackage (

{ lib, stdenv, runCommand, writeReferencesToFile, pkgsStatic
, busybox, cpio, cryptsetup, linux, lvm2
, fetchpatch
}:

let
  inherit (lib) cleanSource cleanSourceWith concatMapStringsSep;

  # https://github.com/NixOS/nixpkgs/pull/148948
  cryptsetup = (pkgsStatic.cryptsetup.override {
    lvm2 = (pkgsStatic.lvm2.override {
      udev = null;
    }).overrideAttrs (old: {
      patches = (old.patches or []) ++ [
        (fetchpatch {
          url = "https://raw.githubusercontent.com/NixOS/nixpkgs/bf8b0d818a6c5fa65f318603756762af492c1a0c/pkgs/os-specific/linux/lvm2/no-shared.diff";
          sha256 = "sha256-t67Osvcn92R7q9V+KDW+SyJDmajzVbnTPONlokcBU9U=";
        })
      ];
      configureFlags = old.configureFlags ++ [ "--enable-static_link" ];
      makeFlags = old.makeFlags ++ [ "libdm.device-mapper" ];
      installPhase = ''
        install -D -t $out/lib libdm/ioctl/libdevmapper.a
        make -C libdm install_include
        make -C libdm install_pkgconfig
      '';
      outputs = [ "out" ];
    });
  }).overrideAttrs (old: {
    NIX_LDFLAGS = "";
    configureFlags = old.configureFlags ++ [
      "--enable-static-cryptsetup"
    ];
  });

  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;
}
) {}

debug log:

solving 91e598f ...
found 91e598f in https://inbox.spectrum-os.org/spectrum-devel/20211212141114.3238230-1-yuka@yuka.dev/
found ba6ede2 in https://spectrum-os.org/git/spectrum
preparing index
index prepared:
100644 ba6ede2e20649870e2f0c6ad8db56b3f7515056b	host/initramfs/default.nix

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20211212141114.3238230-1-yuka@yuka.dev/
diff --git a/host/initramfs/default.nix b/host/initramfs/default.nix
index ba6ede2..91e598f 100644

Checking patch host/initramfs/default.nix...
Applied patch host/initramfs/default.nix cleanly.

index at:
100644 91e598fd23d2eeccf6962f35fa182289c31917a9	host/initramfs/default.nix

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).