Skip to content

wimsio/plutus-nix

🧠 Plutus Smart Contracts Setup Guide with Nix & Cabal

placeholder **Pheidippides β€” rapid Plutus Application Development (rPAD)**

Aim: To promote rapid, easy learning, simplification, and development on Cardano. Just like a Greek messenger Pheidippides, who ran to deliver good news of victory, rPAD aims to quickly deliver quick dApps to Cardano communities.

Welcome to the Plutus development onboarding guide! This document walks you through:

  • Installing Nix (with flakes + nix-command) on Ubuntu, Fedora, Arch, Windows WSL2, and Windows native
  • Entering a reproducible dev shell
  • Building with Cabal
  • Understanding the Vesting contracts and utilities

πŸ“‚ NOTE: Detailed tutorials live in /code/wspace/lecture.


πŸ“š Table of Contents

  1. 🧰 Prerequisites

  2. βš™οΈ Environment Setup (Nix + Flakes)

  3. πŸ“¦ Building the Project

  4. πŸ“ Folder Structure

  5. πŸ” Understanding the Contracts

  6. πŸ”§ Utilities Breakdown

  7. πŸ§ͺ Testing and Debugging

  8. πŸ“– Glossary of Terms

  9. πŸ“ License and Contributions

From Zero to Hero Haskell Plutus Flake.nix Template

image

image

Coming... Offchain Helios


1. 🧰 Prerequisites

  • Git CLI
  • Nix (we’ll install it below with flakes enabled)
  • Optional: VS Code + Haskell extension

2. βš™οΈ Environment Setup (Nix + Flakes)

Start with # πŸš€ NIX SETUP.md Tutorial (with Problems & Solutions) file in this directory

We recommend multi-user (daemon) installs on Linux and WSL2 for Windows. Flakes are enabled via NIX_CONFIG or /etc/nix/nix.conf.

πŸ”§ Common shell snippet (Linux/WSL)

Add to ~/.bashrc (or ~/.zshrc) to always load Nix and enable flakes:

# Nix profile (added by me)
if [ -e /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]; then
  . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
