-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
191 lines (176 loc) · 7.43 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
{
description = "Open RTL synthesis framework and tools";
nixConfig.bash-prompt = "[nix(openXC7)] ";
# Nixpkgs / NixOS version to use.
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils, ... }:
let
# to work with older version of flakes
lastModifiedDate =
self.lastModifiedDate or self.lastModified or "19700101";
# Generate a user-friendly version number.
version = builtins.substring 0 8 lastModifiedDate;
# System types to support.
supportedSystems =
[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in {
# Provide some binary packages for selected system types.
packages = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
inherit (pkgs) lib callPackage stdenv fetchgit fetchFromGitHub;
in rec {
nextpnr-xilinx = callPackage ./nix/nextpnr-xilinx.nix { };
prjxray = callPackage ./nix/prjxray.nix { };
fasm = with pkgs;
with python3Packages;
callPackage ./nix/fasm {
# NOTE(jleightcap): calling this package here is clucky.
# contorted structure here to make the `nix/fasm` directory be
# drop-in to upstream python-modules in nixpkgs.
inherit buildPythonPackage pythonOlder textx cython fetchpatch;
};
nextpnr-xilinx-chipdb = {
artix7 = callPackage ./nix/nextpnr-xilinx-chipdb.nix {
backend = "artix7";
nixpkgs = pkgs;
inherit nextpnr-xilinx;
inherit prjxray;
};
kintex7 = callPackage ./nix/nextpnr-xilinx-chipdb.nix {
backend = "kintex7";
nixpkgs = pkgs;
inherit nextpnr-xilinx;
inherit prjxray;
};
spartan7 = callPackage ./nix/nextpnr-xilinx-chipdb.nix {
backend = "spartan7";
nixpkgs = pkgs;
inherit nextpnr-xilinx;
inherit prjxray;
} ;
zynq7 = callPackage ./nix/nextpnr-xilinx-chipdb.nix {
backend = "zynq7";
nixpkgs = pkgs;
inherit nextpnr-xilinx;
inherit prjxray;
};
};
# disable yosys-synlig for now: synlig is not very good and it does not compile with recent yosys
# yosys-synlig = callPackage ./nix/yosys-synlig.nix { };
});
# contains a mutually consistent set of packages for a full toolchain using nextpnr-xilinx.
devShell = forAllSystems (system:
nixpkgsFor.${system}.mkShell {
buildInputs = (with self.packages.${system}; [
fasm
prjxray
nextpnr-xilinx
# disabled, see above
# yosys-synlig
]) ++ (with nixpkgsFor.${system}; [
yosys
ghdl
yosys-ghdl
openfpgaloader
pypy310
python312Packages.pyyaml
python312Packages.textx
python312Packages.simplejson
python312Packages.intervaltree
]);
shellHook =
let mypkgs = self.packages.${system};
nixpkgs = nixpkgsFor.${system};
pyPkgPath = "/lib/python3.12/site-packages/:";
in nixpkgs.lib.concatStrings [
"export NEXTPNR_XILINX_DIR=" mypkgs.nextpnr-xilinx.outPath "\n"
"export NEXTPNR_XILINX_PYTHON_DIR=" mypkgs.nextpnr-xilinx.outPath "/share/nextpnr/python/\n"
"export PRJXRAY_DB_DIR=" mypkgs.nextpnr-xilinx.outPath "/share/nextpnr/external/prjxray-db\n"
"export PRJXRAY_PYTHON_DIR=" mypkgs.prjxray.outPath "/usr/share/python3/\n"
''export PYTHONPATH=''$PYTHONPATH:''$PRJXRAY_PYTHON_DIR:''
mypkgs.fasm.outPath pyPkgPath
nixpkgs.python312Packages.textx.outPath pyPkgPath
nixpkgs.python312Packages.arpeggio.outPath pyPkgPath
nixpkgs.python312Packages.pyyaml.outPath pyPkgPath
nixpkgs.python312Packages.simplejson.outPath pyPkgPath
nixpkgs.python312Packages.intervaltree.outPath pyPkgPath
nixpkgs.python312Packages.sortedcontainers.outPath pyPkgPath
"\n"
"export PYPY3=" nixpkgs.pypy310.outPath "/bin/pypy3.10"
];
}
);
dockerImage = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
mypkgs = self.packages.${system};
chipdb = mypkgs.nextpnr-xilinx-chipdb;
pyPkgPath = "/lib/python3.10/site-packages/:";
in
pkgs.dockerTools.buildImage {
name = "openxc7-docker";
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = self.devShell.${system}.buildInputs ++ (with pkgs; [
bashInteractive
findutils
gnused
gnugrep
coreutils
gnumake
python312
]) ++ (with chipdb; [
spartan7
artix7
kintex7
zynq7
]);
pathsToLink = [ "/bin" ] ++ (with pkgs.dockerTools; [
usrBinEnv
binSh
]);
};
runAsRoot = pkgs.lib.concatStrings [ ''
#!${pkgs.runtimeShell}
mkdir -p /work
cat > /bin/devshell <<EOF
#!${pkgs.runtimeShell}
'' self.devShell.${system}.shellHook "\n"
"export NEXTPNR_XILINX_PYTHON_DIR=" mypkgs.nextpnr-xilinx.outPath "/share/nextpnr/python/\n"
"export PRJXRAY_DB_DIR=" mypkgs.nextpnr-xilinx.outPath "/share/nextpnr/external/prjxray-db\n"
"export PRJXRAY_PYTHON_DIR=" mypkgs.prjxray.outPath "/usr/share/python3/\n"
''export PYTHONPATH=\''$PYTHONPATH:\''$PRJXRAY_PYTHON_DIR:''
pkgs.python312Packages.textx.outPath pyPkgPath
pkgs.python312Packages.pyyaml.outPath pyPkgPath
pkgs.python312Packages.simplejson.outPath pyPkgPath
pkgs.python312Packages.intervaltree.outPath pyPkgPath
pkgs.python312Packages.arpeggio.outPath pyPkgPath
pkgs.python312Packages.setuptools.outPath pyPkgPath
pkgs.python312Packages.future.outPath pyPkgPath
pkgs.python312Packages.sortedcontainers.outPath pyPkgPath
mypkgs.fasm.outPath "/lib/python3.12/site-packages/"
"\n"
"export NEXTPNR_XILINX_DIR=" mypkgs.nextpnr-xilinx.outPath "\n"
"export SPARTAN7_CHIPDB=" chipdb.spartan7.outPath "\n"
"export ARTIX7_CHIPDB=" chipdb.artix7.outPath "\n"
"export KINTEX7_CHIPDB=" chipdb.kintex7.outPath "\n"
"export ZYNQ7_CHIPDB=" chipdb.zynq7.outPath "\n"
"\nexec ${pkgs.bashInteractive}/bin/bash\n"
''EOF
chmod 755 /bin/devshell
''];
config = {
Cmd = [ "/bin/devshell" ];
WorkingDir = "/work";
Volumes = { "/work" = { }; };
};
}
);
};
}