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