blob: 69e6ac4b0c00f2a6c30d780f78a20d2b0900db9f [file] [log] [blame]
Leopold Schabel9508b122023-07-14 17:54:17 +02001# If you're on NixOS, use me! `nix-shell --pure`.
2with 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}) {};
7let
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 Schabel14bd5192023-08-14 12:19:01 +000013 PS1+='\[\033[01;35m\]\u/monogon\[\033[01;36m\] \w \$\[\033[00m\] '
Leopold Schabel9508b122023-07-14 17:54:17 +020014 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 '';
32in
33(pkgs.buildFHSUserEnv {
34 name = "monogon-nix";
35 targetPkgs = pkgs: with pkgs; [
36 git
Leopold Schabelc38aca22023-08-14 12:22:13 +000037 buildifier
Leopold Schabel9508b122023-07-14 17:54:17 +020038 (stdenv.mkDerivation {
39 name = "bazel";
40 src = builtins.fetchurl {
41 url = https://github.com/bazelbuild/bazel/releases/download/5.4.0/bazel-5.4.0-linux-x86_64;
42 sha256 = "1w58m1brwjfwsv48fmd66inry67m4vgb3bwvwmamhdv099v183jg";
43 };
44 unpackPhase = ''
45 true
46 '';
47 buildPhase = ''
48 mkdir -p $out/bin
49 cp $src $out/bin/.bazel-inner
50 chmod +x $out/bin/.bazel-inner
51
52 cat > $out/bin/bazel <<EOF
53 #!/usr/bin/bash
54 export BAZEL_REAL=$out/bin/.bazel-inner
55 function get_workspace_root() {
56 workspace_dir="\''${PWD}"
57 while [[ "\''${workspace_dir}" != / ]]; do
58 if [[ -e "\''${workspace_dir}/WORKSPACE" || -e "\''${workspace_dir}/WORKSPACE.bazel" ]]; then
59 readonly workspace_dir
60 return
61 fi
62 workspace_dir="$(dirname "\''${workspace_dir}")"
63 done
64 readonly workspace_dir=""
65 }
66
67 get_workspace_root
68 readonly wrapper="\''${workspace_dir}/tools/bazel"
69 if [ -f "\''${wrapper}" ]; then
70 exec -a "\$0" "\''${wrapper}" "\$@"
71 fi
72 exec -a "\$0" "\''${BAZEL_REAL}" "\$@"
73 EOF
74 chmod +x $out/bin/bazel
75 '';
76 dontStrip = true;
77 })
78 zlib
79 curl
80 gcc
81 binutils
82 openjdk11
83 patch
84 python3
85 ];
86 runScript = wrapper;
87}).env
88