nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 230 lines 7.2 kB view raw
1{ 2 lib, 3 buildFHSEnv, 4 callPackage, 5 makeDesktopItem, 6 runtimeShell, 7 runCommand, 8 unstick, 9 quartus-prime-lite, 10 libfaketime, 11 pkgsi686Linux, 12 withQuesta ? true, 13 supportedDevices ? [ 14 "Arria II" 15 "Cyclone V" 16 "Cyclone IV" 17 "Cyclone 10 LP" 18 "MAX II/V" 19 "MAX 10 FPGA" 20 ], 21 unwrapped ? callPackage ./quartus.nix { inherit unstick supportedDevices withQuesta; }, 22 extraProfile ? "", 23}: 24 25let 26 desktopItem = makeDesktopItem { 27 name = "quartus-prime-lite"; 28 exec = "quartus"; 29 icon = "quartus"; 30 desktopName = "Quartus"; 31 genericName = "Quartus Prime"; 32 categories = [ "Development" ]; 33 }; 34in 35# I think questa_fse/linux/vlm checksums itself, so use FHSUserEnv instead of `patchelf` 36buildFHSEnv rec { 37 pname = "quartus-prime-lite"; # wrapped 38 inherit (unwrapped) version; 39 40 targetPkgs = 41 pkgs: with pkgs; [ 42 (runCommand "ld-lsb-compat" { } ( 43 '' 44 mkdir -p "$out/lib" 45 ln -sr "${glibc}/lib/ld-linux-x86-64.so.2" "$out/lib/ld-lsb-x86-64.so.3" 46 '' 47 + lib.optionalString withQuesta '' 48 ln -sr "${pkgsi686Linux.glibc}/lib/ld-linux.so.2" "$out/lib/ld-lsb.so.3" 49 '' 50 )) 51 # quartus requirements 52 glib 53 xorg.libICE 54 xorg.libSM 55 xorg.libXau 56 xorg.libXdmcp 57 xorg.libXScrnSaver 58 libudev0-shim 59 bzip2 60 brotli 61 expat 62 dbus 63 # qsys requirements 64 xorg.libXtst 65 xorg.libXi 66 dejavu_fonts 67 gnumake 68 ]; 69 70 # Also support 32-bit executables used by simulator. 71 multiArch = withQuesta; 72 73 # these libs are installed as 64 bit, plus as 32 bit when multiArch is true 74 multiPkgs = 75 pkgs: 76 with pkgs; 77 let 78 # This seems ugly - can we override `libpng = libpng12` for all `pkgs`? 79 freetype = pkgs.freetype.override { libpng = libpng12; }; 80 fontconfig = pkgs.fontconfig.override { inherit freetype; }; 81 libXft = pkgs.xorg.libXft.override { inherit freetype fontconfig; }; 82 in 83 [ 84 # questa requirements 85 libxml2 86 ncurses5 87 unixODBC 88 libXft 89 # common requirements 90 freetype 91 fontconfig 92 xorg.libX11 93 xorg.libXext 94 xorg.libXrender 95 libxcrypt-legacy 96 ]; 97 98 extraInstallCommands = '' 99 mkdir -p $out/share/applications $out/share/icons/hicolor/64x64/apps 100 ln -s ${desktopItem}/share/applications/* $out/share/applications 101 ln -s ${unwrapped}/quartus/adm/quartusii.png $out/share/icons/hicolor/64x64/apps/quartus.png 102 103 progs_to_wrap=( 104 "${unwrapped}"/quartus/bin/* 105 "${unwrapped}"/quartus/sopc_builder/bin/qsys-{generate,edit,script} 106 "${unwrapped}"/questa_fse/bin/* 107 "${unwrapped}"/questa_fse/linux_x86_64/lmutil 108 ) 109 110 wrapper=$out/bin/${pname} 111 progs_wrapped=() 112 for prog in ''${progs_to_wrap[@]}; do 113 relname="''${prog#"${unwrapped}/"}" 114 bname="$(basename "$relname")" 115 wrapped="$out/$relname" 116 progs_wrapped+=("$wrapped") 117 mkdir -p "$(dirname "$wrapped")" 118 echo "#!${runtimeShell}" >> "$wrapped" 119 NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK=1 120 case "$relname" in 121 questa_fse/*) 122 echo "export NIXPKGS_IS_QUESTA_WRAPPER=1" >> "$wrapped" 123 # Any use of LD_PRELOAD breaks Questa, so disable the 124 # SOURCE_DATE_EPOCH code path. 125 NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK=0 126 ;; 127 esac 128 # SOURCE_DATE_EPOCH blocklist for programs that are known to hang/break 129 # with fixed/static clock. 130 case "$bname" in 131 jtagd|quartus_pgm|quartus) 132 NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK=0 133 ;; 134 esac 135 echo "export NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK=$NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK" >> "$wrapped" 136 echo "exec $wrapper $prog \"\$@\"" >> "$wrapped" 137 done 138 139 cd $out 140 chmod +x ''${progs_wrapped[@]} 141 # link into $out/bin so executables become available on $PATH 142 ln --symbolic --relative --target-directory ./bin ''${progs_wrapped[@]} 143 ''; 144 145 profile = '' 146 # LD_PRELOAD fixes issues in the licensing system that cause memory corruption and crashes when 147 # starting most operations in many containerized environments, including WSL2, Docker, and LXC 148 # (a similiar fix involving LD_PRELOADing tcmalloc did not solve the issue in my situation) 149 # https://community.intel.com/t5/Intel-FPGA-Software-Installation/Running-Quartus-Prime-Standard-on-WSL-crashes-in-libudev-so/m-p/1189032 150 # 151 # But, as can be seen in the above resource, LD_PRELOADing libudev breaks 152 # compiling encrypted device libraries in Questa (with error 153 # `(vlog-2163) Macro `<protected> is undefined.`), so only use LD_PRELOAD 154 # for non-Questa wrappers. 155 if [ "$NIXPKGS_IS_QUESTA_WRAPPER" != 1 ]; then 156 export LD_PRELOAD=''${LD_PRELOAD:+$LD_PRELOAD:}/usr/lib/libudev.so.0 157 fi 158 159 # Implement the SOURCE_DATE_EPOCH specification for reproducible builds 160 # (https://reproducible-builds.org/specs/source-date-epoch). 161 # Require opt-in with NIXPKGS_QUARTUS_REPRODUCIBLE_BUILD=1 for now, in case 162 # the blocklist is incomplete. 163 if [ -n "$SOURCE_DATE_EPOCH" ] && [ "$NIXPKGS_QUARTUS_REPRODUCIBLE_BUILD" = 1 ] && [ "$NIXPKGS_QUARTUS_THIS_PROG_SUPPORTS_FIXED_CLOCK" = 1 ]; then 164 export LD_LIBRARY_PATH="${ 165 lib.makeLibraryPath [ 166 libfaketime 167 pkgsi686Linux.libfaketime 168 ] 169 }''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" 170 export LD_PRELOAD=libfaketime.so.1''${LD_PRELOAD:+:$LD_PRELOAD} 171 export FAKETIME_FMT="%s" 172 export FAKETIME="$SOURCE_DATE_EPOCH" 173 fi 174 '' 175 + extraProfile; 176 177 # Run the wrappers directly, instead of going via bash. 178 runScript = ""; 179 180 passthru = { 181 inherit unwrapped; 182 tests = { 183 buildSof = 184 runCommand "quartus-prime-lite-test-build-sof" 185 { 186 nativeBuildInputs = [ quartus-prime-lite ]; 187 env.NIXPKGS_QUARTUS_REPRODUCIBLE_BUILD = "1"; 188 } 189 '' 190 cat >mydesign.vhd <<EOF 191 library ieee; 192 use ieee.std_logic_1164.all; 193 194 entity mydesign is 195 port ( 196 in_0: in std_logic; 197 in_1: in std_logic; 198 out_1: out std_logic 199 ); 200 end mydesign; 201 202 architecture dataflow of mydesign is 203 begin 204 out_1 <= in_0 and in_1; 205 end dataflow; 206 EOF 207 208 quartus_sh --flow compile mydesign 209 210 if ! [ -f mydesign.sof ]; then 211 echo "error: failed to produce mydesign.sof" >&2 212 exit 1 213 fi 214 215 sha1sum mydesign.sof > "$out" 216 ''; 217 questaEncryptedModel = 218 runCommand "quartus-prime-lite-test-questa-encrypted-model" 219 { 220 env.NIXPKGS_QUARTUS_REPRODUCIBLE_BUILD = "1"; 221 } 222 '' 223 "${quartus-prime-lite}/bin/vlog" "${quartus-prime-lite.unwrapped}/questa_fse/intel/verilog/src/arriav_atoms_ncrypt.v" 224 touch "$out" 225 ''; 226 }; 227 }; 228 229 inherit (unwrapped) meta; 230}