···103- [ ] `meta.maintainers` is set
104- [ ] build time only dependencies are declared in `nativeBuildInputs`
105- [ ] source is fetched using the appropriate function
106-- [ ] phases are respected
0107- [ ] patches that are remotely available are fetched with `fetchpatch`
108109##### Possible improvements
···103- [ ] `meta.maintainers` is set
104- [ ] build time only dependencies are declared in `nativeBuildInputs`
105- [ ] source is fetched using the appropriate function
106+- [ ] the list of `phases` is not overridden
107+- [ ] when a phase (like `installPhase`) is overridden it starts with `runHook preInstall` and ends with `runHook postInstall`.
108- [ ] patches that are remotely available are fetched with `fetchpatch`
109110##### Possible improvements
+4-1
doc/stdenv/stdenv.chapter.md
···325326Each 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`.
32700328While 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.
329330### Controlling phases {#ssec-controlling-phases}
···337338Specifies 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`.
339340-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.
0341342##### `prePhases` {#var-stdenv-prePhases}
343
···325326Each 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`.
327328+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.
329+330While 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.
331332### Controlling phases {#ssec-controlling-phases}
···339340Specifies 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`.
341342+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).
343+Usually, if you just want to add a few phases, it’s more convenient to set one of the variables below (such as `preInstallPhases`).
344345##### `prePhases` {#var-stdenv-prePhases}
346
+2-2
nixos/modules/services/matrix/mjolnir.xml
···98 </para>
99 <para>
100 To use the Antispam Module, add <package>matrix-synapse-plugins.matrix-synapse-mjolnir-antispam</package>
101- to the Synapse plugin list and enable the <literal>mjolnir.AntiSpam</literal> module.
102 </para>
103<programlisting>
104{
···108 ];
109 extraConfig = ''
110 modules:
111- - module: mjolnir.AntiSpam
112 config:
113 # Prevent servers/users in the ban lists from inviting users on this
114 # server to rooms. Default true.
···98 </para>
99 <para>
100 To use the Antispam Module, add <package>matrix-synapse-plugins.matrix-synapse-mjolnir-antispam</package>
101+ to the Synapse plugin list and enable the <literal>mjolnir.Module</literal> module.
102 </para>
103<programlisting>
104{
···108 ];
109 extraConfig = ''
110 modules:
111+ - module: mjolnir.Module
112 config:
113 # Prevent servers/users in the ban lists from inviting users on this
114 # server to rooms. Default true.
···1# This file originates from node2nix
23-{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile}:
45let
6 # Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master
···40 '';
41 };
4243- includeDependencies = {dependencies}:
44- lib.optionalString (dependencies != [])
45- (lib.concatMapStrings (dependency:
46- ''
47- # Bundle the dependencies of the package
48- mkdir -p node_modules
49- cd node_modules
50-51- # Only include dependencies if they don't exist. They may also be bundled in the package.
52- if [ ! -e "${dependency.name}" ]
53- then
54- ${composePackage dependency}
55- fi
5657- cd ..
58- ''
59- ) dependencies);
6061- # Recursively composes the dependencies of a package
62- composePackage = { name, packageName, src, dependencies ? [], ... }@args:
63- builtins.addErrorContext "while evaluating node package '${packageName}'" ''
64- DIR=$(pwd)
65 cd $TMPDIR
6667- unpackFile ${src}
6869 # Make the base dir in which the target dependency resides first
70- mkdir -p "$(dirname "$DIR/${packageName}")"
7172- if [ -f "${src}" ]
73 then
74 # Figure out what directory has been unpacked
75 packageDir="$(find . -maxdepth 1 -type d | tail -1)"
···79 chmod -R u+w "$packageDir"
8081 # Move the extracted tarball into the output folder
82- mv "$packageDir" "$DIR/${packageName}"
83- elif [ -d "${src}" ]
84 then
85 # Get a stripped name (without hash) of the source directory.
86 # On old nixpkgs it's already set internally.
87 if [ -z "$strippedName" ]
88 then
89- strippedName="$(stripHash ${src})"
90 fi
9192 # Restore write permissions to make building work
93 chmod -R u+w "$strippedName"
9495 # Move the extracted directory into the output folder
96- mv "$strippedName" "$DIR/${packageName}"
97 fi
9899- # Unset the stripped name to not confuse the next unpack step
100- unset strippedName
00000000000000000000000101102- # Include the dependencies of the package
103- cd "$DIR/${packageName}"
00104 ${includeDependencies { inherit dependencies; }}
105 cd ..
106 ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
···415 passAsFile = [ "compositionScript" "pinpointDependenciesScript" ];
416417 installPhase = ''
00418 # Create and enter a root node_modules/ folder
419 mkdir -p $out/lib/node_modules
420 cd $out/lib/node_modules
···492 passAsFile = [ "includeScript" "pinpointDependenciesScript" ];
493494 installPhase = ''
00495 mkdir -p $out/${packageName}
496 cd $out/${packageName}
497
···1# This file originates from node2nix
23+{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript}:
45let
6 # Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master
···40 '';
41 };
4243+ # Common shell logic
44+ installPackage = writeShellScript "install-package" ''
45+ installPackage() {
46+ local packageName=$1 src=$2
0000000004748+ local strippedName
004950+ local DIR=$PWD
00051 cd $TMPDIR
5253+ unpackFile $src
5455 # Make the base dir in which the target dependency resides first
56+ mkdir -p "$(dirname "$DIR/$packageName")"
5758+ if [ -f "$src" ]
59 then
60 # Figure out what directory has been unpacked
61 packageDir="$(find . -maxdepth 1 -type d | tail -1)"
···65 chmod -R u+w "$packageDir"
6667 # Move the extracted tarball into the output folder
68+ mv "$packageDir" "$DIR/$packageName"
69+ elif [ -d "$src" ]
70 then
71 # Get a stripped name (without hash) of the source directory.
72 # On old nixpkgs it's already set internally.
73 if [ -z "$strippedName" ]
74 then
75+ strippedName="$(stripHash $src)"
76 fi
7778 # Restore write permissions to make building work
79 chmod -R u+w "$strippedName"
8081 # Move the extracted directory into the output folder
82+ mv "$strippedName" "$DIR/$packageName"
83 fi
8485+ # Change to the package directory to install dependencies
86+ cd "$DIR/$packageName"
87+ }
88+ '';
89+90+ # Bundle the dependencies of the package
91+ #
92+ # Only include dependencies if they don't exist. They may also be bundled in the package.
93+ includeDependencies = {dependencies}:
94+ lib.optionalString (dependencies != []) (
95+ ''
96+ mkdir -p node_modules
97+ cd node_modules
98+ ''
99+ + (lib.concatMapStrings (dependency:
100+ ''
101+ if [ ! -e "${dependency.name}" ]; then
102+ ${composePackage dependency}
103+ fi
104+ ''
105+ ) dependencies)
106+ + ''
107+ cd ..
108+ ''
109+ );
110111+ # Recursively composes the dependencies of a package
112+ composePackage = { name, packageName, src, dependencies ? [], ... }@args:
113+ builtins.addErrorContext "while evaluating node package '${packageName}'" ''
114+ installPackage "${packageName}" "${src}"
115 ${includeDependencies { inherit dependencies; }}
116 cd ..
117 ${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
···426 passAsFile = [ "compositionScript" "pinpointDependenciesScript" ];
427428 installPhase = ''
429+ source ${installPackage}
430+431 # Create and enter a root node_modules/ folder
432 mkdir -p $out/lib/node_modules
433 cd $out/lib/node_modules
···505 passAsFile = [ "includeScript" "pinpointDependenciesScript" ];
506507 installPhase = ''
508+ source ${installPackage}
509+510 mkdir -p $out/${packageName}
511 cd $out/${packageName}
512