Baby step #2c; using postInstall

This may be just a infelicity in the documentation.

When reading section 15.1 of nix Package Manager Guide it shows about an attribute to mkDerivation called postInstall.
So I tried it:-)

#atrTest.nix with postInstall
let
  pkgs = import <nixpkgs> {};
in

pkgs.stdenv.mkDerivation rec {
		name = "atrTest-0.0.1";
		#args = ["-run 2"];
		builder = ./builder.sh;
		src = ./makefile;
		extraStuff = "extra stuff${name} for shell";
		buildInputs = [pkgs.tree];
		postInstall = ''
	mkdir ''${out}/Assets
	echo "all done now running postInstall for ${name}" > ''${out}/Assets/log.txt
'';
		}

It seems that this is just treated as another variable to be added to the environment
before bash calls the builder script. This is fine, I dont actually see any other mention
of this attribute in the manual. I only bring this up because it seems like
a real feature. I have seen, but have not had time to study up on phases.

I’m guessing this may be a vestigial example for a time gone by before the concept of
build phases was fully developed, or maybe its a hint of a future feature. Its hard to tell.
It is in a section describing how to quote and escape strings,not how to use mkDerivation.
It just seems so real and useful.

I’m just pointing this out so maybe others don’t waste so much time trying to
use it and to maybe point out to future editors that maybe it should some how
reference fooInstall to indicate its just a made up example to demonstrate quoting.
Its nice that its a real example but maybe its too real.

No actual question this time, just something to think about; unless o’course
its suppose to work as implied, then why doesn’t it?

1 Like

Passing the attributes to the builder as environment variables is the main job of mkDerivation.

postInstall variable is used by the default (generic) builder, it is run at the end of installPhase. I am guessing it was just used as a real life example, rather than a synthetic one, and reader is only expected to familiarise themselves quite the syntax.