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://nix.dev/manual/nix/latest/language/advanced-attributes.html#adv-attr-allowSubstitutes 61[preferLocalBuild]: https://nix.dev/manual/nix/latest/language/advanced-attributes.html#adv-attr-preferLocalBuild 62[substituter]: https://nix.dev/manual/nix/latest/glossary#gloss-substituter 63[substitutes]: https://nix.dev/manual/nix/latest/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 { inherit name derivationArgs; } buildCommand 156``` 157::: 158 159 160## Writing text files {#trivial-builder-text-writing} 161 162Nixpkgs provides the following functions for producing derivations which write text files or executable scripts into the Nix store. 163They are useful for creating files from Nix expression, and are all implemented as convenience wrappers around `writeTextFile`. 164 165Each of these functions will cause a derivation to be produced. 166When 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 [`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. 167 168:::: {.note} 169Some 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). 170If you need to refer to the resulting files somewhere else in a Nix expression, append their path to the derivation's store path. 171 172For example, if the file destination is a directory: 173 174```nix 175{ 176 my-file = writeTextFile { 177 name = "my-file"; 178 text = '' 179 Contents of File 180 ''; 181 destination = "/share/my-file"; 182 }; 183} 184``` 185 186Remember to append "/share/my-file" to the resulting store path when using it elsewhere: 187 188```nix 189writeShellScript "evaluate-my-file.sh" '' 190 cat ${my-file}/share/my-file 191'' 192``` 193:::: 194 195### `makeDesktopItem` {#trivial-builder-makeDesktopItem} 196 197Write an [XDG desktop file](https://specifications.freedesktop.org/desktop-entry-spec/1.4/) to the Nix store. 198 199This function is usually used to add desktop items to a package through the `copyDesktopItems` hook. 200 201`makeDesktopItem` adheres to version 1.4 of the specification. 202 203#### Inputs {#trivial-builder-makeDesktopItem-inputs} 204 205`makeDesktopItem` takes an attribute set that accepts most values from the [XDG specification](https://specifications.freedesktop.org/desktop-entry-spec/1.4/ar01s06.html). 206 207All 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`. 208 209The "Version" field is hardcoded to the version `makeDesktopItem` currently adheres to. 210 211The 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`: 212 213`name` (String) 214 215: The name of the desktop file in the Nix store. 216 217`type` (String; _optional_) 218 219: Default value: `"Application"` 220 221`desktopName` (String) 222 223: Corresponds to the "Name" field of the specification. 224 225`actions` (List of Attribute set; _optional_) 226 227: A list of attribute sets {name, exec?, icon?} 228 229`extraConfig` (Attribute set; _optional_) 230 231: Additional key/value pairs to be added verbatim to the desktop file. Attributes need to be prefixed with 'X-'. 232 233#### Examples {#trivial-builder-makeDesktopItem-examples} 234 235::: {.example #ex-makeDesktopItem} 236# Usage 1 of `makeDesktopItem` 237 238Write a desktop file `/nix/store/<store path>/my-program.desktop` to the Nix store. 239 240```nix 241{ makeDesktopItem }: 242makeDesktopItem { 243 name = "my-program"; 244 desktopName = "My Program"; 245 genericName = "Video Player"; 246 noDisplay = false; 247 comment = "Cool video player"; 248 icon = "/path/to/icon"; 249 onlyShowIn = [ "KDE" ]; 250 dbusActivatable = true; 251 tryExec = "my-program"; 252 exec = "my-program --someflag"; 253 path = "/some/working/path"; 254 terminal = false; 255 actions.example = { 256 name = "New Window"; 257 exec = "my-program --new-window"; 258 icon = "/some/icon"; 259 }; 260 mimeTypes = [ "video/mp4" ]; 261 categories = [ "Utility" ]; 262 implements = [ "org.my-program" ]; 263 keywords = [ 264 "Video" 265 "Player" 266 ]; 267 startupNotify = false; 268 startupWMClass = "MyProgram"; 269 prefersNonDefaultGPU = false; 270 extraConfig.X-SomeExtension = "somevalue"; 271} 272``` 273 274::: 275 276::: {.example #ex2-makeDesktopItem} 277# Usage 2 of `makeDesktopItem` 278 279Override the `hello` package to add a desktop item. 280 281```nix 282{ 283 copyDesktopItems, 284 hello, 285 makeDesktopItem, 286}: 287 288hello.overrideAttrs { 289 nativeBuildInputs = [ copyDesktopItems ]; 290 291 desktopItems = [ 292 (makeDesktopItem { 293 name = "hello"; 294 desktopName = "Hello"; 295 exec = "hello"; 296 }) 297 ]; 298} 299``` 300 301::: 302 303### `writeTextFile` {#trivial-builder-writeTextFile} 304 305Write a text file to the Nix store. 306 307`writeTextFile` takes an attribute set with the following possible attributes: 308 309`name` (String) 310 311: Corresponds to the name used in the Nix store path identifier. 312 313`text` (String) 314 315: The contents of the file. 316 317`executable` (Bool, _optional_) 318 319: Make this file have the executable bit set. 320 321 Default: `false` 322 323`destination` (String, _optional_) 324 325: A subpath under the derivation's output path into which to put the file. 326 Subdirectories are created automatically when the derivation is realised. 327 328 By default, the store path itself will be a file containing the text contents. 329 330 Default: `""` 331 332`checkPhase` (String, _optional_) 333 334: Commands to run after generating the file. 335 336 Default: `""` 337 338`meta` (Attribute set, _optional_) 339 340: Additional metadata for the derivation. 341 342 Default: `{}` 343 344`allowSubstitutes` (Bool, _optional_) 345 346: Whether to allow substituting from a binary cache. 347 Passed through to [`allowSubstitutes`](https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-allowSubstitutes) of the underlying call to `derivation`. 348 349 It defaults to `false`, as running the derivation's simple `builder` executable locally is assumed to be faster than network operations. 350 Set it to true if the `checkPhase` step is expensive. 351 352 Default: `false` 353 354`preferLocalBuild` (Bool, _optional_) 355 356: 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. 357 358 Passed through to [`preferLocalBuild`](https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-preferLocalBuild) of the underlying call to `derivation`. 359 360 It defaults to `true` for the same reason `allowSubstitutes` defaults to `false`. 361 362 Default: `true` 363 364`derivationArgs` (Attribute set, _optional_) 365 366: Extra arguments to pass to the underlying call to `stdenv.mkDerivation`. 367 368 Default: `{}` 369 370The 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. 371 372::: {.example #ex-writeTextFile} 373# Usage 1 of `writeTextFile` 374 375Write `my-file` to `/nix/store/<store path>/some/subpath/my-cool-script`, making it executable. 376Also run a check on the resulting file in a `checkPhase`, and supply values for the less-used options. 377 378```nix 379writeTextFile { 380 name = "my-cool-script"; 381 text = '' 382 #!/bin/sh 383 echo "This is my cool script!" 384 ''; 385 executable = true; 386 destination = "/some/subpath/my-cool-script"; 387 checkPhase = '' 388 ${pkgs.shellcheck}/bin/shellcheck $out/some/subpath/my-cool-script 389 ''; 390 meta = { 391 license = pkgs.lib.licenses.cc0; 392 }; 393 allowSubstitutes = true; 394 preferLocalBuild = false; 395} 396``` 397::: 398 399::: {.example #ex2-writeTextFile} 400# Usage 2 of `writeTextFile` 401 402Write the string `Contents of File` to `/nix/store/<store path>`. 403See also the [](#trivial-builder-writeText) helper function. 404 405```nix 406writeTextFile { 407 name = "my-file"; 408 text = '' 409 Contents of File 410 ''; 411} 412``` 413::: 414 415::: {.example #ex3-writeTextFile} 416# Usage 3 of `writeTextFile` 417 418Write an executable script `my-script` to `/nix/store/<store path>/bin/my-script`. 419See also the [](#trivial-builder-writeScriptBin) helper function. 420 421```nix 422writeTextFile { 423 name = "my-script"; 424 text = '' 425 echo "hi" 426 ''; 427 executable = true; 428 destination = "/bin/my-script"; 429} 430``` 431::: 432 433### `writeText` {#trivial-builder-writeText} 434 435Write a text file to the Nix store 436 437`writeText` takes the following arguments: 438a string. 439 440`name` (String) 441 442: The name used in the Nix store path. 443 444`text` (String) 445 446: The contents of the file. 447 448The store path will include the name, and it will be a file. 449 450::: {.example #ex-writeText} 451# Usage of `writeText` 452 453Write the string `Contents of File` to `/nix/store/<store path>`: 454 455```nix 456writeText "my-file" '' 457 Contents of File 458'' 459``` 460::: 461 462This is equivalent to: 463 464```nix 465writeTextFile { 466 name = "my-file"; 467 text = '' 468 Contents of File 469 ''; 470} 471``` 472 473### `writeTextDir` {#trivial-builder-writeTextDir} 474 475Write a text file within a subdirectory of the Nix store. 476 477`writeTextDir` takes the following arguments: 478 479`path` (String) 480 481: The destination within the Nix store path under which to create the file. 482 483`text` (String) 484 485: The contents of the file. 486 487The store path will be a directory. 488 489::: {.example #ex-writeTextDir} 490# Usage of `writeTextDir` 491 492Write the string `Contents of File` to `/nix/store/<store path>/share/my-file`: 493 494```nix 495writeTextDir "share/my-file" '' 496 Contents of File 497'' 498``` 499::: 500 501This is equivalent to: 502 503```nix 504writeTextFile { 505 name = "my-file"; 506 text = '' 507 Contents of File 508 ''; 509 destination = "/share/my-file"; 510} 511``` 512 513### `writeScript` {#trivial-builder-writeScript} 514 515Write an executable script file to the Nix store. 516 517`writeScript` takes the following arguments: 518 519`name` (String) 520 521: The name used in the Nix store path. 522 523`text` (String) 524 525: The contents of the file. 526 527The created file is marked as executable. 528The store path will include the name, and it will be a file. 529 530::: {.example #ex-writeScript} 531# Usage of `writeScript` 532 533Write the string `Contents of File` to `/nix/store/<store path>` and make the file executable. 534 535```nix 536writeScript "my-file" '' 537 Contents of File 538'' 539``` 540 541This is equivalent to: 542 543```nix 544writeTextFile { 545 name = "my-file"; 546 text = '' 547 Contents of File 548 ''; 549 executable = true; 550} 551``` 552::: 553 554### `writeScriptBin` {#trivial-builder-writeScriptBin} 555 556Write a script within a `bin` subdirectory of a directory in the Nix store. 557This is for consistency with the convention of software packages placing executables under `bin`. 558 559`writeScriptBin` takes the following arguments: 560 561`name` (String) 562 563: The name used in the Nix store path and within the file created under the store path. 564 565`text` (String) 566 567: The contents of the file. 568 569The created file is marked as executable. 570The file's contents will be put into `/nix/store/<store path>/bin/<name>`. 571The store path will include the name, and it will be a directory. 572 573::: {.example #ex-writeScriptBin} 574# Usage of `writeScriptBin` 575 576```nix 577writeScriptBin "my-script" '' 578 echo "hi" 579'' 580``` 581::: 582 583This is equivalent to: 584 585```nix 586writeTextFile { 587 name = "my-script"; 588 text = '' 589 echo "hi" 590 ''; 591 executable = true; 592 destination = "/bin/my-script"; 593} 594``` 595 596### `writeShellScript` {#trivial-builder-writeShellScript} 597 598Write a Bash script to the store. 599 600`writeShellScript` takes the following arguments: 601 602`name` (String) 603 604: The name used in the Nix store path. 605 606`text` (String) 607 608: The contents of the file. 609 610The created file is marked as executable. 611The store path will include the name, and it will be a file. 612 613This 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. 614<!-- this cannot be changed in practice, so there is no point pretending it's somehow generic --> 615 616::: {.example #ex-writeShellScript} 617# Usage of `writeShellScript` 618 619```nix 620writeShellScript "my-script" '' 621 echo "hi" 622'' 623``` 624::: 625 626This is equivalent to: 627 628```nix 629writeTextFile { 630 name = "my-script"; 631 text = '' 632 #! ${pkgs.runtimeShell} 633 echo "hi" 634 ''; 635 executable = true; 636} 637``` 638 639### `writeShellScriptBin` {#trivial-builder-writeShellScriptBin} 640 641Write a Bash script to a "bin" subdirectory of a directory in the Nix store. 642 643`writeShellScriptBin` takes the following arguments: 644 645`name` (String) 646 647: The name used in the Nix store path and within the file generated under the store path. 648 649`text` (String) 650 651: The contents of the file. 652 653The file's contents will be put into `/nix/store/<store path>/bin/<name>`. 654The store path will include the the name, and it will be a directory. 655 656This function is a combination of [](#trivial-builder-writeShellScript) and [](#trivial-builder-writeScriptBin). 657 658::: {.example #ex-writeShellScriptBin} 659# Usage of `writeShellScriptBin` 660 661```nix 662writeShellScriptBin "my-script" '' 663 echo "hi" 664'' 665``` 666::: 667 668This is equivalent to: 669 670```nix 671writeTextFile { 672 name = "my-script"; 673 text = '' 674 #! ${pkgs.runtimeShell} 675 echo "hi" 676 ''; 677 executable = true; 678 destination = "/bin/my-script"; 679} 680``` 681 682## `concatTextFile`, `concatText`, `concatScript` {#trivial-builder-concatText} 683 684These 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. 685`concatText` and`concatScript` are simple wrappers over `concatTextFile`. 686 687Here are a few examples: 688```nix 689# Writes my-file to /nix/store/<store path> 690concatTextFile 691 { 692 name = "my-file"; 693 files = [ 694 drv1 695 "${drv2}/path/to/file" 696 ]; 697 } 698 # See also the `concatText` helper function below. 699 700 # Writes executable my-file to /nix/store/<store path>/bin/my-file 701 concatTextFile 702 { 703 name = "my-file"; 704 files = [ 705 drv1 706 "${drv2}/path/to/file" 707 ]; 708 executable = true; 709 destination = "/bin/my-file"; 710 } 711 # Writes contents of files to /nix/store/<store path> 712 concatText 713 "my-file" 714 [ 715 file1 716 file2 717 ] 718 719 # Writes contents of files to /nix/store/<store path> 720 concatScript 721 "my-file" 722 [ 723 file1 724 file2 725 ] 726``` 727 728## `writeShellApplication` {#trivial-builder-writeShellApplication} 729 730`writeShellApplication` is similar to `writeShellScriptBin` and `writeScriptBin` but supports runtime dependencies with `runtimeInputs`. 731Writes 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. 732Some basic Bash options are set by default (`errexit`, `nounset`, and `pipefail`), but can be overridden with `bashOptions`. 733 734Extra 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. 735Runtime environment variables can be set with the `runtimeEnv` argument. 736 737For example, the following shell application can refer to `curl` directly, rather than needing to write `${curl}/bin/curl`: 738 739```nix 740writeShellApplication { 741 name = "show-nixos-org"; 742 743 runtimeInputs = [ 744 curl 745 w3m 746 ]; 747 748 text = '' 749 curl -s 'https://nixos.org' | w3m -dump -T text/html 750 ''; 751} 752``` 753 754## `symlinkJoin` {#trivial-builder-symlinkJoin} 755 756This 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. 757Here is an example: 758```nix 759# adds symlinks of hello and stack to current build and prints "links added" 760symlinkJoin { 761 name = "myexample"; 762 paths = [ 763 pkgs.hello 764 pkgs.stack 765 ]; 766 postBuild = "echo links added"; 767} 768``` 769This creates a derivation with a directory structure like the following: 770``` 771/nix/store/sglsr5g079a5235hy29da3mq3hv8sjmm-myexample 772|-- bin 773| |-- hello -> /nix/store/qy93dp4a3rqyn2mz63fbxjg228hffwyw-hello-2.10/bin/hello 774| `-- stack -> /nix/store/6lzdpxshx78281vy056lbk553ijsdr44-stack-2.1.3.1/bin/stack 775`-- share 776 |-- bash-completion 777 | `-- completions 778 | `-- stack -> /nix/store/6lzdpxshx78281vy056lbk553ijsdr44-stack-2.1.3.1/share/bash-completion/completions/stack 779 |-- fish 780 | `-- vendor_completions.d 781 | `-- stack.fish -> /nix/store/6lzdpxshx78281vy056lbk553ijsdr44-stack-2.1.3.1/share/fish/vendor_completions.d/stack.fish 782... 783``` 784 785## `writeClosure` {#trivial-builder-writeClosure} 786 787Given 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. 788 789The result is equivalent to the output of `nix-store -q --requisites`. 790 791For example, 792 793```nix 794writeClosure [ (writeScriptBin "hi" "${hello}/bin/hello") ] 795``` 796 797produces an output path `/nix/store/<hash>-runtime-deps` containing 798 799``` 800/nix/store/<hash>-hello-2.10 801/nix/store/<hash>-hi 802/nix/store/<hash>-libidn2-2.3.0 803/nix/store/<hash>-libunistring-0.9.10 804/nix/store/<hash>-glibc-2.32-40 805``` 806 807You can see that this includes `hi`, the original input path, 808`hello`, which is a direct reference, but also 809the other paths that are indirectly required to run `hello`. 810 811## `writeDirectReferencesToFile` {#trivial-builder-writeDirectReferencesToFile} 812 813Writes the set of references to the output file, that is, their immediate dependencies. 814 815This produces the equivalent of `nix-store -q --references`. 816 817For example, 818 819```nix 820writeDirectReferencesToFile (writeScriptBin "hi" "${hello}/bin/hello") 821``` 822 823produces an output path `/nix/store/<hash>-runtime-references` containing 824 825``` 826/nix/store/<hash>-hello-2.10 827``` 828 829but none of `hello`'s dependencies because those are not referenced directly 830by `hi`'s output.