blob: 2ae043c6b77608773eefb5f1d1e8e917ed66f622 [file] [log] [blame]
Tim Windelschmidt29ac1402023-08-21 15:18:19 +02001{ command ? "bash --noprofile --norc" }:
Leopold Schabel9508b122023-07-14 17:54:17 +02002# If you're on NixOS, use me! `nix-shell --pure`.
3with 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}) {};
8let
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 Schabel14bd5192023-08-14 12:19:01 +000014 PS1+='\[\033[01;35m\]\u/monogon\[\033[01;36m\] \w \$\[\033[00m\] '
Leopold Schabel9508b122023-07-14 17:54:17 +020015 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 Windelschmidt29ac1402023-08-21 15:18:19 +020031 # 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 Schabel9508b122023-07-14 17:54:17 +020037 '';
38in
39(pkgs.buildFHSUserEnv {
40 name = "monogon-nix";
41 targetPkgs = pkgs: with pkgs; [
42 git
Leopold Schabelc38aca22023-08-14 12:22:13 +000043 buildifier
Leopold Schabel9508b122023-07-14 17:54:17 +020044 (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