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