Unverified Commit abdb91a1 authored by Paul Meyer's avatar Paul Meyer Committed by GitHub
Browse files

u-root{,-cmds}: init; gobusybox: init; mkuimage: init (#344853)

parents a8f84a9d 7273516f
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
{
  lib,
  buildGoModule,
  fetchFromGitHub,
}:

buildGoModule rec {
  pname = "gobusybox";
  version = "0.2.0-unstable-2024-03-05";

  src = fetchFromGitHub {
    owner = "u-root";
    repo = "gobusybox";
    rev = "d8fbaca23e26beab648c86c8a67335ad65d0d15c";
    hash = "sha256-hS6YwN6eekyDjp7E6sisW+8HO5WHTEC68XyKZFPihK4=";
  };

  sourceRoot = "${src.name}/src";

  subPackages = [
    "cmd/gencmddeps"
    "cmd/goanywhere"
    "cmd/makebb"
    "cmd/makebbmain"
    "cmd/rewritepkg"
  ];

  CGO_ENABLED = "0";

  vendorHash = "sha256-s4bQLXNFhyAk+UNI1xJXQABjBXtPFXiWvmdttV/6Bm8=";

  ldflags = [ "-s" ];

  meta = {
    description = "Tools for compiling many Go commands into one binary to save space";
    longDescription = "Builds are supported for vendor-based Go and module-based Go";
    homepage = "https://github.com/u-root/gobusybox";
    license = lib.licenses.bsd3;
    maintainers = with lib.maintainers; [ katexochen ];
    mainProgram = "makebb";
  };
}
+57 −0
Original line number Diff line number Diff line
{
  lib,
  buildGoModule,
  fetchFromGitHub,
  coreutils,
  bash,
  stdenv,
}:

buildGoModule {
  pname = "mkuimage";
  version = "0-unstable-2024-02-28";

  src = fetchFromGitHub {
    owner = "u-root";
    repo = "mkuimage";
    rev = "899a47eaaa318bd2327dc94d964ccda40a784037";
    hash = "sha256-sb/LtwAN7RN8jWG/x6pomz2Q+vKekA/teC7U5NVb2qY=";
  };

  vendorHash = "sha256-KX9uv5m4N4+7gOgjhotRac9sz8tWSJ1krq98RWdsbzg=";

  subPackages = [
    "cmd/gentpldeps"
    "cmd/mkuimage"
  ];

  CGO_ENABLED = "0";

  ldflags = [ "-s" ];

  # Tests are failing on darwin as they try to compile u-root binaries
  # that only work on linux.
  #
  # Notice that due to some legacy/bug in buildGoModule, the build isn't
  # failing even the tests are, as we get a false-positive the output
  # filtering: https://github.com/NixOS/nixpkgs/issues/349468
  doCheck = stdenv.isLinux;

  # The tests want to copy /bin/bash and /bin/ls, but we don't have those.
  # As these are interesting e2e tests to check if things work, we substitute
  # them with the actual paths instead of just skipping the tests.
  preCheck = ''
    substituteInPlace ./cmd/mkuimage/main_test.go \
      --replace-fail '-files=/bin/bash"' '-files=${bash}/bin/bash:bin/bash"' \
      --replace-fail '-files=/bin/ls"' '-files=${coreutils}/bin/ls:bin/ls"' \
      --replace-fail '-files=/bin/bash' '-files=${bash}/bin/bash'
  '';

  meta = {
    description = "Create small Go-based root file systems -- with support for CPIOs and (TBD) Docker images";
    homepage = "https://github.com/u-root/mkuimage";
    license = lib.licenses.bsd3;
    maintainers = with lib.maintainers; [ katexochen ];
    mainProgram = "mkuimage";
  };
}
+204 −0
Original line number Diff line number Diff line
{
  lib,
  u-root,
  which,
}:

u-root.overrideAttrs (prevAttrs: {
  subPackages = [
    "cmds/boot/boot"
    "cmds/boot/fitboot"
    "cmds/boot/pxeboot"
    "cmds/cluster/nodestats"
    "cmds/contrib/fbptcat"
    "cmds/core/backoff"
    "cmds/core/base64"
    "cmds/core/basename"
    "cmds/core/blkid"
    "cmds/core/brctl"
    "cmds/core/cat"
    "cmds/core/chmod"
    "cmds/core/chroot"
    "cmds/core/cmp"
    "cmds/core/comm"
    "cmds/core/cp"
    "cmds/core/cpio"
    "cmds/core/date"
    "cmds/core/dd"
    "cmds/core/df"
    "cmds/core/dhclient"
    "cmds/core/dirname"
    "cmds/core/dmesg"
    "cmds/core/du"
    "cmds/core/echo"
    "cmds/core/false"
    "cmds/core/find"
    "cmds/core/free"
    "cmds/core/fusermount"
    "cmds/core/gosh"
    "cmds/core/gpgv"
    "cmds/core/gpt"
    "cmds/core/grep"
    "cmds/core/gzip"
    "cmds/core/head"
    "cmds/core/hexdump"
    "cmds/core/hostname"
    "cmds/core/hwclock"
    "cmds/core/id"
    "cmds/core/init"
    "cmds/core/insmod"
    "cmds/core/io"
    "cmds/core/ip"
    "cmds/core/kexec"
    "cmds/core/kill"
    "cmds/core/lddfiles"
    "cmds/core/ln"
    "cmds/core/lockmsrs"
    "cmds/core/losetup"
    "cmds/core/ls"
    "cmds/core/lsdrivers"
    "cmds/core/lsmod"
    "cmds/core/man"
    "cmds/core/md5sum"
    "cmds/core/mkdir"
    "cmds/core/mkfifo"
    "cmds/core/mknod"
    "cmds/core/mktemp"
    "cmds/core/more"
    "cmds/core/mount"
    "cmds/core/msr"
    "cmds/core/mv"
    "cmds/core/netcat"
    "cmds/core/netstat"
    "cmds/core/nohup"
    "cmds/core/ntpdate"
    "cmds/core/pci"
    "cmds/core/ping"
    "cmds/core/poweroff"
    "cmds/core/printenv"
    "cmds/core/ps"
    "cmds/core/pwd"
    "cmds/core/readlink"
    "cmds/core/realpath"
    "cmds/core/rm"
    "cmds/core/rmmod"
    "cmds/core/rsdp"
    "cmds/core/scp"
    "cmds/core/seq"
    "cmds/core/shasum"
    "cmds/core/shutdown"
    "cmds/core/sleep"
    "cmds/core/sluinit"
    "cmds/core/sort"
    "cmds/core/sshd"
    "cmds/core/strace"
    "cmds/core/strings"
    "cmds/core/stty"
    "cmds/core/switch_root"
    "cmds/core/sync"
    "cmds/core/tail"
    "cmds/core/tar"
    "cmds/core/tee"
    "cmds/core/time"
    "cmds/core/timeout"
    "cmds/core/touch"
    "cmds/core/tr"
    "cmds/core/true"
    "cmds/core/truncate"
    "cmds/core/ts"
    "cmds/core/tty"
    "cmds/core/umount"
    "cmds/core/uname"
    "cmds/core/uniq"
    "cmds/core/unmount"
    "cmds/core/unshare"
    "cmds/core/uptime"
    "cmds/core/watchdog"
    "cmds/core/watchdogd"
    "cmds/core/wc"
    "cmds/core/wget"
    "cmds/core/which"
    "cmds/core/xargs"
    "cmds/core/yes"
    "cmds/exp/acpicat"
    "cmds/exp/acpigrep"
    "cmds/exp/ansi"
    "cmds/exp/bootvars"
    "cmds/exp/bzimage"
    "cmds/exp/cbmem"
    "cmds/exp/console"
    "cmds/exp/crc"
    "cmds/exp/disk_unlock"
    "cmds/exp/dmidecode"
    "cmds/exp/dumpebda"
    "cmds/exp/dumpmemmap"
    "cmds/exp/ectool"
    "cmds/exp/ed"
    "cmds/exp/efivarfs"
    "cmds/exp/esxiboot"
    "cmds/exp/fbnetboot"
    "cmds/exp/fbsplash"
    "cmds/exp/fdtdump"
    "cmds/exp/field"
    "cmds/exp/fixrsdp"
    "cmds/exp/forth"
    "cmds/exp/freq"
    "cmds/exp/getty"
    "cmds/exp/hdparm"
    "cmds/exp/ipmidump"
    "cmds/exp/kconf"
    "cmds/exp/localboot"
    "cmds/exp/lsfabric"
    "cmds/exp/madeye"
    "cmds/exp/modprobe"
    "cmds/exp/netbootxyz"
    "cmds/exp/newsshd"
    "cmds/exp/nvme_unlock"
    "cmds/exp/page"
    "cmds/exp/partprobe"
    "cmds/exp/pflask"
    "cmds/exp/pox"
    "cmds/exp/pxeserver"
    "cmds/exp/readelf"
    "cmds/exp/readpe"
    "cmds/exp/run"
    "cmds/exp/rush"
    "cmds/exp/smbios_transfer"
    "cmds/exp/smn"
    "cmds/exp/srvfiles"
    "cmds/exp/ssh"
    "cmds/exp/syscallfilter"
    "cmds/exp/systemboot"
    "cmds/exp/tac"
    "cmds/exp/tc"
    "cmds/exp/tcpdump"
    "cmds/exp/tcz"
    "cmds/exp/tftp"
    "cmds/exp/traceroute"
    "cmds/exp/uefiboot"
    "cmds/exp/vboot"
    "cmds/exp/vmboot"
    "cmds/exp/watch"
    "cmds/exp/zbi"
    "cmds/exp/zimage"
    "cmds/extra/tsort"
    "cmds/fwtools/flash"
    "cmds/fwtools/spidev"
  ];

  allowGoReference = false;

  nativeCheckInputs = [ which ];

  preCheck = ''
    rm cmds/core/brctl/*_test.go # Error: open /sys/class/net: no such file or directory
    rm cmds/core/du/*_test.go # Error: expected 0 got 8
    rm cmds/core/mkdir/*_test.go # Error: Mode = 'drwxr-xr-x', want: 'dgrwxrwxrwx'
    rm cmds/core/netcat/*_test.go # Error: parseRemoteAddr(tcp, ::1) = [::1 localhost], want a subset of [::1 ip6-localhost]
    rm cmds/exp/bzimage/*_test.go # Error: compressed KernelCode too big: was 611116, now 611124
  '';

  meta = (lib.removeAttrs prevAttrs.meta [ "mainProgram" ]) // {
    longDescription = "All u-root commands compiles as standalone binaries";
  };
})
+72 −0
Original line number Diff line number Diff line
{
  lib,
  buildGoModule,
  fetchFromGitHub,
  coreutils,
  bash,

  linuxManualConfig,
  fetchurl,
  linux_latest,
}:

buildGoModule rec {
  pname = "u-root";
  version = "0.14.0-unstable-2024-09-26";

  src = fetchFromGitHub {
    owner = "u-root";
    repo = "u-root";
    rev = "a620c4fc0eeeaa71ea68c27d6ef96352ed814829";
    hash = "sha256-8B2H3AwGo9friveBk4bijOph9bSSNR7PPKJYEuywgm4=";
  };

  vendorHash = null;

  subPackages = [ "." ];

  CGO_ENABLED = "0";

  ldflags = [ "-s" ];

  allowGoReference = true;

  # The tests want to copy /bin/bash and /bin/ls, but we don't have those.
  # As these are interesting e2e tests to check if things work, we substitute
  # them with the actual paths instead of just skipping the tests.
  preCheck = ''
    substituteInPlace ./uroot_test.go \
      --replace-fail '-files=/bin/bash"' '-files=${bash}/bin/bash:bin/bash"' \
      --replace-fail '-files=/bin/ls"' '-files=${coreutils}/bin/ls:bin/ls"' \
      --replace-fail '-files=/bin/bash' '-files=${bash}/bin/bash'
  '';

  passthru = {
    # Somewhat minimal kernel config for Go/u-root, used by upstream for testing.
    # This can be used to quickly run u-root locally with proper serial console output.
    kernel-amd64 = linuxManualConfig {
      inherit (linux_latest) version src;
      configfile = fetchurl {
        url = "https://raw.githubusercontent.com/hugelgupf/vmtest/5d9f3d34a58dc7b13bca786e8ac32d3e2ce4e95d/images/kernel-amd64/config_linux.txt";
        hash = "sha256-CjhWWK6YwSOXP10mpnJjG5nwLWs2cDtebvlDBLzN5fI=";
      };
      allowImportFromDerivation = true;
    };
  };

  meta = {
    description = "A fully Go userland with Linux bootloaders";
    longDescription = ''
      u-root can create a one-binary root file system (initramfs) containing a busybox-like set of tools written in Go.

      The package exposes `u-root.kernel-amd64` passthru for a minimal and pre-configured kernel to be used locally with QEMU.
    '';
    homepage = "https://u-root.org/";
    downloadPage = "https://github.com/u-root/u-root";
    changelog = "https://github.com/u-root/u-root/blob/${src.rev}/RELEASES";
    license = lib.licenses.bsd3;
    maintainers = with lib.maintainers; [ katexochen ];
    mainProgram = "u-root";
    platforms = lib.platforms.linux;
  };
}