1# Trivial build helpers {#chap-trivial-builders} 2 3Nixpkgs provides a variety of wrapper functions that help build commonly useful derivations. 4Like [`stdenv.mkDerivation`](#sec-using-stdenv), each of these build helpers creates a derivation, but the arguments passed are different (usually simpler) from those required by `stdenv.mkDerivation`. 5 6 7## `runCommandWith` {#trivial-builder-runCommandWith} 8 9The function `runCommandWith` returns a derivation built using the specified command(s), in a specified environment. 10 11It is the underlying base function of all [`runCommand*` variants]. 12The general behavior is controlled via a single attribute set passed 13as the first argument, and allows specifying `stdenv` freely. 14 15The following [`runCommand*` variants] exist: `runCommand`, `runCommandCC`, and `runCommandLocal`. 16 17[`runCommand*` variants]: #trivial-builder-runCommand 18 19### Type {#trivial-builder-runCommandWith-Type} 20 21``` 22runCommandWith :: { 23 name :: name; 24 stdenv? :: Derivation; 25 runLocal? :: Bool; 26 derivationArgs? :: { ... }; 27} -> String -> Derivation 28``` 29 30### Inputs {#trivial-builder-runCommandWith-Inputs} 31 32`name` (String) 33: The derivation's name, which Nix will append to the store path; see [`mkDerivation`](#sec-using-stdenv). 34 35`runLocal` (Boolean) 36: If set to `true` this forces the derivation to be built locally, not using [substitutes] nor remote builds. 37 This is intended for very cheap commands (<1s execution time) which can be sped up by avoiding the network round-trip(s). 38 Its effect is to set [`preferLocalBuild = true`][preferLocalBuild] and [`allowSubstitutes = false`][allowSubstitutes]. 39 40 ::: {.note} 41 This prevents the use of [substituters][substituter], so only set `runLocal` (or use `runCommandLocal`) when certain the user will 42 always have a builder for the `system` of the derivation. This should be true for most trivial use cases 43 (e.g., just copying some files to a different location or adding symlinks) because there the `system` 44 is usually the same as `builtins.currentSystem`. 45 ::: 46 47`stdenv` (Derivation) 48: The [standard environment](#chap-stdenv) to use, defaulting to `pkgs.stdenv` 49 50`derivationArgs` (Attribute set) 51: Additional arguments for [`mkDerivation`](#sec-using-stdenv). 52 53`buildCommand` (String) 54: Shell commands to run in the derivation builder. 55 56 ::: {.note} 57 You have to create a file or directory `$out` for Nix to be able to run the builder successfully. 58 ::: 59 60[allowSubstitutes]: https://nixos.org/nix/manual/#adv-attr-allowSubstitutes 61[preferLocalBuild]: https://nixos.org/nix/manual/#adv-attr-preferLocalBuild 62[substituter]: https://nix.dev/manual/nix/latest/glossary#gloss-substituter 63[substitutes]: https://nix.dev/manual/nix/2.23/glossary#gloss-substitute 64 65::: {.example #ex-runcommandwith} 66# Invocation of `runCommandWith` 67 68```nix 69runCommandWith 70 { 71 name = "example"; 72 derivationArgs.nativeBuildInputs = [ cowsay ]; 73 } 74 '' 75 cowsay > $out <<EOMOO 76 'runCommandWith' is a bit cumbersome, 77 so we have more ergonomic wrappers. 78 EOMOO 79 '' 80``` 81 82::: 83 84 85## `runCommand` and `runCommandCC` {#trivial-builder-runCommand} 86 87The function `runCommand` returns a derivation built using the specified command(s), in the `stdenvNoCC` environment. 88 89`runCommandCC` is similar but uses the default compiler environment. To minimize dependencies, `runCommandCC` 90should only be used when the build command needs a C compiler. 91 92`runCommandLocal` is also similar to `runCommand`, but forces the derivation to be built locally. 93See the note on [`runCommandWith`] about `runLocal`. 94 95[`runCommandWith`]: #trivial-builder-runCommandWith 96 97### Type {#trivial-builder-runCommand-Type} 98 99``` 100runCommand :: String -> AttrSet -> String -> Derivation 101runCommandCC :: String -> AttrSet -> String -> Derivation 102runCommandLocal :: String -> AttrSet -> String -> Derivation 103``` 104 105### Input {#trivial-builder-runCommand-Input} 106 107While the type signature(s) differ from [`runCommandWith`], individual arguments with the same name will have the same type and meaning: 108 109`name` (String) 110: The derivation's name 111 112`derivationArgs` (Attribute set) 113: Additional parameters passed to [`mkDerivation`] 114 115`buildCommand` (String) 116: The command(s) run to build the derivation. 117 118 119::: {.example #ex-runcommand-simple} 120# Invocation of `runCommand` 121 122```nix 123runCommand "my-example" { } '' 124 echo My example command is running 125 126 mkdir $out 127 128 echo I can write data to the Nix store > $out/message 129 130 echo I can also run basic commands like: 131 132 echo ls 133 ls 134 135 echo whoami 136 whoami 137 138 echo date 139 date 140'' 141``` 142::: 143 144::: {.note} 145`runCommand name derivationArgs buildCommand` is equivalent to 146```nix 147runCommandWith { 148 inherit name derivationArgs; 149 stdenv = stdenvNoCC; 150} buildCommand 151``` 152 153Likewise, `runCommandCC name derivationArgs buildCommand` is equivalent to 154```nix 155runCommandWith { 156 inherit name derivationArgs; 157} buildCommand 158``` 159::: 160 161 162## Writing text files {#trivial-builder-text-writing} 163 164Nixpkgs provides the following functions for producing derivations which write text files or executable scripts into the Nix store. 165They are useful for creating files from Nix expression, and are all implemented as convenience wrappers around `writeTextFile`. 166 167Each of these functions will cause a derivation to be produced. 168When you coerce the result of each of these functions to a string with [string interpolation](https://nixos.org/manual/nix/stable/language/string-interpolation) or [`builtins.toString`](https://nixos.org/manual/nix/stable/language/builtins#builtins-toString), it will evaluate to the [store path](https://nixos.org/manual/nix/stable/store/store-path) of this derivation. 169 170:::: {.note} 171Some of these functions will put the resulting files within a directory inside the [derivation output](https://nixos.org/manual/nix/stable/language/derivations#attr-outputs). 172If you need to refer to the resulting files somewhere else in a Nix expression, append their path to the derivation's store path. 173 174For example, if the file destination is a directory: 175 176```nix 177{ 178 my-file = writeTextFile { 179 name = "my-file"; 180 text = '' 181 Contents of File 182 ''; 183 destination = "/share/my-file"; 184 }; 185} 186``` 187 188Remember to append "/share/my-file" to the resulting store path when using it elsewhere: 189 190```nix 191writeShellScript "evaluate-my-file.sh" '' 192 cat ${my-file}/share/my-file 193'' 194``` 195:::: 196 197### `makeDesktopItem` {#trivial-builder-makeDesktopItem} 198 199Write an [XDG desktop file](https://specifications.freedesktop.org/desktop-entry-spec/1.4/) to the Nix store. 200 201This function is usually used to add desktop items to a package through the `copyDesktopItems` hook. 202 203`makeDesktopItem` adheres to version 1.4 of the specification. 204 205#### Inputs {#trivial-builder-makeDesktopItem-inputs} 206 207`makeDesktopItem` takes an attribute set that accepts most values from the [XDG specification](https://specifications.freedesktop.org/desktop-entry-spec/1.4/ar01s06.html). 208 209All recognised keys from the specification are supported with the exception of the "Hidden" field. The keys are converted into camelCase format, but correspond 1:1 to their equivalent in the specification: `genericName`, `noDisplay`, `comment`, `icon`, `onlyShowIn`, `notShowIn`, `dbusActivatable`, `tryExec`, `exec`, `path`, `terminal`, `mimeTypes`, `categories`, `implements`, `keywords`, `startupNotify`, `startupWMClass`, `url`, `prefersNonDefaultGPU`. 210 211The "Version" field is hardcoded to the version `makeDesktopItem` currently adheres to. 212 213The following fields are either required, are of a different type than in the specification, carry specific default values, or are additional fields supported by `makeDesktopItem`: 214 215`name` (String) 216 217: The name of the desktop file in the Nix store. 218 219`type` (String; _optional_) 220 221: Default value: `"Application"` 222 223`desktopName` (String) 224 225: Corresponds to the "Name" field of the specification. 226 227`actions` (List of Attribute set; _optional_) 228 229: A list of attribute sets {name, exec?, icon?} 230 231`extraConfig` (Attribute set; _optional_) 232 233: Additional key/value pairs to be added verbatim to the desktop file. Attributes need to be prefixed with 'X-'. 234 235#### Examples {#trivial-builder-makeDesktopItem-examples} 236 237::: {.example #ex-makeDesktopItem} 238# Usage 1 of `makeDesktopItem` 239 240Write a desktop file `/nix/store/<store path>/my-program.desktop` to the Nix store. 241 242```nix 243{ makeDesktopItem }: 244makeDesktopItem { 245 name = "my-program"; 246 desktopName = "My Program"; 247 genericName = "Video Player"; 248 noDisplay = false; 249 comment = "Cool video player"; 250 icon = "/path/to/icon"; 251 onlyShowIn = [ "KDE" ]; 252 dbusActivatable = true; 253 tryExec = "my-program"; 254 exec = "my-program --someflag"; 255 path = "/some/working/path"; 256 terminal = false; 257 actions.example = { 258 name = "New Window"; 259 exec = "my-program --new-window"; 260 icon = "/some/icon"; 261 }; 262 mimeTypes = [ "video/mp4" ]; 263 categories = [ "Utility" ]; 264 implements = [ "org.my-program" ]; 265 keywords = [ 266 "Video" 267 "Player" 268 ]; 269 startupNotify = false; 270 startupWMClass = "MyProgram"; 271 prefersNonDefaultGPU = false; 272 extraConfig.X-SomeExtension = "somevalue"; 273} 274``` 275 276::: 277 278::: {.example #ex2-makeDesktopItem} 279# Usage 2 of `makeDesktopItem` 280 281Override the `hello` package to add a desktop item. 282 283```nix 284{ 285 copyDesktopItems, 286 hello, 287 makeDesktopItem, 288}: 289 290hello.overrideAttrs { 291 nativeBuildInputs = [ copyDesktopItems ]; 292 293 desktopItems = [ 294 (makeDesktopItem { 295 name = "hello"; 296 desktopName = "Hello"; 297 exec = "hello"; 298 }) 299 ]; 300} 301``` 302 303::: 304 305### `writeTextFile` {#trivial-builder-writeTextFile} 306 307Write a text file to the Nix store. 308 309`writeTextFile` takes an attribute set with the following possible attributes: 310 311`name` (String) 312 313: Corresponds to the name used in the Nix store path identifier. 314 315`text` (String) 316 317: The contents of the file. 318 319`executable` (Bool, _optional_) 320 321: Make this file have the executable bit set. 322 323 Default: `false` 324 325`destination` (String, _optional_) 326 327: A subpath under the derivation's output path into which to put the file. 328 Subdirectories are created automatically when the derivation is realised. 329 330 By default, the store path itself will be a file containing the text contents. 331 332 Default: `""` 333 334`checkPhase` (String, _optional_) 335 336: Commands to run after generating the file. 337 338 Default: `""` 339 340`meta` (Attribute set, _optional_) 341 342: Additional metadata for the derivation. 343 344 Default: `{}` 345 346`allowSubstitutes` (Bool, _optional_) 347 348: Whether to allow substituting from a binary cache. 349 Passed through to [`allowSubstitutes`](https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-allowSubstitutes) of the underlying call to `builtins.derivation`. 350 351 It defaults to `false`, as running the derivation's simple `builder` executable locally is assumed to be faster than network operations. 352 Set it to true if the `checkPhase` step is expensive. 353 354 Default: `false` 355 356`preferLocalBuild` (Bool, _optional_) 357 358: Whether to prefer building locally, even if faster [remote build machines](https://nixos.org/manual/nix/stable/command-ref/conf-file#conf-substituters) are available. 359 360 Passed through to [`preferLocalBuild`](https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-preferLocalBuild) of the underlying call to `builtins.derivation`. 361 362 It defaults to `true` for the same reason `allowSubstitutes` defaults to `false`. 363 364 Default: `true` 365 366`derivationArgs` (Attribute set, _optional_) 367 368: Extra arguments to pass to the underlying call to `stdenv.mkDerivation`. 369 370 Default: `{}` 371 372The resulting store path will include some variation of the name, and it will be a file unless `destination` is used, in which case it will be a directory. 373 374::: {.example #ex-writeTextFile} 375# Usage 1 of `writeTextFile` 376 377Write `my-file` to `/nix/store/<store path>/some/subpath/my-cool-script`, making it executable. 378Also run a check on the resulting file in a `checkPhase`, and supply values for the less-used options. 379 380```nix 381writeTextFile { 382 name = "my-cool-script"; 383 text = '' 384 #!/bin/sh 385 echo "This is my cool script!" 386 ''; 387 executable = true; 388 destination = "/some/subpath/my-cool-script"; 389 checkPhase = '' 390 ${pkgs.shellcheck}/bin/shellcheck $out/some/subpath/my-cool-script 391 ''; 392 meta = { 393 license = pkgs.lib.licenses.cc0; 394 }; 395 allowSubstitutes = true; 396 preferLocalBuild = false; 397} 398``` 399::: 400 401::: {.example #ex2-writeTextFile} 402# Usage 2 of `writeTextFile` 403 404Write the string `Contents of File` to `/nix/store/<store path>`. 405See also the [](#trivial-builder-writeText) helper function. 406 407```nix 408writeTextFile { 409 name = "my-file"; 410 text = '' 411 Contents of File 412 ''; 413} 414``` 415::: 416 417::: {.example #ex3-writeTextFile} 418# Usage 3 of `writeTextFile` 419 420Write an executable script `my-script` to `/nix/store/<store path>/bin/my-script`. 421See also the [](#trivial-builder-writeScriptBin) helper function. 422 423```nix 424writeTextFile { 425 name = "my-script"; 426 text = '' 427 echo "hi" 428 ''; 429 executable = true; 430 destination = "/bin/my-script"; 431} 432``` 433::: 434 435### `writeText` {#trivial-builder-writeText} 436 437Write a text file to the Nix store 438 439`writeText` takes the following arguments: 440a string. 441 442`name` (String) 443 444: The name used in the Nix store path. 445 446`text` (String) 447 448: The contents of the file. 449 450The store path will include the name, and it will be a file. 451 452::: {.example #ex-writeText} 453# Usage of `writeText` 454 455Write the string `Contents of File` to `/nix/store/<store path>`: 456 457```nix 458writeText "my-file" '' 459 Contents of File 460'' 461``` 462::: 463 464This is equivalent to: 465 466```nix 467writeTextFile { 468 name = "my-file"; 469 text = '' 470 Contents of File 471 ''; 472} 473``` 474 475### `writeTextDir` {#trivial-builder-writeTextDir} 476 477Write a text file within a subdirectory of the Nix store. 478 479`writeTextDir` takes the following arguments: 480 481`path` (String) 482 483: The destination within the Nix store path under which to create the file. 484 485`text` (String) 486 487: The contents of the file. 488 489The store path will be a directory. 490 491::: {.example #ex-writeTextDir} 492# Usage of `writeTextDir` 493 494Write the string `Contents of File` to `/nix/store/<store path>/share/my-file`: 495 496```nix 497writeTextDir "share/my-file" '' 498 Contents of File 499'' 500``` 501::: 502 503This is equivalent to: 504 505```nix 506writeTextFile { 507 name = "my-file"; 508 text = '' 509 Contents of File 510 ''; 511 destination = "/share/my-file"; 512} 513``` 514 515### `writeScript` {#trivial-builder-writeScript} 516 517Write an executable script file to the Nix store. 518 519`writeScript` takes the following arguments: 520 521`name` (String) 522 523: The name used in the Nix store path. 524 525`text` (String) 526 527: The contents of the file. 528 529The created file is marked as executable. 530The store path will include the name, and it will be a file. 531 532::: {.example #ex-writeScript} 533# Usage of `writeScript` 534 535Write the string `Contents of File` to `/nix/store/<store path>` and make the file executable. 536 537```nix 538writeScript "my-file" '' 539 Contents of File 540'' 541``` 542 543This is equivalent to: 544 545```nix 546writeTextFile { 547 name = "my-file"; 548 text = '' 549 Contents of File 550 ''; 551 executable = true; 552} 553``` 554::: 555 556### `writeScriptBin` {#trivial-builder-writeScriptBin} 557 558Write a script within a `bin` subdirectory of a directory in the Nix store. 559This is for consistency with the convention of software packages placing executables under `bin`. 560 561`writeScriptBin` takes the following arguments: 562 563`name` (String) 564 565: The name used in the Nix store path and within the file created under the store path. 566 567`text` (String) 568 569: The contents of the file. 570 571The created file is marked as executable. 572The file's contents will be put into `/nix/store/<store path>/bin/<name>`. 573The store path will include the name, and it will be a directory. 574 575::: {.example #ex-writeScriptBin} 576# Usage of `writeScriptBin` 577 578```nix 579writeScriptBin "my-script" '' 580 echo "hi" 581'' 582``` 583::: 584 585This is equivalent to: 586 587```nix 588writeTextFile { 589 name = "my-script"; 590 text = '' 591 echo "hi" 592 ''; 593 executable = true; 594 destination = "/bin/my-script"; 595} 596``` 597 598### `writeShellScript` {#trivial-builder-writeShellScript} 599 600Write a Bash script to the store. 601 602`writeShellScript` takes the following arguments: 603 604`name` (String) 605 606: The name used in the Nix store path. 607 608`text` (String) 609 610: The contents of the file. 611 612The created file is marked as executable. 613The store path will include the name, and it will be a file. 614 615This function is almost exactly like [](#trivial-builder-writeScript), except that it prepends to the file a [shebang](https://en.wikipedia.org/wiki/Shebang_%28Unix%29) line that points to the version of Bash used in Nixpkgs. 616<!-- this cannot be changed in practice, so there is no point pretending it's somehow generic --> 617 618::: {.example #ex-writeShellScript} 619# Usage of `writeShellScript` 620 621```nix 622writeShellScript "my-script" '' 623 echo "hi" 624'' 625``` 626::: 627 628This is equivalent to: 629 630```nix 631writeTextFile { 632 name = "my-script"; 633 text = '' 634 #! ${pkgs.runtimeShell} 635 echo "hi" 636 ''; 637 executable = true; 638} 639``` 640 641### `writeShellScriptBin` {#trivial-builder-writeShellScriptBin} 642 643Write a Bash script to a "bin" subdirectory of a directory in the Nix store. 644 645`writeShellScriptBin` takes the following arguments: 646 647`name` (String) 648 649: The name used in the Nix store path and within the file generated under the store path. 650 651`text` (String) 652 653: The contents of the file. 654 655The file's contents will be put into `/nix/store/<store path>/bin/<name>`. 656The store path will include the the name, and it will be a directory. 657 658This function is a combination of [](#trivial-builder-writeShellScript) and [](#trivial-builder-writeScriptBin). 659 660::: {.example #ex-writeShellScriptBin} 661# Usage of `writeShellScriptBin` 662 663```nix 664writeShellScriptBin "my-script" '' 665 echo "hi" 666'' 667``` 668::: 669 670This is equivalent to: 671 672```nix 673writeTextFile { 674 name = "my-script"; 675 text = '' 676 #! ${pkgs.runtimeShell} 677 echo "hi" 678 ''; 679 executable = true; 680 destination = "/bin/my-script"; 681} 682``` 683 684## `concatTextFile`, `concatText`, `concatScript` {#trivial-builder-concatText} 685 686These functions concatenate `files` to the Nix store in a single file. This is useful for configuration files structured in lines of text. `concatTextFile` takes an attribute set and expects two arguments, `name` and `files`. `name` corresponds to the name used in the Nix store path. `files` will be the files to be concatenated. You can also set `executable` to true to make this file have the executable bit set. 687`concatText` and`concatScript` are simple wrappers over `concatTextFile`. 688 689Here are a few examples: 690```nix 691# Writes my-file to /nix/store/<store path> 692concatTextFile 693 { 694 name = "my-file"; 695 files = [ 696 drv1 697 "${drv2}/path/to/file" 698 ]; 699 } 700 # See also the `concatText` helper function below. 701 702 # Writes executable my-file to /nix/store/<store path>/bin/my-file 703 concatTextFile 704 { 705 name = "my-file"; 706 files = [ 707 drv1 708 "${drv2}/path/to/file" 709 ]; 710 executable = true; 711 destination = "/bin/my-file"; 712 } 713 # Writes contents of files to /nix/store/<store path> 714 concatText 715 "my-file" 716 [ file1 file2 ] 717 718 # Writes contents of files to /nix/store/<store path> 719 concatScript 720 "my-file" 721 [ 722 file1 723 file2 724 ] 725``` 726 727## `writeShellApplication` {#trivial-builder-writeShellApplication} 728 729`writeShellApplication` is similar to `writeShellScriptBin` and `writeScriptBin` but supports runtime dependencies with `runtimeInputs`. 730Writes an executable shell script to `/nix/store/<store path>/bin/<name>` and checks its syntax with [`shellcheck`](https://github.com/koalaman/shellcheck) and the `bash`'s `-n` option. 731Some basic Bash options are set by default (`errexit`, `nounset`, and `pipefail`), but can be overridden with `bashOptions`. 732 733Extra arguments may be passed to `stdenv.mkDerivation` by setting `derivationArgs`; note that variables set in this manner will be set when the shell script is _built,_ not when it's run. 734Runtime environment variables can be set with the `runtimeEnv` argument. 735 736For example, the following shell application can refer to `curl` directly, rather than needing to write `${curl}/bin/curl`: 737 738```nix 739writeShellApplication { 740 name = "show-nixos-org"; 741 742 runtimeInputs = [ 743 curl 744 w3m 745 ]; 746 747 text = '' 748 curl -s 'https://nixos.org' | w3m -dump -T text/html 749 ''; 750} 751``` 752 753## `symlinkJoin` {#trivial-builder-symlinkJoin} 754 755This can be used to put many derivations into the same directory structure. It works by creating a new derivation and adding symlinks to each of the paths listed. It expects two arguments, `name`, and `paths`. `name` (or alternatively `pname` and `version`) is the name used in the Nix store path for the created derivation. `paths` is a list of paths that will be symlinked. These paths can be to Nix store derivations or any other subdirectory contained within. 756Here is an example: 757```nix 758# adds symlinks of hello and stack to current build and prints "links added" 759symlinkJoin { 760 name = "myexample"; 761 paths = [ 762 pkgs.hello 763 pkgs.stack 764 ]; 765 postBuild = "echo links added"; 766} 767``` 768This creates a derivation with a directory structure like the following: 769``` 770/nix/store/sglsr5g079a5235hy29da3mq3hv8sjmm-myexample 771|-- bin 772| |-- hello -> /nix/store/qy93dp4a3rqyn2mz63fbxjg228hffwyw-hello-2.10/bin/hello 773| `-- stack -> /nix/store/6lzdpxshx78281vy056lbk553ijsdr44-stack-2.1.3.1/bin/stack 774`-- share 775 |-- bash-completion 776 | `-- completions 777 | `-- stack -> /nix/store/6lzdpxshx78281vy056lbk553ijsdr44-stack-2.1.3.1/share/bash-completion/completions/stack 778 |-- fish 779 | `-- vendor_completions.d 780 | `-- stack.fish -> /nix/store/6lzdpxshx78281vy056lbk553ijsdr44-stack-2.1.3.1/share/fish/vendor_completions.d/stack.fish 781... 782``` 783 784## `writeClosure` {#trivial-builder-writeClosure} 785 786Given a list of [store paths](https://nixos.org/manual/nix/stable/glossary#gloss-store-path) (or string-like expressions coercible to store paths), write their collective [closure](https://nixos.org/manual/nix/stable/glossary#gloss-closure) to a text file. 787 788The result is equivalent to the output of `nix-store -q --requisites`. 789 790For example, 791 792```nix 793writeClosure [ (writeScriptBin "hi" ''${hello}/bin/hello'') ] 794``` 795 796produces an output path `/nix/store/<hash>-runtime-deps` containing 797 798``` 799/nix/store/<hash>-hello-2.10 800/nix/store/<hash>-hi 801/nix/store/<hash>-libidn2-2.3.0 802/nix/store/<hash>-libunistring-0.9.10 803/nix/store/<hash>-glibc-2.32-40 804``` 805 806You can see that this includes `hi`, the original input path, 807`hello`, which is a direct reference, but also 808the other paths that are indirectly required to run `hello`. 809 810## `writeDirectReferencesToFile` {#trivial-builder-writeDirectReferencesToFile} 811 812Writes the set of references to the output file, that is, their immediate dependencies. 813 814This produces the equivalent of `nix-store -q --references`. 815 816For example, 817 818```nix 819writeDirectReferencesToFile (writeScriptBin "hi" ''${hello}/bin/hello'') 820``` 821 822produces an output path `/nix/store/<hash>-runtime-references` containing 823 824``` 825/nix/store/<hash>-hello-2.10 826``` 827 828but none of `hello`'s dependencies because those are not referenced directly 829by `hi`'s output.