summary refs log tree commit diff
path: root/pkgs/os-specific/linux/minimal-bootstrap/bash/default.nix
blob: dea5ad9f017fe67b5b61f1db37c780472d009db2 (plain) (blame)
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
90
91
92
93
94
95
96
97
98
99
{ lib
, buildPlatform
, hostPlatform
, fetchurl
, bootBash
, gnumake
, gnused
, gnugrep
, gnutar
, gawk
, gzip
, gcc
, glibc
, binutils
, linux-headers
, derivationWithMeta
, bash
, coreutils
}:
let
  pname = "bash";
  version = "5.2.15";

  src = fetchurl {
    url = "mirror://gnu/bash/bash-${version}.tar.gz";
    sha256 = "132qng0jy600mv1fs95ylnlisx2wavkkgpb19c6kmz7lnmjhjwhk";
  };
in
bootBash.runCommand "${pname}-${version}" {
  inherit pname version;

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

  passthru.runCommand = name: env: buildCommand:
    derivationWithMeta ({
      inherit name buildCommand;
      builder = "${bash}/bin/bash";
      args = [
        "-e"
        (builtins.toFile "bash-builder.sh" ''
          export CONFIG_SHELL=$SHELL
          bash -eux $buildCommandPath
        '')
      ];
      passAsFile = [ "buildCommand" ];

      SHELL = "${bash}/bin/bash";
      PATH = lib.makeBinPath ((env.nativeBuildInputs or []) ++ [
        bash
        coreutils
      ]);
    } // (builtins.removeAttrs env [ "nativeBuildInputs" ]));

  passthru.tests.get-version = result:
    bootBash.runCommand "${pname}-get-version-${version}" {} ''
      ${result}/bin/bash --version
      mkdir $out
    '';

  meta = with lib; {
    description = "GNU Bourne-Again Shell, the de facto standard shell on Linux";
    homepage = "https://www.gnu.org/software/bash";
    license = licenses.gpl3Plus;
    maintainers = teams.minimal-bootstrap.members;
    platforms = platforms.unix;
  };
} ''
  # Unpack
  tar xzf ${src}
  cd bash-${version}

  # Configure
  export CC="gcc -I${glibc}/include -I${linux-headers}/include"
  export LIBRARY_PATH="${glibc}/lib"
  export LIBS="-lc -lnss_files -lnss_dns -lresolv"
  export ac_cv_func_dlopen=no
  bash ./configure \
    --prefix=$out \
    --build=${buildPlatform.config} \
    --host=${hostPlatform.config} \
    --disable-nls \
    --disable-net-redirections

  # Build
  make SHELL=bash

  # Install
  make install
  ln -s bash $out/bin/sh
''