Plutus Development Setup on macOS

  • Plutus
  • Cardano
  • Nix
  • macOS

Prerequisites

  • macOS (11.2 Big Sur)
  • Terminal

Install Nix

Download and Install

1sh <(curl -L https://nixos.org/nix/install) --no-daemon

This will install Nix into the /nix folder.

Check it is properly installed by running

1nix --version

Configuration

In order to allow Nix to download binary packages for Plutus, provided by IOHK (IOG), you'll need to add the servers from which they can be downloaded to the /etc/nix/nix.conf config file.

Open /etc/nix/nix.conf using an editor of your choice, e.g.

1vim /etc/nix/nix.conf

and add the two lines below

1substituters = https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/
2trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

Note: Do not configure the sandbox feature here, it tends to break the setup.

You may need to restart your computer at this point.

Download Plutus Code

Download the Plutus code from GitHub and build Plutus Core.

1git clone https://github.com/input-output-hk/plutus.git
2cd plutus/
3nix build -f default.nix plutus.haskell.packages.plutus-core.components.library

Troubleshooting

This should work. However, some people experienced errors complaining about a missing /usr/lib/libSystem.B.dylib. In such a case, first make sure you do not have the sandbox enabled in /etc/nix/nix.conf. If that's already the case, try to upgrade nixpkgs to a newer (albeit unstable) version by running

1sudo nix-channel --add https://nixos.org/channels/nixpkgs-unstable unstable

Build Plutus Playground

1nix-build -A plutus-playground.client
2nix-build -A plutus-playground.server
3nix-build -A plutus-playground.generate-purescript
4nix-build -A plutus-playground.start-backend
5nix-build -A plutus-pab

Build and run playground server

1nix-shell
2cd plutus-pab/
3plutus-pab-generate-purs
4
5cd ../plutus-playground-server
6plutus-playground-generate-purs
7plutus-playground-server

In a new terminal start the playground client

1cd plutus/
2nix-shell
3cd plutus-playground-client
4npm run start

Development Workflow

Now, whenever you want to work on Plutus projects, you need to head into the plutus/ folder and enter the nix-shell

1cd plutus/
2nix-shell

For the Plutus Pioneer Program, you'd then

1cd ../plutus-pioneer-program/
2cabal build

Resources

1️⃣ Plutus on GitHub

2️⃣ Plutus Pioneer Program on GitHub

3️⃣ Plutus Community Docs

4️⃣ Plutus Pioneer Programm - Lecture #1

5️⃣ Plutus Setup Instructions by lsmor