Skip to content

Commit 515509b

Browse files
committed
Added Nix documentation to README
1 parent 8b076fc commit 515509b

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ A battery-included library for writing on-chip protocols, such as AMBA AXI and A
2222
- [License](#license)
2323
- [Project goals](#project-goals)
2424
- [Contributing](#contributing)
25+
- [Nix](#nix)
2526
- [TODO](#todo)
2627

2728
# Introduction
@@ -613,6 +614,59 @@ This project does not aim to:
613614
# Contributing
614615
No formal guidelines yet, but feel free to open a PR!
615616

617+
# Nix
618+
This project exposes several Nix flake outputs. Most notibly the `clash-protocols` and `clash-protocols-base` packages themselves. These packages are exposed individually, or as an overlay (which you need to apply on top of clash-compiler).
619+
620+
Contributing to `clash-protocols` can be done via the developer shell exposed by the Nix flake. Open a terminal and typing: `nix develop`. Optionally a specific GHC version can be selected as well as a `-minimal` or `-full` version. The `-minimal` shell does **NOT** contain the Haskell Language Server, whilst the `-full` shell does. When using the developer shell, do not forget to remove the `cabal.project` file. This file contains a package source and Cabal prioritizes local package sources over Nix sources. Removing the `cabal.project` file should work fine when developing with Nix.
621+
622+
You can also add this project as a Nix-dependency. This project depends on `clash-compiler`, the recommended way to add this to your project as a Nix dependency is as follows:
623+
624+
First add `clash-compiler` and `clash-protocols` to your flake inputs:
625+
```nix
626+
inputs = {
627+
clash-compiler.url = "github:clash-lang/clash-compiler"
628+
clash-protocols = {
629+
url = "github:clash-lang/clash-protocols"
630+
inputs.clash-compiler.follows = "clash-compiler";
631+
};
632+
};
633+
```
634+
635+
It is important to have clash-protocols follow the same clash-compiler version as your project, this ensures you do not get different Haskell package hashes. Afterwards, use the `clashPackages` as a baseline for your Haskell packages and overlay this project's overlay ontop of it:
636+
637+
```nix
638+
let
639+
# The GHC version you would like to use
640+
# This has to be be one of the supported versions of clash-compiler
641+
clash-compiler = "ghc9101";
642+
643+
# Import the normal and Haskell package set from clash-protocols
644+
pkgs = (import clash-compiler.inputs.nixpkgs {
645+
inherit system;
646+
}).extend clash-compiler.overlays.${compiler-version};
647+
clash-pkgs = pkgs."clashPackages-${compiler-version}";
648+
649+
# Define your Haskell package
650+
overlay = final: prev: {
651+
# Your haskell package here
652+
my-package = prev.developPackage {
653+
root = ./my-source;
654+
overrides = _: _: final;
655+
};
656+
}
657+
# Make sure to include the clash-protocols overlay!
658+
# This is what brings the clash-compiler packages into scope
659+
// clash-protocols.overlays.${system}.default final prev;
660+
661+
hs-pkgs = clash-pkgs.extend overlay;
662+
in
663+
{
664+
# .. your outputs
665+
}
666+
```
667+
668+
And that's it!
669+
616670
# TODO
617671

618672
0.1

0 commit comments

Comments
 (0)