···180180181181#### Preparation {#javascript-yarn2nix-preparation}
182182183183-You will need at least a yarn.lock and yarn.nix file.
183183+You will need at least a `yarn.lock` file. If upstream does not have one you need to generate it and reference it in your package definition.
184184+185185+If the downloaded files contain the `package.json` and `yarn.lock` files they can be used like this:
184186185185-- Generate a yarn.lock in upstream if it is not already there.
186186-- `yarn2nix > yarn.nix` will generate the dependencies in a Nix format.
187187+```nix
188188+offlineCache = fetchYarnDeps {
189189+ yarnLock = src + "/yarn.lock";
190190+ sha256 = "....";
191191+};
192192+```
187193188194#### mkYarnPackage {#javascript-yarn2nix-mkYarnPackage}
189195190190-This will by default try to generate a binary. For package only generating static assets (Svelte, Vue, React...), you will need to explicitly override the build step with your instructions. It's important to use the `--offline` flag. For example if you script is `"build": "something"` in package.json use:
196196+`mkYarnPackage` will by default try to generate a binary. For package only generating static assets (Svelte, Vue, React, WebPack, ...), you will need to explicitly override the build step with your instructions.
197197+198198+It's important to use the `--offline` flag. For example if you script is `"build": "something"` in `package.json` use:
191199192200```nix
193201buildPhase = ''
194194- yarn build --offline
202202+ export HOME=$(mktemp -d)
203203+ yarn --offline build
195204'';
196205```
197206···201210distPhase = "true";
202211```
203212204204-The configure phase can sometimes fail because it tries to be too clever. One common override is:
213213+The configure phase can sometimes fail because it makes many assumptions which may not always apply. One common override is:
205214206215```nix
207207-configurePhase = "ln -s $node_modules node_modules";
216216+configurePhase = ''
217217+ ln -s $node_modules node_modules
218218+'';
219219+```
220220+221221+or if you need a writeable node_modules directory:
222222+223223+```nix
224224+configurePhase = ''
225225+ cp -r $node_modules node_modules
226226+ chmod +w node_modules
227227+'';
208228```
209229210230#### mkYarnModules {#javascript-yarn2nix-mkYarnModules}
211231212212-This will generate a derivation including the node_modules. If you have to build a derivation for an integrated web framework (rails, phoenix..), this is probably the easiest way. [Plausible](https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/web-apps/plausible/default.nix#L39) offers a good example of how to do this.
232232+This will generate a derivation including the `node_modules` directory.
233233+If you have to build a derivation for an integrated web framework (rails, phoenix..), this is probably the easiest way.
213234214235#### Overriding dependency behavior
215236
+14-7
flake.nix
···2020 nixos = import ./nixos/lib { lib = final; };
21212222 nixosSystem = args:
2323- import ./nixos/lib/eval-config.nix (args // {
2424- modules = args.modules ++ [ {
2525- system.nixos.versionSuffix =
2626- ".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}";
2727- system.nixos.revision = final.mkIf (self ? rev) self.rev;
2828- } ];
2929- });
2323+ import ./nixos/lib/eval-config.nix (
2424+ args // {
2525+ modules = args.modules ++ [{
2626+ system.nixos.versionSuffix =
2727+ ".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}";
2828+ system.nixos.revision = final.mkIf (self ? rev) self.rev;
2929+ }];
3030+ } // lib.optionalAttrs (! args?system) {
3131+ # Allow system to be set modularly in nixpkgs.system.
3232+ # We set it to null, to remove the "legacy" entrypoint's
3333+ # non-hermetic default.
3434+ system = null;
3535+ }
3636+ );
3037 });
31383239 checks.x86_64-linux.tarball = jobs.tarball;
···99# expressions are ever made modular at the top level) can just use
1010# types.submodule instead of using eval-config.nix
1111evalConfigArgs@
1212-{ # !!! system can be set modularly, would be nice to remove
1212+{ # !!! system can be set modularly, would be nice to remove,
1313+ # however, removing or changing this default is too much
1414+ # of a breaking change. To set it modularly, pass `null`.
1315 system ? builtins.currentSystem
1416, # !!! is this argument needed any more? The pkgs argument can
1517 # be set modularly anyway.
···4850 # this. Since the latter defaults to the former, the former should
4951 # default to the argument. That way this new default could propagate all
5052 # they way through, but has the last priority behind everything else.
5151- nixpkgs.system = lib.mkDefault system;
5353+ nixpkgs.system = lib.mkIf (system != null) (lib.mkDefault system);
52545355 _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_);
5456 };
+34
nixos/modules/misc/nixpkgs.nix
···244244 defaultText = literalExpression
245245 ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
246246 description = ''
247247+ Systems with a recently generated <literal>hardware-configuration.nix</literal>
248248+ do not need to specify this option, unless cross-compiling, in which case
249249+ you should set <emphasis>only</emphasis> <option>nixpkgs.buildPlatform</option>.
250250+251251+ If this is somehow not feasible, you may fall back to removing the
252252+ <option>nixpkgs.hostPlatform</option> line from the generated config and
253253+ use the old options.
254254+247255 Specifies the platform on which NixOS should be built. When
248256 <code>nixpkgs.crossSystem</code> is unset, it also specifies
249257 the platform <emphasis>for</emphasis> which NixOS should be
···265273 default = null;
266274 example = { system = "aarch64-linux"; config = "aarch64-unknown-linux-gnu"; };
267275 description = ''
276276+ Systems with a recently generated <literal>hardware-configuration.nix</literal>
277277+ may instead specify <emphasis>only</emphasis> <option>nixpkgs.buildPlatform</option>,
278278+ or fall back to removing the <option>nixpkgs.hostPlatform</option> line from the generated config.
279279+268280 Specifies the platform for which NixOS should be
269281 built. Specify this only if it is different from
270282 <code>nixpkgs.localSystem</code>, the platform
···280292 system = mkOption {
281293 type = types.str;
282294 example = "i686-linux";
295295+ default =
296296+ if opt.hostPlatform.isDefined
297297+ then
298298+ throw ''
299299+ Neither ${opt.system} nor any other option in nixpkgs.* is meant
300300+ to be read by modules and configurations.
301301+ Use pkgs.stdenv.hostPlatform instead.
302302+ ''
303303+ else
304304+ throw ''
305305+ Neither ${opt.hostPlatform} nor or the legacy option ${opt.system} has been set.
306306+ You can set ${opt.hostPlatform} in hardware-configuration.nix by re-running
307307+ a recent version of nixos-generate-config.
308308+ The option ${opt.system} is still fully supported for NixOS 22.05 interoperability,
309309+ but will be deprecated in the future, so we recommend to set ${opt.hostPlatform}.
310310+ '';
311311+ defaultText = lib.literalMD ''
312312+ Traditionally `builtins.currentSystem`, but unset when invoking NixOS through `lib.nixosSystem`.
313313+ '';
283314 description = ''
315315+ This option does not need to be specified for NixOS configurations
316316+ with a recently generated <literal>hardware-configuration.nix</literal>.
317317+284318 Specifies the Nix platform type on which NixOS should be built.
285319 It is better to specify <code>nixpkgs.localSystem</code> instead.
286320 <programlisting>
···132132133133 # If the host is 64-bit and the container is 32-bit, add a
134134 # --personality flag.
135135- ${optionalString (config.nixpkgs.localSystem.system == "x86_64-linux") ''
135135+ ${optionalString (pkgs.stdenv.hostPlatform.system == "x86_64-linux") ''
136136 if [ "$(< ''${SYSTEM_PATH:-/nix/var/nix/profiles/per-container/$INSTANCE/system}/system)" = i686-linux ]; then
137137 extraFlags+=" --personality=x86"
138138 fi
···110110 # and libraries path.
111111 # We prefetch it, patch it, and override it in a global bazelrc.
112112 system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux";
113113- arch = stdenv.hostPlatform.parsed.cpu.name;
113113+114114+ # on aarch64 Darwin, `uname -m` returns "arm64"
115115+ arch = with stdenv.hostPlatform; if isDarwin && isAarch64 then "arm64" else parsed.cpu.name;
114116115117 remote_java_tools = stdenv.mkDerivation {
116118 name = "remote_java_tools_${system}";
···135135 # and libraries path.
136136 # We prefetch it, patch it, and override it in a global bazelrc.
137137 system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux";
138138- arch = stdenv.hostPlatform.parsed.cpu.name;
138138+139139+ # on aarch64 Darwin, `uname -m` returns "arm64"
140140+ arch = with stdenv.hostPlatform; if isDarwin && isAarch64 then "arm64" else parsed.cpu.name;
139141140142 remote_java_tools = stdenv.mkDerivation {
141143 name = "remote_java_tools_${system}";