lol

doc: update fetchzip docs, add examples and follow conventions

With updates in a doc team meeting with Valentin, Silvan and Johannes :)

authored by

DS and committed by
Silvan Mosberger
e67c7383 f955c923

+150 -10
+150 -10
doc/build-helpers/fetchers.chapter.md
··· 283 283 284 284 _Default value:_ `""`. 285 285 286 - `recursiveHash` (Boolean; _optional_) 286 + `recursiveHash` (Boolean; _optional_) []{#sec-pkgs-fetchers-fetchurl-inputs-recursiveHash} 287 287 : If set to `true`, will signal to Nix that the hash given to `fetchurl` was calculated using the `"recursive"` mode. 288 288 See [the documentation on the Nix manual](https://nixos.org/manual/nix/stable/language/advanced-attributes.html#adv-attr-outputHashMode) for more information about the existing modes. 289 289 ··· 296 296 297 297 _Default value_: `false`. 298 298 299 - `downloadToTemp` (Boolean; _optional_) 299 + `downloadToTemp` (Boolean; _optional_) []{#sec-pkgs-fetchers-fetchurl-inputs-downloadToTemp} 300 300 : If `true`, saves the downloaded file to a temporary location instead of the expected Nix store location. 301 301 This is useful when used in conjunction with `postFetch` attribute, otherwise `fetchurl` will not produce any meaningful output. 302 302 ··· 519 519 520 520 ## `fetchzip` {#sec-pkgs-fetchers-fetchzip} 521 521 522 - Downloads content from a given URL (which is assumed to be an archive), and decompresses the archive for you, making files and directories directly accessible. 523 - `fetchzip` can only be used with archives. 524 - Despite its name, `fetchzip` is not limited to `.zip` files and can also be used with any tarball. 522 + Returns a [fixed-output derivation](https://nixos.org/manual/nix/stable/glossary.html#gloss-fixed-output-derivation) which downloads an archive from a given URL and decompresses it. 523 + 524 + Despite its name, `fetchzip` is not limited to `.zip` files but can also be used with [various compressed tarball formats](#tar-files) by default. 525 + This can extended by specifying additional attributes, see [](#ex-fetchers-fetchzip-rar-archive) to understand how to do that. 526 + 527 + ### Inputs {#sec-pkgs-fetchers-fetchzip-inputs} 528 + 529 + `fetchzip` requires an attribute set, and most attributes are passed to the underlying call to [`fetchurl`](#sec-pkgs-fetchers-fetchurl). 530 + 531 + The attributes below are treated differently by `fetchzip` when compared to what `fetchurl` expects: 532 + 533 + `name` (String; _optional_) 534 + : Works as defined in `fetchurl`, but has a different default value than `fetchurl`. 535 + 536 + _Default value:_ `"source"`. 537 + 538 + `nativeBuildInputs` (List of Attribute Set; _optional_) 539 + : Works as defined in `fetchurl`, but it is also augmented by `fetchzip` to include packages to deal with additional archives (such as `.zip`). 540 + 541 + _Default value:_ `[]`. 542 + 543 + `postFetch` (String; _optional_) 544 + : Works as defined in `fetchurl`, but it is also augmented with the code needed to make `fetchzip` work. 545 + 546 + :::{.caution} 547 + It is only safe to modify files in `$out` in `postFetch`. 548 + Consult the implementation of `fetchzip` for anything more involved. 549 + ::: 525 550 526 - It has two required arguments, a URL and a hash. 527 - The hash is typically `hash`, although many more hash algorithms are supported. 528 - Nixpkgs contributors are currently recommended to use `hash`. 529 - This hash will be used by Nix to identify your source. 530 - A typical usage of `fetchzip` is provided below. 551 + _Default value:_ `""`. 552 + 553 + `stripRoot` (Boolean; _optional_) 554 + : If `true`, the decompressed contents are moved one level up the directory tree. 555 + 556 + This is useful for archives that decompress into a single directory which commonly includes some values that change with time, such as version numbers. 557 + When this is the case (and `stripRoot` is `true`), `fetchzip` will remove this directory and make the decompressed contents available in the top-level directory. 558 + 559 + [](#ex-fetchers-fetchzip-simple-striproot) shows what this attribute does. 560 + 561 + This attribute is **not** passed through to `fetchurl`. 562 + 563 + _Default value:_ `true`. 564 + 565 + `extension` (String or Null; _optional_) 566 + : If set, the archive downloaded by `fetchzip` will be renamed to a filename with the extension specified in this attribute. 567 + 568 + This is useful when making `fetchzip` support additional types of archives, because the implementation may use the extension of an archive to determine whether they can decompress it. 569 + If the URL you're using to download the contents doesn't end with the extension associated with the archive, use this attribute to fix the filename of the archive. 570 + 571 + This attribute is **not** passed through to `fetchurl`. 572 + 573 + _Default value:_ `null`. 574 + 575 + `recursiveHash` (Boolean; _optional_) 576 + : Works [as defined in `fetchurl`](#sec-pkgs-fetchers-fetchurl-inputs-recursiveHash), but its default value is different than for `fetchurl`. 577 + 578 + _Default value:_ `true`. 579 + 580 + `downloadToTemp` (Boolean; _optional_) 581 + : Works [as defined in `fetchurl`](#sec-pkgs-fetchers-fetchurl-inputs-downloadToTemp), but its default value is different than for `fetchurl`. 582 + 583 + _Default value:_ `true`. 584 + 585 + `extraPostFetch` **DEPRECATED** 586 + : This attribute is deprecated. 587 + Please use `postFetch` instead. 588 + 589 + This attribute is **not** passed through to `fetchurl`. 590 + 591 + ### Examples {#sec-pkgs-fetchers-fetchzip-examples} 592 + 593 + ::::{.example #ex-fetchers-fetchzip-simple-striproot} 594 + # Using `fetchzip` to output contents directly 595 + 596 + The following recipe shows how to use `fetchzip` to decompress a `.tar.gz` archive: 531 597 532 598 ```nix 533 599 { fetchzip }: ··· 536 602 hash = "sha256-3ABYlME9R8klcpJ7MQpyFEFwHmxDDEzIYBqu/CpDYmg="; 537 603 } 538 604 ``` 605 + 606 + This archive has all its contents in a directory named `patchelf-0.18.0`. 607 + This means that after decompressing, you'd have to enter this directory to see the contents of the archive. 608 + However, `fetchzip` makes this easier through the attribute `stripRoot` (enabled by default). 609 + 610 + After building the recipe, the derivation output will show all the files in the archive at the top level: 611 + 612 + ```shell 613 + $ nix-build 614 + (output removed for clarity) 615 + /nix/store/1b7h3fvmgrcddvs0m299hnqxlgli1yjw-source 616 + 617 + $ ls /nix/store/1b7h3fvmgrcddvs0m299hnqxlgli1yjw-source 618 + aclocal.m4 completions configure.ac m4 Makefile.in patchelf.spec README.md tests 619 + build-aux configure COPYING Makefile.am patchelf.1 patchelf.spec.in src version 620 + ``` 621 + 622 + If `stripRoot` is set to `false`, the derivation output will be the decompressed archive as-is: 623 + 624 + ```nix 625 + { fetchzip }: 626 + fetchzip { 627 + url = "https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0.tar.gz"; 628 + hash = "sha256-uv3FuKE4DqpHT3yfE0qcnq0gYjDNQNKZEZt2+PUAneg="; 629 + stripRoot = false; 630 + } 631 + ``` 632 + 633 + :::{.caution} 634 + The hash changed! 635 + Whenever changing attributes of a Nixpkgs fetcher, [remember to invalidate the hash](#chap-pkgs-fetchers-caveats), otherwise you won't get the results you're expecting! 636 + ::: 637 + 638 + After building the recipe: 639 + 640 + ```shell 641 + $ nix-build 642 + (output removed for clarity) 643 + /nix/store/2hy5bxw7xgbgxkn0i4x6hjr8w3dbx16c-source 644 + 645 + $ ls /nix/store/2hy5bxw7xgbgxkn0i4x6hjr8w3dbx16c-source 646 + patchelf-0.18.0 647 + ``` 648 + :::: 649 + 650 + ::::{.example #ex-fetchers-fetchzip-rar-archive} 651 + # Using `fetchzip` to decompress a `.rar` file 652 + 653 + The `unrar` package provides a [setup hook](#ssec-setup-hooks) to decompress `.rar` archives during the [unpack phase](#ssec-unpack-phase), which can be used with `fetchzip` to decompress those archives: 654 + 655 + ```nix 656 + { fetchzip, unrar }: 657 + fetchzip { 658 + url = "https://archive.org/download/SpaceCadet_Plus95/Space_Cadet.rar"; 659 + hash = "sha256-fC+zsR8BY6vXpUkVd6i1jF0IZZxVKVvNi6VWCKT+pA4="; 660 + stripRoot = false; 661 + nativeBuildInputs = [ unrar ]; 662 + } 663 + ``` 664 + 665 + Since this particular `.rar` file doesn't put its contents in a directory inside the archive, `stripRoot` must be set to `false`. 666 + 667 + After building the recipe, the derivation output will show the decompressed files: 668 + 669 + ```shell 670 + $ nix-build 671 + (output removed for clarity) 672 + /nix/store/zpn7knxfva6rfjja2gbb4p3l9w1f0d36-source 673 + 674 + $ ls /nix/store/zpn7knxfva6rfjja2gbb4p3l9w1f0d36-source 675 + FONT.DAT PINBALL.DAT PINBALL.EXE PINBALL2.MID TABLE.BMP WMCONFIG.EXE 676 + MSCREATE.DIR PINBALL.DOC PINBALL.MID Sounds WAVEMIX.INF 677 + ``` 678 + :::: 539 679 540 680 ## `fetchpatch` {#fetchpatch} 541 681