summaryrefslogtreecommitdiff
path: root/pkgs/os-specific/linux/minimal-bootstrap/coreutils/static.nix
blob: 22eca3a3c873ad63fef9e54f524b06e5a26d6268 (plain)
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
{
  lib,
  buildPlatform,
  hostPlatform,
  fetchurl,
  bash,
  gcc,
  musl,
  binutils,
  gnumake,
  gnused,
  gnugrep,
  gawk,
  diffutils,
  findutils,
  gnutar,
  gzip,
  linux-headers,
}:
let
  inherit (import ./common.nix { inherit lib; }) meta;
  pname = "coreutils-static";
  version = "9.10";

  src = fetchurl {
    url = "mirror://gnu/coreutils/coreutils-${version}.tar.gz";
    hash = "sha256-4L3h+2hQlEf8cjzyUX6KjH+kZ2mRm7dJDtNQoukjhWI=";
  };

  configureFlags = [
    "--prefix=${placeholder "out"}"
    "--build=${buildPlatform.config}"
    "--host=${hostPlatform.config}"
    "--disable-dependency-tracking"
    "--disable-nls"
    # libstdbuf.so fails in static builds
    "--enable-no-install-program=stdbuf"
    "--enable-single-binary=symlinks"
    "CC=musl-gcc"
    "CFLAGS=\"-static -I${linux-headers}/include\""
  ];
in
bash.runCommand "${pname}-${version}"
  {
    inherit pname version meta;

    nativeBuildInputs = [
      gcc
      musl
      binutils
      gnumake
      gnused
      gnugrep
      gawk
      diffutils
      findutils
      gnutar
      gzip
    ];

    passthru.tests.get-version =
      result:
      bash.runCommand "${pname}-get-version-${version}" { } ''
        ${result}/bin/coreutils --version
        mkdir $out
      '';
  }
  ''
    # Unpack
    tar xzf ${src}
    cd coreutils-${version}

    # Configure
    bash ./configure ${lib.concatStringsSep " " configureFlags}

    # Build
    make -j $NIX_BUILD_CORES

    # Install
    make -j $NIX_BUILD_CORES install-strip

    # Remove documentation not needed in the bootstrap chain.
    rm -rf $out/share/info $out/share/man
  ''