about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/interpreters/octave/build-env.nix
blob: 59575f95fc4b06c910cab1152e2d8a21b7d96270 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{ lib, 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;

  nativeBuildInputs = [ makeWrapper ];
  buildInputs = [ 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 = ''
      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, use -f so it
      # will not fail if no .tar.gz symlinks are there - for example if
      # sommething which is not a tarball used as a package
      rm -f $out/*.tar.gz

      createOctavePackagesPath $out ${octave}

      # Create the file even if the loop afterwards has no packages to run over
      touch $out/.octave_packages
      for path in ${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 "${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
      '';
    };
  };
}