Skip to content

Commit

Permalink
Merge pull request #108562 from KarlJoad/octave-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
doronbehar authored Feb 24, 2021
2 parents 1e4c84f + 64bacd1 commit aca03db
Show file tree
Hide file tree
Showing 79 changed files with 2,757 additions and 99 deletions.
83 changes: 83 additions & 0 deletions pkgs/development/interpreters/octave/build-env.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{ stdenv, octave, buildEnv
, makeWrapper, texinfo
, octavePackages
, wrapOctave
, computeRequiredOctavePackages
, extraLibs ? []
, extraOutputsToInstall ? []
, postBuild ? ""
, ignoreCollisions ? false
}:

# Create an octave executable that knows about additional packages
let
packages = computeRequiredOctavePackages extraLibs;

in buildEnv {
name = "${octave.name}-env";
paths = extraLibs ++ [ octave ];

inherit ignoreCollisions;
extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;

buildInputs = [ makeWrapper texinfo wrapOctave ];

# During "build" we must first unlink the /share symlink to octave's /share
# Then, we can re-symlink the all of octave/share, except for /share/octave
# in env/share/octave, re-symlink everything from octave/share/octave and then
# perform the pkg install.
postBuild = ''
. "${makeWrapper}/nix-support/setup-hook"
# The `makeWrapper` used here is the one defined in
# ${makeWrapper}/nix-support/setup-hook
if [ -L "$out/bin" ]; then
unlink $out/bin
mkdir -p "$out/bin"
cd "${octave}/bin"
for prg in *; do
if [ -x $prg ]; then
makeWrapper "${octave}/bin/$prg" "$out/bin/$prg" --set OCTAVE_SITE_INITFILE "$out/share/octave/site/m/startup/octaverc"
fi
done
cd $out
fi
# Remove symlinks to the input tarballs, they aren't needed.
rm $out/*.tar.gz
createOctavePackagesPath $out ${octave}
for path in ${stdenv.lib.concatStringsSep " " packages}; do
if [ -e $path/*.tar.gz ]; then
$out/bin/octave-cli --eval "pkg local_list $out/.octave_packages; \
pkg prefix $out/${octave.octPkgsPath} $out/${octave.octPkgsPath}; \
pfx = pkg (\"prefix\"); \
pkg install -nodeps -local $path/*.tar.gz"
fi
done
# Re-write the octave-wide startup file (share/octave/site/m/startup/octaverc)
# To point to the new local_list in $out
addPkgLocalList $out ${octave}
wrapOctavePrograms "${stdenv.lib.concatStringsSep " " packages}"
'' + postBuild;

inherit (octave) meta;

passthru = octave.passthru // {
interpreter = "$out/bin/octave";
inherit octave;
env = stdenv.mkDerivation {
name = "interactive-${octave.name}-environment";

buildCommand = ''
echo >&2 ""
echo >&2 "*** octave 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
echo >&2 ""
exit 1
'';
};
};
}
113 changes: 113 additions & 0 deletions pkgs/development/interpreters/octave/build-octave-package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Generic builder for GNU Octave libraries.
# This is a file that contains nested functions. The first, outer, function
# is the library- and package-wide details, such as the nixpkgs library, any
# additional configuration provided, and the namePrefix to use (based on the
# pname and version of Octave), the octave package, etc.

{ lib
, stdenv
, config
, octave
, texinfo
, computeRequiredOctavePackages
, writeRequiredOctavePackagesHook
}:

# The inner function contains information required to build the individual
# libraries.
{ fullLibName ? "${attrs.pname}-${attrs.version}"

, src

, dontPatch ? false
, patches ? []
, patchPhase ? ""

, enableParallelBuilding ? true
# Build-time dependencies for the package, which were compiled for the system compiling this.
, nativeBuildInputs ? []

# Build-time dependencies for the package, which may not have been compiled for the system compiling this.
, buildInputs ? []

# Propagate build dependencies so in case we have A -> B -> C,
# C can import package A propagated by B
# Run-time dependencies for the package.
, propagatedBuildInputs ? []

# Octave packages that are required at runtime for this one.
# These behave similarly to propagatedBuildInputs, where if
# package A is needed by B, and C needs B, then C also requires A.
# The main difference between these and propagatedBuildInputs is
# during the package's installation into octave, where all
# requiredOctavePackages are ALSO installed into octave.
, requiredOctavePackages ? []

, preBuild ? ""

, meta ? {}

, passthru ? {}

, ... } @ attrs:

let
requiredOctavePackages' = computeRequiredOctavePackages requiredOctavePackages;

in stdenv.mkDerivation {
packageName = "${fullLibName}";
# The name of the octave package ends up being
# "octave-version-package-version"
name = "${octave.pname}-${octave.version}-${fullLibName}";

# This states that any package built with the function that this returns
# will be an octave package. This is used for ensuring other octave
# packages are installed into octave during the environment building phase.
isOctavePackage = true;

OCTAVE_HISTFILE = "/dev/null";

inherit src;

inherit dontPatch patches patchPhase;

dontConfigure = true;

enableParallelBuilding = enableParallelBuilding;

requiredOctavePackages = requiredOctavePackages';

nativeBuildInputs = [
octave
writeRequiredOctavePackagesHook
]
++ nativeBuildInputs;

buildInputs = buildInputs ++ requiredOctavePackages';

propagatedBuildInputs = propagatedBuildInputs ++ [ texinfo ];

preBuild = if preBuild == "" then
''
# This trickery is needed because Octave expects a single directory inside
# at the top-most level of the tarball.
tar --transform 's,^,${fullLibName}/,' -cz * -f ${fullLibName}.tar.gz
''
else
preBuild;

buildPhase = ''
runHook preBuild
mkdir -p $out
octave-cli --eval "pkg build $out ${fullLibName}.tar.gz"
runHook postBuild
'';

# We don't install here, because that's handled when we build the environment
# together with Octave.
dontInstall = true;

inherit meta;
}
Loading

0 comments on commit aca03db

Please sign in to comment.