base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / pkgs / by-name / ds / dssat / package.nix
blob4b40302c415da7dbb29f70c7b5d9fca006fbd1cb
2   stdenv,
3   lib,
4   cmake,
5   glibc,
6   gfortran,
7   makeWrapper,
8   fetchFromGitHub,
9   fetchpatch,
10   dos2unix,
11   dataRepo ? fetchFromGitHub {
12     owner = "DSSAT";
13     repo = "dssat-csm-data";
14     rev = "v4.8.2.8";
15     hash = "sha256-hbSBKEvdSd1lfbemfp4Lk4/JcGMXGVjm1x7P7lmmuA0=";
16   },
18 let
19   # Temporary patch to fix 80 chars limit on paths
20   # https://github.com/DSSAT/dssat-csm-os/pull/417/
21   charLimitPatch = fetchpatch {
22     url = "https://github.com/DSSAT/dssat-csm-os/pull/417/commits/9215012a297c074f392b5e7eb90b8c20495f13f7.patch";
23     hash = "sha256-WwJR5lnWtR3aYWZmk8pBC0/qaRqY0UrWHIaYp2ajImE=";
24   };
26 stdenv.mkDerivation (final: {
27   pname = "dssat";
28   version = "4.8.2.12";
30   src = fetchFromGitHub {
31     owner = "DSSAT";
32     repo = "dssat-csm-os";
33     rev = "refs/tags/v${final.version}";
34     hash = "sha256-8OaTM7IXFZjlelx5O4O+bVNQj4dIhGzIk2iCfpqI8uA=";
35   };
37   # maintainers are on windows and have CRLF endings in their files
38   # And github returns a patch file in unix format only.
39   patchPhase = ''
40     runHook prePatch
41     cp ${charLimitPatch} ./limit-path.patch
42     unix2dos ./limit-path.patch
43     patch --binary -p1 < ./limit-path.patch
44     runHook postPatch
45   '';
47   nativeBuildInputs = [
48     cmake
49     dos2unix
50     gfortran
51     makeWrapper
52   ];
54   buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ glibc.static ];
56   cmakeFlags = [ "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}/share/dssat/" ];
58   postInstall = ''
59     mkdir -p $out/share/dssat/Data
60     cp -r $src/Data/* $out/share/dssat/Data/
61     cp -r ${dataRepo}/* $out/share/dssat/Data/
62     makeWrapper $out/share/dssat/dscsm048 $out/bin/dscsm048
63   '';
65   meta = {
66     homepage = "https://github.com/DSSAT/dssat-csm-os";
67     description = "Cropping System Model";
68     mainProgram = "dscsm048";
69     license = lib.licenses.bsd3;
70     maintainers = with lib.maintainers; [ pcboy ];
71     platforms = lib.platforms.unix;
72     broken = stdenv.hostPlatform.isAarch64 && stdenv.hostPlatform.isLinux;
73   };