nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 octave,
5 buildEnv,
6 makeWrapper,
7 locale,
8 texinfo,
9 glibcLocalesUtf8,
10 wrapOctave,
11 computeRequiredOctavePackages,
12 extraLibs ? [ ],
13 extraOutputsToInstall ? [ ],
14 postBuild ? "",
15 ignoreCollisions ? false,
16}:
17
18# Create an octave executable that knows about additional packages
19let
20 packages = computeRequiredOctavePackages extraLibs;
21
22 # glibcLocalesUtf8 is null on darwin
23 localeArchiveArgs = lib.optionalString (glibcLocalesUtf8 != null) ''
24 --set LOCALE_ARCHIVE "${glibcLocalesUtf8}/lib/locale/locale-archive"
25 '';
26
27in
28buildEnv {
29 name = "${octave.name}-env";
30 paths = extraLibs ++ [ octave ];
31
32 inherit ignoreCollisions;
33 extraOutputsToInstall = [ "out" ] ++ extraOutputsToInstall;
34
35 nativeBuildInputs = [ makeWrapper ];
36 buildInputs = [
37 locale
38 texinfo
39 wrapOctave
40 ];
41
42 # During "build" we must first unlink the /share symlink to octave's /share
43 # Then, we can re-symlink the all of octave/share, except for /share/octave
44 # in env/share/octave, re-symlink everything from octave/share/octave and then
45 # perform the pkg install.
46 postBuild = ''
47 if [ -L "$out/bin" ]; then
48 unlink $out/bin
49 mkdir -p "$out/bin"
50 cd "${octave}/bin"
51 for prg in *; do
52 if [ -x $prg ]; then
53 makeWrapper "${octave}/bin/$prg" "$out/bin/$prg" \
54 --set OCTAVE_SITE_INITFILE "$out/share/octave/site/m/startup/octaverc" \
55 ${localeArchiveArgs}
56 fi
57 done
58 cd $out
59 fi
60
61 # Remove symlinks to the input tarballs, they aren't needed, use -f so it
62 # will not fail if no .tar.gz symlinks are there - for example if
63 # sommething which is not a tarball used as a package
64 rm -f $out/*.tar.gz
65
66 createOctavePackagesPath $out ${octave}
67
68 # Create the file even if the loop afterwards has no packages to run over
69 touch $out/.octave_packages
70 for path in ${lib.concatStringsSep " " packages}; do
71 if [ -e $path/*.tar.gz ]; then
72 $out/bin/octave-cli --eval "pkg local_list $out/.octave_packages; \
73 pkg prefix $out/${octave.octPkgsPath} $out/${octave.octPkgsPath}; \
74 pfx = pkg (\"prefix\"); \
75 pkg install -nodeps -local $path/*.tar.gz"
76 fi
77 done
78
79 # Re-write the octave-wide startup file (share/octave/site/m/startup/octaverc)
80 # To point to the new local_list in $out
81 addPkgLocalList $out ${octave}
82
83 wrapOctavePrograms "${lib.concatStringsSep " " packages}"
84 # We also need to modify the Exec= line of the desktop file, so it will point
85 # to the wrapper we generated above.
86 rm $out/share/applications # should be a symlink to ${octave}/share/applications
87 mkdir $out/share/applications
88 substitute \
89 ${octave}/share/applications/org.octave.Octave.desktop \
90 $out/share/applications/org.octave.Octave.desktop \
91 --replace-fail ${octave}/bin/octave $out/bin/octave
92 ''
93 + postBuild;
94
95 inherit (octave) meta version;
96
97 passthru = (removeAttrs octave.passthru [ "tests" ]) // {
98 interpreter = "$out/bin/octave";
99 inherit octave;
100 env = stdenv.mkDerivation {
101 name = "interactive-${octave.name}-environment";
102
103 buildCommand = ''
104 echo >&2 ""
105 echo >&2 "*** octave 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
106 echo >&2 ""
107 exit 1
108 '';
109 };
110 };
111}