Commit 481e1d3a authored by Karl Hallsby's avatar Karl Hallsby Committed by Doron Behar
Browse files

octave.pkgs: init

Heavily based on Python's packages set.
parent 148eff94
Loading
Loading
Loading
Loading
+83 −0
Original line number Diff line number Diff line
{ 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 −0
Original line number Diff line number Diff line
# 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;
}
+132 −99
Original line number Diff line number Diff line
{ stdenv
, pkgs
, lib
# Note: either stdenv.mkDerivation or, for octaveFull, the qt-5 mkDerivation
# with wrapQtAppsHook (comes from libsForQt5.callPackage)
@@ -45,6 +46,11 @@
, python ? null
, overridePlatforms ? null
, sundials ? null
# - Packages required for building extra packages.
, newScope
, callPackage
, makeSetupHook
, makeWrapper
# - Build Octave Qt GUI:
, enableQt ? false
, qtbase ? null
@@ -60,6 +66,7 @@
}:

let

  # Not always evaluated
  blas' = if use64BitIdx then
    blas.override {
@@ -94,7 +101,19 @@ let
  else
    null
  ;
in mkDerivation rec {

  octavePackages = import ../../../top-level/octave-packages.nix {
    inherit pkgs;
    inherit lib stdenv fetchurl newScope;
    octave = self;
  };

  wrapOctave = callPackage ./wrap-octave.nix {
    octave = self;
    inherit (pkgs) makeSetupHook makeWrapper;
  };

  self = mkDerivation rec {
    version = "6.2.0";
    pname = "octave";

@@ -186,15 +205,27 @@ in mkDerivation rec {
      cp test/fntests.log $out/share/octave/${pname}-${version}-fntests.log || true
    '';

  passthru = {
    passthru = rec {
      sitePath = "share/octave/${version}/site";
      octPkgsPath = "share/octave/octave_packages";
      blas = blas';
      lapack = lapack';
      qrupdate = qrupdate';
      arpack = arpack';
      suitesparse = suitesparse';
      inherit fftw fftwSinglePrec;
      inherit portaudio;
      inherit jdk;
      inherit python;
      inherit enableQt enableJIT enableReadline enableJava;
      buildEnv = callPackage ./build-env.nix {
        octave = self;
        inherit octavePackages wrapOctave;
        inherit (octavePackages) computeRequiredOctavePackages;
      };
      withPackages = import ./with-packages.nix { inherit buildEnv octavePackages; };
      pkgs = octavePackages;
      interpreter = "${self}/bin/octave";
    };

    meta = {
@@ -208,4 +239,6 @@ in mkDerivation rec {
        (lib.platforms.linux ++ lib.platforms.darwin)
      else overridePlatforms;
    };
}
  };

in self
+13 −0
Original line number Diff line number Diff line
# Hooks for building Octave packages.
{ octave
, lib
, callPackage
, makeSetupHook
}:

rec {
  writeRequiredOctavePackagesHook = callPackage ({ }:
    makeSetupHook {
      name = "write-required-octave-packages-hook";
    } ./write-required-octave-packages-hook.sh) {};
}
+17 −0
Original line number Diff line number Diff line
# Setup hook for writing octave packages that are run-time dependencies for
# another package to a nix-support file.
# `echo`s the full path name to the package derivation that is required.
echo "Sourcing octave-write-required-octave-packages-hook.sh"

octaveWriteRequiredOctavePackagesPhase() {
    echo "Executing octaveWriteRequiredOctavePackagesPhase"

    mkdir -p $out/nix-support
    echo ${requiredOctavePackages} > $out/nix-support/required-octave-packages
}

# Yes its a bit long...
if [ -z "${dontWriteRequiredOctavePackagesPhase-}" ]; then
    echo "Using octaveWriteRequiredOctavePackagesPhase"
    preDistPhases+=" octaveWriteRequiredOctavePackagesPhase"
fi
Loading