localPackages.nvhpc: use fhs to build

This commit is contained in:
2024-02-21 13:43:19 +08:00
parent f98887155e
commit 9204d9879b

View File

@@ -1,50 +1,38 @@
{
stdenvNoCC, fetchurl,
gcc, gfortran, autoPatchelfHook,
flock, glibc, coreutils, util-linux, iconv
}:
{ stdenvNoCC, fetchurl, buildFHSEnv }:
let
versions =
{
"24.1" = "1n0x1x7ywvr3623ylvrjagayn44mbvfas3c3062p7y3asmgjx697";
"23.1" = "1xg933f4n1bw39y1x1vrjrbzpx36sbmjgvi332hfck3dbx0n982m";
};
mkNvhpc = { version, sha256 }: stdenvNoCC.mkDerivation rec
releaseName = version:
let versions = builtins.splitVersion version;
in "nvhpc_20${builtins.elemAt versions 0}_${builtins.concatStringsSep "" versions}_Linux_x86_64_cuda_multi";
builder = buildFHSEnv
{
pname = "nvhpc";
inherit version;
src = let versions = builtins.splitVersion version; in fetchurl
{
url = "https://developer.download.nvidia.com/hpc-sdk/${version}/"
+ "nvhpc_20${builtins.elemAt versions 0}_${builtins.concatStringsSep "" versions}"
+ "_Linux_x86_64_cuda_multi.tar.gz";
inherit sha256;
};
BuildInputs = [ gfortran gfortran.cc gcc ];
propagatedBuildInputs = BuildInputs;
nativeBuildInputs =
[
autoPatchelfHook flock
glibc.bin # ldconfig
coreutils # chmod
util-linux # rev
];
postUnpack = ''patchShebangs .'';
dontBuild = true;
dontStrip = true;
NVHPC_SILENT = "true";
NVHPC_INSTALL_TYPE = "single";
installPhase =
''
export NVHPC_INSTALL_DIR=$out/share/nvhpc
ldconfig -C $NIX_BUILD_TOP/ld.so.cache
sed -i 's|/bin/chmod|chmod|g' install_components/install
sed -i 's|/sbin/ldconfig|ldconfig -C $NIX_BUILD_TOP/ld.so.cache|g' install_components/install
sed -i 's|/usr/lib/x86_64-linux-gnu|${iconv.out}/lib|g' \
install_components/Linux_x86_64/${version}/compilers/bin/makelocalrc
./install
'';
autoPatchelfIgnoreMissingDeps = [ "*" ];
name = "builder";
targetPkgs = pkgs: with pkgs; [ gfortran coreutils flock ];
extraBwrapArgs = [ "--bind" "$out" "$out" ];
};
in
builtins.mapAttrs (version: sha256: mkNvhpc { inherit version sha256; }) versions
in let buildNvhpc = version: stdenvNoCC.mkDerivation
{
pname = "nvhpc";
inherit version;
src = fetchurl
{
url = "https://developer.download.nvidia.com/hpc-sdk/${version}/${releaseName version}.tar.gz";
sha256 = versions.${version};
};
dontFixup = true;
dontBuild = true;
installPhase =
''
export NVHPC_SILENT=true
export NVHPC_INSTALL_TYPE=single
export NVHPC_INSTALL_DIR=$out/share/nvhpc
# $out should exist before bwrap
mkdir -p $out
${builder}/bin/builder ./install
'';
};
in builtins.mapAttrs (version: _: buildNvhpc version) versions