-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
233 lines (226 loc) · 8.42 KB
/
Copy pathflake.nix
File metadata and controls
233 lines (226 loc) · 8.42 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
{
description = "Nix files made to ease imperative installation of Xilinx tools";
# https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix
inputs.flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
outputs =
{
self,
nixpkgs,
flake-compat,
}:
let
# We don't use flake-utils.lib.eachDefaultSystem since only x86_64-linux is
# supported
pkgs = nixpkgs.legacyPackages.x86_64-linux;
targetPkgs = import ./common.nix;
runScriptPrefix =
{
errorOut ? true,
}:
''
# Search for an imperative declaration of the installation directory of xilinx
if [[ -f ~/.config/xilinx/nix.sh ]]; then
source ~/.config/xilinx/nix.sh
''
+ pkgs.lib.optionalString errorOut ''
else
echo "nix-xilinx: error: Did not find ~/.config/xilinx/nix.sh" >&2
exit 1
fi
if [[ ! -d "$INSTALL_DIR" ]]; then
echo "nix-xilinx: error: INSTALL_DIR $INSTALL_DIR isn't a directory" >&2
exit 2
''
+ ''
fi
'';
# Might be useful for usage of this flake in another flake with devShell +
# direnv setup. See:
# https://gitlab.com/doronbehar/nix-matlab/-/merge_requests/1#note_631741222
shellHooksCommon = (runScriptPrefix { }) + ''
# Rename the variables for others to extend it in their shellHook
export XILINX_INSTALL_DIR="$INSTALL_DIR"
unset INSTALL_DIR
export XILINX_VERSION=$VERSION
unset VERSION
'';
# Used in many packages
metaCommon = with pkgs.lib; {
# This license is not of Xilinx' tools, but for this repository
license = licenses.mit;
# Probably best to install this completely imperatively on a system other
# then NixOS.
platforms = platforms.linux;
};
createXilinxPkg =
{ product, meta }:
let
name = pkgs.lib.strings.toLower product;
fhsEnv = pkgs.buildFHSEnv {
inherit name targetPkgs meta;
runScript = pkgs.writeScript "xilinx-${product}-runner" (
(runScriptPrefix { })
+ ''
export LD_LIBRARY_PATH=/lib:$LD_LIBRARY_PATH
export GDK_BACKEND=x11
export DISPLAY="''${DISPLAY:-:0}"
export _JAVA_AWT_WM_NONREPARENTING=1
export ELECTRON_OZONE_PLATFORM_HINT=x11
_xil_tmpdir=$(mktemp -d -t xilinx-node-XXXXXX)
printf '#!/bin/sh\nexport LD_LIBRARY_PATH=/lib64:$LD_LIBRARY_PATH\nexec /usr/bin/node "$@"\n' \
> "$_xil_tmpdir/node"
chmod +x "$_xil_tmpdir/node"
export PATH="$_xil_tmpdir:$PATH"
if [[ -d $INSTALL_DIR/$VERSION/${product} ]]; then
exec $INSTALL_DIR/$VERSION/${product}/bin/${name} "$@"
else
echo It seems ${product} isn\'t installed because '$INSTALL_DIR/$VERSION/${product}' doesn\'t exist. Follow >&2
echo the instructions in the README of nix-xilinx and make sure ${product} is selected during the >&2
echo installation wizard. If it\'s supposed to be installed, check that your \~/.config/xilinx/nix.sh >&2
echo have a correct '$VERSION' variable set in it - check that the '$VERSION' directory actually exists. >&2
exit 1
fi
''
);
};
desktopItem = pkgs.makeDesktopItem {
desktopName = product;
inherit name;
exec = "${fhsEnv}/bin/${name}";
icon = name;
categories = [
"Utility"
"Development"
"IDE"
];
};
iconPkgs =
{
vivado = [
(pkgs.runCommand "${name}-icon" { } ''
install -Dm644 ${./icons/vivado.png} $out/share/icons/hicolor/256x256/apps/${name}.png
'')
];
vitis_hls = [
(pkgs.runCommand "${name}-icon" { } ''
install -Dm644 ${./icons/vitis_hls.png} $out/share/icons/hicolor/256x256/apps/${name}.png
'')
];
vitis = [ ];
model_composer = [
(pkgs.runCommand "${name}-icon" { } ''
install -Dm644 ${./icons/matlab.png} $out/share/icons/hicolor/256x256/apps/${name}.png
'')
];
}
.${name};
in
pkgs.symlinkJoin {
inherit name meta;
paths = [
fhsEnv
desktopItem
]
++ iconPkgs;
};
in
{
packages.x86_64-linux.xilinx-shell = pkgs.buildFHSEnv {
name = "xilinx-shell";
inherit targetPkgs;
runScript = pkgs.writeScript "xilinx-shell-runner" (
(runScriptPrefix {
# If the user hasn't setup a ~/.config/xilinx/nix.sh file yet, don't
# yell at them that it's missing
errorOut = false;
})
+ ''
cat <<EOF
============================
welcome to nix-xilinx shell!
To install vivado or vitis:
${nixpkgs.lib.strings.escape [ "`" "'" "\"" "$" ] (builtins.readFile ./install.adoc)}
4. Finish the installation, and exit the shell (with \`exit\`).
5. Follow the rest of the instructions in the README to make xilinx
executable available anywhere on your system.
============================
EOF
LD_LIBRARY_PATH=/lib:$LD_LIBRARY_PATH exec bash
''
);
meta = metaCommon // {
homepage = "https://gitlab.com/doronbehar/nix-xilinx";
description = "A bash shell from which you can install xilinx tools or launch them from CLI";
};
};
packages.x86_64-linux.vivado = createXilinxPkg {
product = "Vivado";
meta = metaCommon // {
homepage = "https://www.xilinx.com/products/design-tools/vivado.html";
description = "Software suite for synthesis and analysis of (HDL) designs";
};
};
packages.x86_64-linux.vitis = createXilinxPkg {
product = "Vitis";
meta = metaCommon // {
homepage = "https://www.xilinx.com/products/design-tools/vitis.html";
description = "A comprehensive development environment";
};
};
packages.x86_64-linux.vitis_hls = createXilinxPkg {
product = "Vitis_HLS";
meta = metaCommon // {
homepage = "https://xilinx.github.io/Vitis-Tutorials/2020-2/docs/Getting_Started/Vitis_HLS/README.html";
description = "High-Level Synthesis from C, C++ and OpenCL";
};
};
packages.x86_64-linux.model_composer = createXilinxPkg {
product = "Model_Composer";
meta = metaCommon // {
homepage = "https://www.xilinx.com/products/design-tools/vitis/vitis-model-composer.html";
description = "A Xilinx toolbox for MATLAB and Simulink for DSP Design";
};
};
packages.x86_64-linux.xsct = pkgs.buildFHSEnv {
name = "xsct";
inherit targetPkgs;
runScript = pkgs.writeScript "xilinx-xsct-runner" (
(runScriptPrefix { })
+ ''
export LD_LIBRARY_PATH=/lib:$LD_LIBRARY_PATH
export XILINX_VIVADO="$INSTALL_DIR/$VERSION/Vivado"
exec "$INSTALL_DIR/$VERSION/Vivado/bin/xsdb" "$@"
''
);
meta = metaCommon // {
description = "Xilinx Software Command-line Tool (xsct/xsdb)";
};
};
overlay = final: prev: {
inherit (self.packages.x86_64-linux)
xilinx-shell
vivado
vitis
vitis_hls
model_composer
xsct
;
};
nixosModules.vivado-server = import ./modules/vivado-server.nix;
inherit shellHooksCommon;
devShell.x86_64-linux = pkgs.mkShell {
buildInputs = (targetPkgs pkgs) ++ [
self.packages.x86_64-linux.xilinx-shell
];
# From some reason using the attribute xilinx-shell directly as the
# devShell doesn't make it run like that by default.
shellHook = ''
exec xilinx-shell
'';
};
defaultPackage.x86_64-linux = self.packages.x86_64-linux.xilinx-shell;
};
}