elif [ -e "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
  . "$HOME/.nix-profile/etc/profile.d/nix.sh"
fi

# Enable Nix experimental features for this shell
export NIX_CONFIG="experimental-features = nix-command flakes"

βœ… System-wide alternative (Linux/WSL): Create /etc/nix/nix.conf (no need for the export above if you do this):

experimental-features = nix-command flakes

2.1 Ubuntu

Install (daemon):

sh <(curl -L https://nixos.org/nix/install) --daemon
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh

Optional system-wide flakes:

sudo mkdir -p /etc/nix
echo 'experimental-features = nix-command flakes' | sudo tee /etc/nix/nix.conf

2.2 Fedora

SELinux is enabled by default. If the daemon won’t start, check journalctl -u nix-daemon.

Install (daemon):

sh <(curl -L https://nixos.org/nix/install) --daemon
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
sudo systemctl enable --now nix-daemon

Optional system-wide flakes:

sudo mkdir -p /etc/nix
echo 'experimental-features = nix-command flakes' | sudo tee /etc/nix/nix.conf

2.3 Arch

Install (daemon):

sh <(curl -L https://nixos.org/nix/install) --daemon
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
sudo systemctl enable --now nix-daemon

Optional system-wide flakes:

sudo mkdir -p /etc/nix
echo 'experimental-features = nix-command flakes' | sudo tee /etc/nix/nix.conf

2.4 Windows (WSL2)

Recommended Windows path for Plutus dev.

Enable systemd in WSL (once):

sudo tee /etc/wsl.conf >/dev/null <<'EOF'
[boot]
systemd=true
EOF

Then, in Windows PowerShell:

wsl --shutdown

Reopen Ubuntu (WSL).

Install (daemon) inside WSL:

sh <(curl -L https://nixos.org/nix/install) --daemon
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
sudo systemctl enable --now nix-daemon

Optional system-wide flakes (inside WSL):

sudo mkdir -p /etc/nix
echo 'experimental-features = nix-command flakes' | sudo tee /etc/nix/nix.conf

2.5 Windows (Native)

Native Nix on Windows is evolving. Prefer WSL2 if possible. If you proceed natively, enable flakes via PowerShell:

User-level persistent env:

setx NIX_CONFIG "experimental-features = nix-command flakes"

(Reopen PowerShell.)

Optional profile for immediate effect:

if (!(Test-Path $PROFILE)) { New-Item -Type File -Path $PROFILE -Force | Out-Null }
Add-Content $PROFILE '$env:NIX_CONFIG = "experimental-features = nix-command flakes"'

If you use Git Bash/MSYS, you can add the same Linux snippet to ~/.bashrc and adjust any profile paths installed by the native Nix package.


2.6 Verify Your Setup

nix --version
nix flake --help
nix doctor

On Linux/WSL:

systemctl status nix-daemon

3. πŸ“¦ Building the Project

a) Clone and Enter

git clone <your-repo-url>
cd plutus-nix

b) Enter the Dev Shell (flakes)

nix develop

If not using flakes:

nix-shell

c) Build with Cabal

cabal update
cabal build all

This builds both the Utilities library and the wspace smart contract/test modules.


4. πŸ“ Folder Structure

plutus-nix/
β”œβ”€β”€ .devcontainer/
β”œβ”€β”€ .vscode/
β”œβ”€β”€ code/
β”‚   β”œβ”€β”€ dist-newstyle/
β”‚   β”œβ”€β”€ nix/
β”‚   β”œβ”€β”€ Utilities/
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   └── Utilities/
β”‚   β”‚   β”‚       β”œβ”€β”€ Conversions.hs
β”‚   β”‚   β”‚       β”œβ”€β”€ PlutusTx.hs
β”‚   β”‚   β”‚       β”œβ”€β”€ Serialise.hs
β”‚   β”‚   β”‚       └── Utilities.hs
β”‚   β”‚   β”œβ”€β”€ Utilities.cabal
β”‚   β”‚   └── hie.yaml
β”‚   β”œβ”€β”€ wspace/
β”‚   β”‚   β”œβ”€β”€ assets/
β”‚   β”‚   β”œβ”€β”€ lecture/
β”‚   β”‚   β”‚   β”œβ”€β”€ CGPlutusUtilsv1.hs
β”‚   β”‚   β”‚   β”œβ”€β”€ CGTime.hs
β”‚   β”‚   β”‚   β”œβ”€β”€ ParameterizedVesting.hs
β”‚   β”‚   β”‚   └── Vesting.hs
β”‚   β”‚   β”œβ”€β”€ test/
β”‚   β”‚   β”‚   β”œβ”€β”€ CGPlutusUtilsSpec.hs
β”‚   β”‚   β”‚   β”œβ”€β”€ CGTimeSpec.hs
β”‚   β”‚   β”‚   β”œβ”€β”€ VestingSpec.hs
β”‚   β”‚   β”‚   β”œβ”€β”€ ParameterizedVestingSpec.hs
β”‚   β”‚   β”‚   β”œβ”€β”€ Spec.hs
β”‚   β”‚   β”‚   └── Main.hs
β”‚   β”‚   β”œβ”€β”€ docs/
β”‚   β”‚   β”œβ”€β”€ Tutorials.md
β”‚   β”‚   β”œβ”€β”€ cabal.project
β”‚   β”‚   └── wspace.cabal
β”œβ”€β”€ .gitignore
β”œβ”€β”€ flake.nix
└── README.md

5. πŸ” Understanding the Contracts

5.1 Basic Vesting

  • File: lecture/Vesting.hs

  • Validates that:

    • A transaction is signed by the beneficiary
    • The deadline has been reached

5.2 Parameterized Vesting

  • File: lecture/ParameterizedVesting.hs

  • Accepts:

    • beneficiary :: PubKeyHash
    • deadline :: POSIXTime
  • Uses liftCode to embed these at compile time


6. πŸ”§ Utilities Breakdown

Address Utilities

  • File: lecture/CGPlutusUtilsv1.hs

    • Decode Bech32 β†’ PubKeyHash
    • Encode PubKeyHash β†’ Bech32 (mainnet/testnet)

Time Utilities

  • File: lecture/CGTime.hs

    • POSIX, ISO8601, UTC conversions
    • Time arithmetic: add/diff/getNow

7. πŸ§ͺ Testing and Debugging

Test Entry

main :: IO ()
main = defaultMain tests

Test Files

test/
β”œβ”€β”€ CGPlutusUtilsSpec.hs
β”œβ”€β”€ CGTimeSpec.hs
β”œβ”€β”€ VestingSpec.hs
β”œβ”€β”€ ParameterizedVestingSpec.hs
β”œβ”€β”€ Spec.hs
└── Main.hs

Run tests via:

cabal test all

8. πŸ“– Glossary of Terms

Term Description
POSIXTime Seconds since the Unix epoch
PubKeyHash (PKH) Hash of a wallet's public key
Validator The on-chain logic for validation
ScriptContext Transaction context during validation
liftCode / applyCode Embeds values directly into compiled code
Bech32 Human-readable address format for Cardano
txSignedBy Checks if a transaction is signed by a specific PKH
Utilities Library Helper functions for off-chain dev/test
Cabal / Nix Build and environment tools for Haskell & Plutus

πŸ†• Additional Glossary Terms

Term Description
UTxO Unspent transaction output, Cardano’s accounting model
Datum On-chain data attached to UTxOs
GADT Generalized Algebraic Data Type in Haskell
HRP Human-Readable Part of a Bech32 string

9. πŸ“ License and Contributions

License

MIT License

Copyright (c) 2025 Women In Move Solutions (Pty) Ltd & Coxygen Global (Pty) Ltd
...

Author & Ownership

  • Author: Bernard Sibanda
  • Company: Coxygen Global (Pty) Ltd
  • Date: 27 September, 2025

Who is Bernard Sibanda? (Professional Intro omitted here for brevity; keep your original β€œProfessional Introduction” section beneath this license block as-is.)


πŸ”§ Troubleshooting (Quick)

  • nix flake unknown: Ensure your shell loaded the snippet or /etc/nix/nix.conf has experimental-features = nix-command flakes.

  • Daemon issues (Linux/WSL):

    sudo systemctl status nix-daemon
    journalctl -u nix-daemon -e

    On WSL, confirm /etc/wsl.conf has systemd=true and you ran wsl --shutdown.

  • nix develop not found: You’re not on flakes; either enable flakes or use nix-shell.

  • Cabal can’t find GHC: Enter the Nix dev shell first (nix develop) so toolchains are pinned.


About

Haskell Plutus quick and easy development setup demo

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published