This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
141 lines (124 loc) · 3.73 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{
description = "A build system for Yosys and Amaranth, and a framework for building projects with them";
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-23.11;
flake-utils.url = github:numtide/flake-utils;
amaranth = {
url = github:amaranth-lang/amaranth;
flake = false;
};
amaranth-boards = {
url = github:amaranth-lang/amaranth-boards;
flake = false;
};
amaranth-stdio = {
url = github:amaranth-lang/amaranth-stdio;
flake = false;
};
yosys = {
url = github:YosysHQ/yosys;
flake = false;
};
abc = {
url = github:YosysHQ/abc?rev=03da96f12fb4deb153cc0dc73936df346ecd4bcf;
flake = false;
};
};
outputs = inputs @ {
self,
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
inherit (pkgs) lib;
python = pkgs.python311;
hdxSetupHook =
pkgs.makeSetupHook {
name = "hdx-setup-hook.sh";
propagatedBuildInputs = [
python.pkgs.pip
python.pkgs.editables
];
substitutions = {
pythonInterpreter = python.interpreter;
pythonSitePackages = python.sitePackages;
};
passthru.provides.setupHook = true;
}
./hdx-setup-hook.sh;
callPackage = pkgs.lib.callPackageWith env;
env =
pkgs
// {
inherit python;
hdxInputs = inputs;
inherit hdxSetupHook;
amaranth = callPackage ./pkgs/amaranth.nix {};
amaranth-boards = callPackage ./pkgs/amaranth-boards.nix {};
amaranth-stdio = callPackage ./pkgs/amaranth-stdio.nix {};
yosys = callPackage ./pkgs/yosys.nix {};
abc = callPackage ./pkgs/abc.nix {};
hdx = callPackage ./pkgs/hdx.nix {};
rainhdx = callPackage ./rainhdx {};
};
in {
packages.default = env.hdx;
packages.rainhdx = env.rainhdx;
formatter = pkgs.alejandra;
devShells = rec {
default = env.hdx;
amaranth = env.amaranth.overridePythonAttrs (prev: {
name = "hdx-amaranth";
src = null;
nativeBuildInputs =
prev.nativeBuildInputs
++ lib.remove env.amaranth env.hdx.propagatedBuildInputs
++ [hdxSetupHook];
preShellHook = builtins.readFile ./amaranth-shell-hook.sh;
postShellHook = ''
# Start shell back where we came from.
cd $HDX_START
'';
doCheck = false;
});
amaranth-yosys = amaranth.overridePythonAttrs (prev: {
name = "hdx-amaranth+yosys";
nativeBuildInputs =
lib.remove env.yosys prev.nativeBuildInputs
++ env.yosys.nativeBuildInputs
++ [
(
if pkgs.stdenv.isDarwin
then pkgs.lldb
else pkgs.gdb
)
pkgs.verilog
];
buildInputs =
lib.remove env.yosys prev.buildInputs
++ env.yosys.buildInputs;
preShellHook =
lib.replaceStrings ["@Makefile.conf.hdx@"] [
(env.yosys.overrideAttrs {
makefileConfPrefix = "$(HDX_OUT)";
extraMakefileConf = ''
ENABLE_DEBUG=1
STRIP=echo hdx: Not doing this: strip
'';
})
.makefileConf
]
(builtins.readFile
./amaranth-yosys-shell-hook.sh);
});
};
})
// {
templates.rainhdx = {
path = ./rainhdx/template;
description = "A minimal FPGA project using Amaranth";
};
};
}