| Leopold Schabel | 9508b12 | 2023-07-14 17:54:17 +0200 | [diff] [blame] | 1 | # If you're on NixOS, use me! `nix-shell --pure`. |
| Tim Windelschmidt | 98000a5 | 2025-03-06 14:22:15 +0100 | [diff] [blame] | 2 | { pkgs ? (import ./third_party/nix { }), extraConf ? "" }: |
| Leopold Schabel | 9508b12 | 2023-07-14 17:54:17 +0200 | [diff] [blame] | 3 | let |
| Tim Windelschmidt | 98000a5 | 2025-03-06 14:22:15 +0100 | [diff] [blame] | 4 | 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 Schabel | 9508b12 | 2023-07-14 17:54:17 +0200 | [diff] [blame] | 43 | in |
| Tim Windelschmidt | 98000a5 | 2025-03-06 14:22:15 +0100 | [diff] [blame] | 44 | (pkgs.buildFHSEnv { |
| 45 | name = "monogon-nix"; |
| 46 | targetPkgs = targetPkgs: with targetPkgs; [ |
| 47 | bazel-unwrapped # Our custom bazel package based on upstream |
| Tim Windelschmidt | 78fd25b | 2025-07-02 21:30:09 +0200 | [diff] [blame^] | 48 | 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 Windelschmidt | 98000a5 | 2025-03-06 14:22:15 +0100 | [diff] [blame] | 54 | ]; |
| 55 | runScript = wrapper; |
| 56 | }).env |