Tim Windelschmidt | 48f22ce | 2023-09-20 22:48:26 +0200 | [diff] [blame] | 1 | { pkgs, extraConf ? "" }: with pkgs; |
| 2 | let |
| 3 | wrapper = pkgs.writeScript "wrapper.sh" |
| 4 | '' |
| 5 | # Fancy colorful PS1 to make people notice easily they're in the Monogon Nix shell. |
| 6 | PS1='\[\033]0;\u/monogon:\w\007\]' |
| 7 | if type -P dircolors >/dev/null ; then |
| 8 | PS1+='\[\033[01;35m\]\u/monogon\[\033[01;36m\] \w \$\[\033[00m\] ' |
| 9 | fi |
| 10 | export PS1 |
| 11 | |
| 12 | # Use Nix-provided cert store. |
| 13 | export NIX_SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt" |
| 14 | export SSL_CERT_FILE="${cacert}/etc/ssl/certs/ca-bundle.crt" |
| 15 | |
| 16 | # Let some downstream machinery know we're on NixOS. This is used mostly to |
| 17 | # work around Bazel/NixOS interactions. |
| 18 | export MONOGON_NIXOS=yep |
| 19 | |
| 20 | # Convince rules_go to use /bin/bash and not a NixOS store bash which has |
| 21 | # no idea how to resolve other things in the nix store once PATH is |
| 22 | # stripped by (host_)action_env. |
| 23 | export BAZEL_SH=/bin/bash |
| 24 | |
| 25 | ${extraConf} |
| 26 | |
| 27 | # Allow passing a custom command via env since nix-shell doesn't support |
| 28 | # this yet: https://github.com/NixOS/nix/issues/534 |
| 29 | if [ ! -n "$COMMAND" ]; then |
| 30 | COMMAND="bash --noprofile --norc" |
| 31 | fi |
| 32 | exec $COMMAND |
| 33 | ''; |
| 34 | in |
| 35 | (pkgs.buildFHSUserEnv { |
| 36 | name = "monogon-nix"; |
| 37 | targetPkgs = pkgs: with pkgs; [ |
| 38 | git |
| 39 | buildifier |
| 40 | (stdenv.mkDerivation { |
| 41 | name = "bazel"; |
| 42 | src = builtins.fetchurl { |
| 43 | url = https://github.com/bazelbuild/bazel/releases/download/5.4.0/bazel-5.4.0-linux-x86_64; |
| 44 | sha256 = "1w58m1brwjfwsv48fmd66inry67m4vgb3bwvwmamhdv099v183jg"; |
| 45 | }; |
| 46 | unpackPhase = '' |
| 47 | true |
| 48 | ''; |
| 49 | buildPhase = '' |
| 50 | mkdir -p $out/bin |
| 51 | cp $src $out/bin/.bazel-inner |
| 52 | chmod +x $out/bin/.bazel-inner |
| 53 | |
| 54 | cat > $out/bin/bazel <<EOF |
| 55 | #!/usr/bin/bash |
| 56 | export BAZEL_REAL=$out/bin/.bazel-inner |
| 57 | function get_workspace_root() { |
| 58 | workspace_dir="\''${PWD}" |
| 59 | while [[ "\''${workspace_dir}" != / ]]; do |
| 60 | if [[ -e "\''${workspace_dir}/WORKSPACE" || -e "\''${workspace_dir}/WORKSPACE.bazel" ]]; then |
| 61 | readonly workspace_dir |
| 62 | return |
| 63 | fi |
| 64 | workspace_dir="$(dirname "\''${workspace_dir}")" |
| 65 | done |
| 66 | readonly workspace_dir="" |
| 67 | } |
| 68 | |
| 69 | get_workspace_root |
| 70 | readonly wrapper="\''${workspace_dir}/tools/bazel" |
| 71 | if [ -f "\''${wrapper}" ]; then |
| 72 | exec -a "\$0" "\''${wrapper}" "\$@" |
| 73 | fi |
| 74 | exec -a "\$0" "\''${BAZEL_REAL}" "\$@" |
| 75 | EOF |
| 76 | chmod +x $out/bin/bazel |
| 77 | ''; |
| 78 | dontStrip = true; |
| 79 | }) |
| 80 | zlib |
| 81 | curl |
| 82 | gcc |
| 83 | binutils |
| 84 | openjdk11 |
| 85 | patch |
| 86 | python3 |
| 87 | busybox |
| 88 | niv |
| 89 | google-cloud-sdk |
| 90 | ]; |
| 91 | runScript = wrapper; |
| 92 | }) |