blob: 155726c76f843ebe171f9aac06b785672a6dd5b7 [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
Tim Windelschmidt78fd25b2025-07-02 21:30:09 +020048 zlib # Bazel dependency
49 python3 # Workspace status script
50 git # Bazel expects git to be available
51 gnupg # our gopass integration requires gpg in the PATH
52 niv # For updating third_party/nix
53 google-cloud-sdk # Pushing containers to GCR
Tim Windelschmidt98000a52025-03-06 14:22:15 +010054 ];
55 runScript = wrapper;
56}).env