pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / development / interpreters / octave / build-octave-package.nix
blob30f9bc3b5e1cec251a72e51093bda3ac803075f7
1 # Generic builder for GNU Octave libraries.
2 # This is a file that contains nested functions. The first, outer, function
3 # is the library- and package-wide details, such as the nixpkgs library, any
4 # additional configuration provided, and the namePrefix to use (based on the
5 # pname and version of Octave), the octave package, etc.
7 { lib
8 , stdenv
9 , config
10 , octave
11 , texinfo
12 , computeRequiredOctavePackages
13 , writeRequiredOctavePackagesHook
16 # The inner function contains information required to build the individual
17 # libraries.
18 { fullLibName ? "${attrs.pname}-${attrs.version}"
20 , src
22 , dontPatch ? false
23 , patches ? []
24 , patchPhase ? ""
26 , enableParallelBuilding ? true
27 # Build-time dependencies for the package, which were compiled for the system compiling this.
28 , nativeBuildInputs ? []
30 # Build-time dependencies for the package, which may not have been compiled for the system compiling this.
31 , buildInputs ? []
33 # Propagate build dependencies so in case we have A -> B -> C,
34 # C can import package A propagated by B
35 # Run-time dependencies for the package.
36 , propagatedBuildInputs ? []
38 # Octave packages that are required at runtime for this one.
39 # These behave similarly to propagatedBuildInputs, where if
40 # package A is needed by B, and C needs B, then C also requires A.
41 # The main difference between these and propagatedBuildInputs is
42 # during the package's installation into octave, where all
43 # requiredOctavePackages are ALSO installed into octave.
44 , requiredOctavePackages ? []
46 , preBuild ? ""
48 , meta ? {}
50 , passthru ? {}
52 , ... } @ attrs:
54 let
55   requiredOctavePackages' = computeRequiredOctavePackages requiredOctavePackages;
57   # Must use attrs.nativeBuildInputs before they are removed by the removeAttrs
58   # below, or everything fails.
59   nativeBuildInputs' = [
60     octave
61     writeRequiredOctavePackagesHook
62   ]
63   ++ nativeBuildInputs;
65   passthru' = {
66     updateScript = [
67       ../../../../maintainers/scripts/update-octave-packages
68       (builtins.unsafeGetAttrPos "pname" octave.pkgs.${attrs.pname}).file
69     ];
70   }
71   // passthru;
73   # This step is required because when
74   # a = { test = [ "a" "b" ]; }; b = { test = [ "c" "d" ]; };
75   # (a // b).test = [ "c" "d" ];
76   # This used to mean that if a package defined extra nativeBuildInputs, it
77   # would override the ones for building an Octave package (the hook and Octave
78   # itself, causing everything to fail.
79   attrs' = builtins.removeAttrs attrs [ "nativeBuildInputs" "passthru" ];
81 in stdenv.mkDerivation ({
82   packageName = "${fullLibName}";
83   # The name of the octave package ends up being
84   # "octave-version-package-version"
85   name = "${octave.pname}-${octave.version}-${fullLibName}";
87   # This states that any package built with the function that this returns
88   # will be an octave package. This is used for ensuring other octave
89   # packages are installed into octave during the environment building phase.
90   isOctavePackage = true;
92   OCTAVE_HISTFILE = "/dev/null";
94   inherit src;
96   inherit dontPatch patches patchPhase;
98   dontConfigure = true;
100   enableParallelBuilding = enableParallelBuilding;
102   requiredOctavePackages = requiredOctavePackages';
104   nativeBuildInputs = nativeBuildInputs';
106   buildInputs = buildInputs ++ requiredOctavePackages';
108   propagatedBuildInputs = propagatedBuildInputs ++ [ texinfo ];
110   preBuild = if preBuild == "" then
111     ''
112       # This trickery is needed because Octave expects a single directory inside
113       # at the top-most level of the tarball.
114       tar --transform 's,^,${fullLibName}/,' -cz * -f ${fullLibName}.tar.gz
115     ''
116              else
117                preBuild;
119   buildPhase = ''
120     runHook preBuild
122     mkdir -p $out
123     octave-cli --eval "pkg build $out ${fullLibName}.tar.gz"
125     runHook postBuild
126   '';
128   # We don't install here, because that's handled when we build the environment
129   # together with Octave.
130   dontInstall = true;
132   passthru = passthru';
134   inherit meta;
135 } // attrs')