Guide for installing Plutus playground locally on MacOS Monterey with M1 chip

Hi,

Last week I had trouble installing plutus playground on MacOS Monterey, whereas it was fine when I followed this guide when I’m still on Big Sur. Mac still have compatibility issues recently because they’re still transitioning to their new M1 chip (i.e issues with Nixpkg).
Granted that plutus is highly under development right now, and things always change in their new release and updates.

After 2 days of trial and error last week, I find some workaround that is working on my machine with MacOS Monterey. So I’m here to write a guide that is hopefully will enable any Mac users out there who’s using M1 chip, to be able learn plutus and follow along Plutus Pioneer #2

MacBook Pro 13" M1 (2020)
MacOS Monterey 12.0.1
8 GB RAM
256GB storage

Setting up nix and plutus environment

  1. Install nix NixOS - Getting Nix / NixOS
    curl -L https://nixos.org/nix/install | sh
  2. Edit /etc/nix/nix.conf file and add this line from IOHK binary cache
substituters        = https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/
trusted-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=
  1. This is only for M1 user, inside /etc/nix/nix.conf add this line (Reference)
# system = aarch64-darwin
system = x86_64-darwin
extra-platforms = x86_64-darwin aarch64-darwin

Update the env with running this on terminal nix-env -iA nixpkgs.nix

  1. Restart computer (THIS IS IMPORTANT, in order for nix to restart their daemon tools, and source the nix.conf file)
  2. Open terminal and clone plutus repo
    git clone https://github.com/input-output-hk/plutus.git
  3. Inside plutus directory, switch to commit
    git checkout 34aa9c323ed6da68a11f41d41d5aca9f469aaf4b
  4. In the same directory (plutus root folder), build the Plutus Core library
    nix build -f default.nix plutus.haskell.packages.plutus-core.components.library
  5. Build the dependencies for Plutus server and client (Reference, step 10 and 11)
  • Build the Plutus Playground Client / Server
nix-build -A plutus-playground.client
nix-build -A plutus-playground.server
  • Build other plutus dependencies
nix-build -A plutus-playground.generate-purescript
nix-build -A plutus-playground.start-backend
nix-build -A plutus-pab
  1. Run nix-shell in this current folder. It will took quite a while the first time running nix-shell
  2. If bash error arise
  3. If any error arises, refer to this guide
  4. Done

Workflow for following weekly course from Plutus Pioneer Program:

Plutus Pioneer Program - Iteration #2

General idea:

  1. Only run nix-shell within 34aa9c323ed6da68a11f41d41d5aca9f469aaf4b commit, other commit will result in unexpected error or long GHC build for some reason (i.e when running nix-shell with ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4)
  2. Set up 3 terminals at the start, and run nix-shell in each of them
  3. After we’re inside nix-shell, we can navigate freely to different commit of each week
  4. Before running plutus-playground-server and npm run start inside nix-shell and plutus/plutus-playground-client/ folder, you must run cabal update and cabal build inside each corresponding week
  5. If you want to move on to week02 for example, then you have to switch plutus/ repo to commit hash specified inside cabal.project (tag), after that run cabal update and cabal build inside …/plutus-pioneer-program/src/week02/ directory
  6. Do this every time you’re switching week, no need to get out of nix-shell.
  7. Next time you wanted to get into nix-shell again, make sure to follow again from step 1

Detailed guide (Read the general idea to fully understand the workflow)

  1. Clone plutus-pioneer-program outside of plutus folder
    git clone https://github.com/input-output-hk/plutus-pioneer-program.git
  2. Change directory into plutus, switch to this commit
    git checkout 34aa9c323ed6da68a11f41d41d5aca9f469aaf4b
  3. Run nix-shell
  4. Open 2 other terminal and run nix-shell in each of them (** Terminal 1 and terminal 2 will be used for running server and client instances, while terminal 3 will be used for navigating inside plutus-pioneer-program folder **)
  5. In terminal 3, while inside nix-shell, navigate to …/plutus-pioneer-program/code/week01
  6. open cabal.project, and look for tag, copy the commit hash
  7. In terminal 1, git checkout ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4
  8. In terminal 3, while still in /week01 folder, run cabal update, then cabal build. It will take quite a while
  9. In terminal 1 and terminal 2, change directory to plutus/plutus-playground-client/
  10. In terminal 1, run plutus-playground-server
  11. In terminal 2, run npm run start
  12. If some error happen in terminal 2, try it again. Sometimes it’s working the second time for me
  13. Open your browser, and enter to localhost:8009
  14. Playground should be able to run locally
4 Likes

Thank you for the effort :pray:

No problem! Happy to contribute to the community

Thanks for sharing! I also encountered an issue where group nixbld doesn’t have any user, resulting the following error:

the build users group 'nixbld' has no members

I had to manually add all nixbld users to nixbld group manually with this command to solve this problem:

# This is based on the fact that I have 32 nixbld users (_nixbld1, _nixbld2, ... _nixbld32) created.
# You could see all nix builders with command: dscl . list /users |grep -i nix
for i in {1..32}; do sudo dscl . append /Groups/nixbld GroupMembership _nixbld$i; done
1 Like

If you need to reinstall nix, this is the step for uninstalling it on Mac:

  1. Run installation command for nix curl -L https://nixos.org/nix/install | sh
  2. It will then prompt to uninstall nix on your system. Follow the guide specified on terminal
  3. The /nix will face with an error, resource busy
  4. Restart computer
  5. Open Disk Utility, then erase /nix volume
  6. Delete /nix volume
  7. Restart computer

How do you know which branch use? I mean from where do you know do you need to switch to git checkout 34aa9c323ed6da68a11f41d41d5aca9f469aaf4b

I got it from here, in the Troubleshooting section at the bottom. I found that it’s the commit that would work in M1 MacOS Monterey, and decided to go with it and use it instead of using the updated master branch