The Problem
GHDL is a popular VHDL simulator. Currently, I am taking an FPGA course and I need to use either 100 GB Vivado or tiny GHDL. I use an M1 MacBook Air as my daily driver. It is not x86_64 . . . . it is ARM. It’s also running NixOS instead of the more common Fedora Remix. Because of this you might assume I can use the ghdl that is packaged in the Nix repos. Wrong! Arm is not currently supported :)
Solution
Of course I can go to the github repo, clone it, and build it myself. But that is not the Nix way. Imperative bad. So I’ve crafted a Flake that will solve this issue. The problem with the current build of GHDL on the Nix repos is that it is using gnat13. We can solve this issue by making a derivation that will build with an updated version. Problem Solved
1{
2 description = "Flake to build GHDL from upstream source with gnat-bootstrap14";
3
4 inputs = {
5 nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6 ghdl-src = {
7 url = "github:ghdl/ghdl";
8 flake = false;
9 };
10 };
11
12 outputs =
13 {
14 self,
15 nixpkgs,
16 ghdl-src,
17 }:
18 let
19 systems = [
20 "aarch64-linux"
21 ];
22 forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f (import nixpkgs { inherit system; }));
23 in
24 {
25 packages = forAllSystems (pkgs: {
26 default = pkgs.stdenv.mkDerivation {
27 pname = "ghdl";
28 version = "git";
29
30 src = ghdl-src;
31
32 nativeBuildInputs = with pkgs; [
33 git
34 cmake
35 gcc
36 llvm
37 wget
38 gnumake
39 automake
40 zlib
41 gnat-bootstrap14
42 python3
43 ];
44
45 configurePhase = ''
46 export GHDL_BACKEND=llvm
47 export CC=${pkgs.gcc}/bin/gcc
48 export CXX=${pkgs.gcc}/bin/g++
49
50 ./configure --prefix=$out --with-llvm-config --enable-libghdl
51
52 '';
53
54 buildPhase = ''
55 make
56 '';
57
58 installPhase = ''
59 make install
60 '';
61 };
62 });
63 };
64}
This is my current flake. If you would like to add just the package to your own flake, see below
Example for User flake
1
2{
3 description = "Flake to build GHDL from upstream source with gnat-bootstrap14";
4
5 inputs = {
6 nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
7 ghdl = {
8 url = "github:Sheepheerd/nix-ghdl";
9 };
10
11 };
12
13 outputs =
14 {
15 self,
16 nixpkgs,
17 ghdl,
18 }:
19 let
20 systems = [
21 "aarch64-linux"
22 "aarch64-darwin"
23 ]; # adjust if needed
24 forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f (import nixpkgs { inherit system; }));
25 in
26 {
27 devShells = forAllSystems (pkgs: {
28 default = pkgs.mkShell {
29 buildInputs = with pkgs; [
30 ghdl.packages.${pkgs.system}.default
31 pkgs.gtkwave
32 ];
33 };
34 });
35 };
36}