···103103- [ ] `meta.maintainers` is set
104104- [ ] build time only dependencies are declared in `nativeBuildInputs`
105105- [ ] source is fetched using the appropriate function
106106-- [ ] phases are respected
106106+- [ ] the list of `phases` is not overridden
107107+- [ ] when a phase (like `installPhase`) is overridden it starts with `runHook preInstall` and ends with `runHook postInstall`.
107108- [ ] patches that are remotely available are fetched with `fetchpatch`
108109109110##### Possible improvements
+4-1
doc/stdenv/stdenv.chapter.md
···325325326326Each phase can be overridden in its entirety either by setting the environment variable `namePhase` to a string containing some shell commands to be executed, or by redefining the shell function `namePhase`. The former is convenient to override a phase from the derivation, while the latter is convenient from a build script. However, typically one only wants to *add* some commands to a phase, e.g. by defining `postInstall` or `preFixup`, as skipping some of the default actions may have unexpected consequences. The default script for each phase is defined in the file `pkgs/stdenv/generic/setup.sh`.
327327328328+When overriding a phase, for example `installPhase`, it is important to start with `runHook preInstall` and end it with `runHook postInstall`, otherwise `preInstall` and `postInstall` will not be run. Even if you don't use them directly, it is good practice to do so anyways for downstream users who would want to add a `postInstall` by overriding your derivation.
329329+328330While inside an interactive `nix-shell`, if you wanted to run all phases in the order they would be run in an actual build, you can invoke `genericBuild` yourself.
329331330332### Controlling phases {#ssec-controlling-phases}
···337339338340Specifies the phases. You can change the order in which phases are executed, or add new phases, by setting this variable. If it’s not set, the default value is used, which is `$prePhases unpackPhase patchPhase $preConfigurePhases configurePhase $preBuildPhases buildPhase checkPhase $preInstallPhases installPhase fixupPhase installCheckPhase $preDistPhases distPhase $postPhases`.
339341340340-Usually, if you just want to add a few phases, it’s more convenient to set one of the variables below (such as `preInstallPhases`), as you then don’t specify all the normal phases.
342342+It is discouraged to set this variable, as it is easy to miss some important functionality hidden in some of the less obviously needed phases (like `fixupPhase` which patches the shebang of scripts).
343343+Usually, if you just want to add a few phases, it’s more convenient to set one of the variables below (such as `preInstallPhases`).
341344342345##### `prePhases` {#var-stdenv-prePhases}
343346
+2-2
nixos/modules/services/matrix/mjolnir.xml
···9898 </para>
9999 <para>
100100 To use the Antispam Module, add <package>matrix-synapse-plugins.matrix-synapse-mjolnir-antispam</package>
101101- to the Synapse plugin list and enable the <literal>mjolnir.AntiSpam</literal> module.
101101+ to the Synapse plugin list and enable the <literal>mjolnir.Module</literal> module.
102102 </para>
103103<programlisting>
104104{
···108108 ];
109109 extraConfig = ''
110110 modules:
111111- - module: mjolnir.AntiSpam
111111+ - module: mjolnir.Module
112112 config:
113113 # Prevent servers/users in the ban lists from inviting users on this
114114 # server to rooms. Default true.
···11# This file originates from node2nix
2233-{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile}:
33+{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript}:
4455let
66 # Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master
···4040 '';
4141 };
42424343- includeDependencies = {dependencies}:
4444- lib.optionalString (dependencies != [])
4545- (lib.concatMapStrings (dependency:
4646- ''
4747- # Bundle the dependencies of the package
4848- mkdir -p node_modules
4949- cd node_modules
5050-5151- # Only include dependencies if they don't exist. They may also be bundled in the package.
5252- if [ ! -e "${dependency.name}" ]
5353- then
5454- ${composePackage dependency}
5555- fi
4343+ # Common shell logic
4444+ installPackage = writeShellScript "install-package" ''
4545+ installPackage() {
4646+ local packageName=$1 src=$2
56475757- cd ..
5858- ''
5959- ) dependencies);
4848+ local strippedName
60496161- # Recursively composes the dependencies of a package
6262- composePackage = { name, packageName, src, dependencies ? [], ... }@args:
6363- builtins.addErrorContext "while evaluating node package '${packageName}'" ''
6464- DIR=$(pwd)
5050+ local DIR=$PWD
6551 cd $TMPDIR
66526767- unpackFile ${src}
5353+ unpackFile $src
68546955 # Make the base dir in which the target dependency resides first
7070- mkdir -p "$(dirname "$DIR/${packageName}")"
5656+ mkdir -p "$(dirname "$DIR/$packageName")"
71577272- if [ -f "${src}" ]
5858+ if [ -f "$src" ]
7359 then
7460 # Figure out what directory has been unpacked
7561 packageDir="$(find . -maxdepth 1 -type d | tail -1)"
···7965 chmod -R u+w "$packageDir"
80668167 # Move the extracted tarball into the output folder
8282- mv "$packageDir" "$DIR/${packageName}"
8383- elif [ -d "${src}" ]
6868+ mv "$packageDir" "$DIR/$packageName"
6969+ elif [ -d "$src" ]
8470 then
8571 # Get a stripped name (without hash) of the source directory.
8672 # On old nixpkgs it's already set internally.
8773 if [ -z "$strippedName" ]
8874 then
8989- strippedName="$(stripHash ${src})"
7575+ strippedName="$(stripHash $src)"
9076 fi
91779278 # Restore write permissions to make building work
9379 chmod -R u+w "$strippedName"
94809581 # Move the extracted directory into the output folder
9696- mv "$strippedName" "$DIR/${packageName}"
8282+ mv "$strippedName" "$DIR/$packageName"
9783 fi
98849999- # Unset the stripped name to not confuse the next unpack step
100100- unset strippedName
8585+ # Change to the package directory to install dependencies
8686+ cd "$DIR/$packageName"
8787+ }
8888+ '';
8989+9090+ # Bundle the dependencies of the package
9191+ #
9292+ # Only include dependencies if they don't exist. They may also be bundled in the package.
9393+ includeDependencies = {dependencies}:
9494+ lib.optionalString (dependencies != []) (
9595+ ''
9696+ mkdir -p node_modules
9797+ cd node_modules
9898+ ''
9999+ + (lib.concatMapStrings (dependency:
100100+ ''
101101+ if [ ! -e "${dependency.name}" ]; then
102102+ ${composePackage dependency}
103103+ fi
104104+ ''
105105+ ) dependencies)
106106+ + ''
107107+ cd ..
108108+ ''
109109+ );
101110102102- # Include the dependencies of the package
103103- cd "$DIR/${packageName}"
111111+ # Recursively composes the dependencies of a package
112112+ composePackage = { name, packageName, src, dependencies ? [], ... }@args:
113113+ builtins.addErrorContext "while evaluating node package '${packageName}'" ''
114114+ installPackage "${packageName}" "${src}"
104115 ${includeDependencies { inherit dependencies; }}
105116 cd ..
106117 ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
···415426 passAsFile = [ "compositionScript" "pinpointDependenciesScript" ];
416427417428 installPhase = ''
429429+ source ${installPackage}
430430+418431 # Create and enter a root node_modules/ folder
419432 mkdir -p $out/lib/node_modules
420433 cd $out/lib/node_modules
···492505 passAsFile = [ "includeScript" "pinpointDependenciesScript" ];
493506494507 installPhase = ''
508508+ source ${installPackage}
509509+495510 mkdir -p $out/${packageName}
496511 cd $out/${packageName}
497512