Skip to content

Instantly share code, notes, and snippets.

@jordaniza
Last active April 14, 2025 15:03
Show Gist options
  • Save jordaniza/f5a66af196f35bbcd6f3570bde0a7003 to your computer and use it in GitHub Desktop.
Save jordaniza/f5a66af196f35bbcd6f3570bde0a7003 to your computer and use it in GitHub Desktop.
FHS Shell env for running rzup and cargo-risczero
{
description = "Dev shell with rzup and RISC Zero FHS compatibility";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
rzupStartup = pkgs.writeShellScript "start-rzup-env" ''
export HOME=$PWD/.risc0
export RZUP_HOME=$HOME
export PATH=$RZUP_HOME/bin:$PATH
export RUSTUP_HOME=$PWD/.rustup
export CARGO_HOME=$PWD/.cargo
echo "rzup-env ready. rzup path: $RZUP_HOME/bin"
if [ ! -x "$RZUP_HOME/bin/rzup" ]; then
echo "rzup not found. Do you want to install it? (y/n)"
read -r answer
if [ "$answer" = "y" ]; then
echo "Installing rzup to $HOME..."
mkdir -p "$RZUP_HOME/bin"
export HOME="$RZUP_HOME"
curl -fsSL https://risc0.com/install | bash
else
echo "⚠️ Skipping rzup installation"
fi
fi
exec ${pkgs.zsh}/bin/zsh -l
'';
# FHS user environment
rzup-fhs = pkgs.buildFHSUserEnv {
name = "rzup-env";
targetPkgs = pkgs: [
pkgs.glibc
pkgs.bash
pkgs.coreutils
pkgs.curl
pkgs.findutils
pkgs.rustup
pkgs.openssl
pkgs.pkg-config
pkgs.zsh
];
runScript = rzupStartup;
};
in {
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
rustup
curl
bash
zsh
rzup-fhs
];
shellHook = ''
export RUSTUP_HOME=$PWD/.rustup
export CARGO_HOME=$PWD/.cargo
export PATH=$CARGO_HOME/bin:$PATH
export RZUP_HOME=$PWD/.risc0
export PATH=$RZUP_HOME/bin:$PATH
export PATH=${rzup-fhs}/bin:$PATH
export OPENSSL_DIR="${pkgs.openssl.dev}"
export OPENSSL_LIB_DIR="${pkgs.openssl.out}/lib"
export OPENSSL_INCLUDE_DIR="${pkgs.openssl.dev}/include"
export PKG_CONFIG_PATH="${pkgs.openssl.dev}/lib/pkgconfig"
echo "rzup path enabled: $RZUP_HOME/bin"
echo "run 'rzup-env' for a full FHS shell with rzup + RISC Zero support"
exec ${pkgs.zsh}/bin/zsh -l
'';
};
# Optional: expose the FHS shell as an app (CLI-style)
apps.${system}.rzup = {
type = "app";
program = "${rzup-fhs}/bin/rzup-env";
};
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment