blob: 5d4fa0133679d889858e111bf9d42f734d0633bc [file] [log] [blame]
Leopold Schabel9508b122023-07-14 17:54:17 +02001# If you're on NixOS, use me! `nix-shell --pure`.
Tim Windelschmidt98000a52025-03-06 14:22:15 +01002{ pkgs ? (import ./third_party/nix { }), extraConf ? "" }:
Leopold Schabel9508b122023-07-14 17:54:17 +02003let
Tim Windelschmidt98000a52025-03-06 14:22:15 +01004 wrapper = pkgs.writeScript "wrapper.sh"
5 ''
6 # Fancy colorful PS1 to make people notice easily they're in the Monogon Nix shell.
7 PS1='\[\033]0;\u/monogon:\w\007\]'
8 if type -P dircolors >/dev/null ; then
9 PS1+='\[\033[01;35m\]\u/monogon\[\033[01;36m\] \w \$\[\033[00m\] '
10 fi
11 export PS1
12
13 # Use Nix-provided cert store.
14 export NIX_SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
15 export SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
16
17 # Let some downstream machinery know we're on NixOS. This is used mostly to
18 # work around Bazel/NixOS interactions.
19 export MONOGON_NIXOS=yep
20
21 # Convince rules_go to use /bin/bash and not a NixOS store bash which has
22 # no idea how to resolve other things in the nix store once PATH is
23 # stripped by (host_)action_env.
24 export BAZEL_SH=/bin/bash
25
26 # buildFHSEnv makes /etc a tmpfs and symlinks some files from host /etc.
27 # Create some additional symlinks for files we want from host /etc.
28 for i in bazel.bazelrc gitconfig; do
29 if [[ -e "/.host-etc/$i" ]] && [[ ! -e "/etc/$i" ]]; then
30 ln -s "/.host-etc/$i" "/etc/$i"
31 fi
32 done
33
34 ${extraConf}
35
36 # Allow passing a custom command via env since nix-shell doesn't support
37 # this yet: https://github.com/NixOS/nix/issues/534
38 if [ ! -n "$COMMAND" ]; then
39 COMMAND="bash --noprofile --norc"
40 fi
41 exec $COMMAND
42 '';
Leopold Schabel9508b122023-07-14 17:54:17 +020043in
Tim Windelschmidt98000a52025-03-06 14:22:15 +010044(pkgs.buildFHSEnv {
45 name = "monogon-nix";
46 targetPkgs = targetPkgs: with targetPkgs; [
47 bazel-unwrapped # Our custom bazel package based on upstream
48 git
49 buildifier
50 zlib
51 curl
52 gcc
53 binutils
54 openjdk21
55 patch
56 python3
57 busybox
58 niv
59 google-cloud-sdk
60 swtpm
61 nix
62 ];
63 runScript = wrapper;
64}).env