Plutarch dev environment for EMURGO CSA
- If you're setting up Nix on your system for the first time, try Determinate Systems' Zero-to-Nix in lieu of the official installer, as it provides an easier tool for installing and uninstalling Nix.
- Alternatively, you may follow the instructions for multi-user installation for your OS at nixos.org. This approach will require some additional configuration and it will be harder to uninstall Nix should you need to. It is only recommended if you've previously installed Nix on your system, as it will detect and repair a previous installation as needed.
- When you are finished installing Nix, close the terminal session and open a fresh one.
-
Edit
/etc/nix/nix.conf
: this requires root access to edit. Use a terminal-based editor likenano
(i.e.):sudo nano /etc/nix/nix.conf
Note: if no configuration file exists at
/etc/nix/nix.conf
it's possible the file is located elsewhere, depending on your OS. Runfind / -name "nix.conf" 2>/dev/null
to find the location of the file (this may take several minutes). -
Modify the file following the instructions below:
# Sample /etc/nix/nix.conf # Step 2a: Add this line to enable required features if missing (if you used the Zero-to-Nix installer this should already be added) experimental-features = nix-command flakes ca-derivations # Step 2b: Add your username to trusted-users (also include 'root' to prevent overriding default setting) trusted-users = root your-username # Step 2c: Avoid unwanted garbage collection with nix-direnv keep-outputs = true
-
🚨 IMPORTANT! You must restart the
nix-daemon
to apply the changesLinux:
sudo systemctl restart nix-daemon
MacOS:
sudo launchctl stop org.nixos.nix-daemon sudo launchctl start org.nixos.nix-daemon
- This repository is designed to work with the
direnv
utility to provide convenient automatic loading of the Nix development environment via the.envrc
file. - The
.envrc
file also configures environment variables to buildcabal
outputs in a local directory (.cabal
) and generates a symlink to the environment's installation of Haskell Language Server (HLS), mitigating potential conflicts with system-wide Haskell tooling in VS Code/Codium. - While the environment can be loaded manually without
direnv
(usingnix develop --accept-flake-config
), it is recommended to install and usedirenv
for best experience. - You can install
direnv
using Nix with the commandnix profile install nixpkgs#direnv
. This is the recommended method, as versions ofdirenv
provided by other package managers (likeapt
on Linux) may be outdated and not support usage withnix-direnv
. Alternative installation methods are explained here. - After installation,
direnv
must be "hooked" into your preferred terminal shell by adding a snippet to the shell configuration file(s).- For Linux users using
bash
, the following snippet should be added to the bottom of your~/.bashrc
file:eval "$(direnv hook bash)"
- For MacOS users using
zsh
, the following snippet should be added to the bottom of your~/.zprofile
and~/.zshrc
files:eval "$(direnv hook zsh)"
- Instructions for alternative shells are provided here.
- For Linux users using
- After completing installation and hooking
direnv
into your preferred terminal shell, open a new terminal session, enter the project directory and rundirenv allow
to allowdirenv
to load the.envrc
file.
- After entering the project directory in your terminal session and allowing the environment to load via
direnv
(or runnix develop --accept-flake-config
if not usingdirenv
), runcabal user-config init; cabal update; cabal build
to updatecabal
and build the Haskell (Plutarch) project. - You can use
cabal run
to run the project's executable (inapp/Main.hs
) and serialize the sample contracts to thecompiled
directory.
- The Nix environment for this project includes a preconfigured instance of VS Codium, which is set up to work out of the box with several preinstalled extensions for completing CSA coursework.
- The bundled editor can only be used with setups that allow the use of GUI applications (this excludes WSL/WSL2 and remote setups that connect via SSH). If needed, your system-wide installation of VS Code/Codium can be used instead, but may require additional configuration. When you launch VS Code/Codium and open the project folder for the first time, you should receive a popup prompt to install some recommended extensions.
- To use the bundled editor, after entering the project directory in your terminal session and allowing the environment to load via
direnv
(or runnix develop --accept-flake-config
if not usingdirenv
), runcodium .
to launch the bundled VS Codium instance.