Hi,
I’m new to Nix and NixOS. I’m looking into creating Nix packages & have been looking at other Nix packages’ syntax. I see a lot of “fetchFromGithub” being used which pulls from github.com without having to specify that.
I have entered the correct domain into the Domain field under fetchFromGitea, but it does not want to connect for some reason & continues to state “Could not resolve host:”. I can take the same exact URL it’s using and wget the file perfectly fine from the same CLI. I’m not sure what I’m missing here!
My Questions are: How can I get fetchFromGitea to work? Is there an example somewhere I can look at?
Thanks
1 Like
You can use the domain
argument:
You can see many examples in Nixpkgs:
It should probably be documented in the manual:
# Fetchers {#chap-pkgs-fetchers}
When using Nix, you will frequently need to download source code and other files from the internet. For this purpose, Nix provides the [_fixed output derivation_](https://nixos.org/manual/nix/stable/#fixed-output-drvs) feature and Nixpkgs provides various functions that implement the actual fetching from various protocols and services.
## Caveats
Because fixed output derivations are _identified_ by their hash, a common mistake is to update a fetcher's URL or a version parameter, without updating the hash. **This will cause the old contents to be used.** So remember to always invalidate the hash argument.
For those who develop and maintain fetchers, a similar problem arises with changes to the implementation of a fetcher. These may cause a fixed output derivation to fail, but won't normally be caught by tests because the supposed output is already in the store or cache. For the purpose of testing, you can use a trick that is embodied by the [`invalidateFetcherByDrvHash`](#sec-pkgs-invalidateFetcherByDrvHash) function. It uses the derivation `name` to create a unique output path per fetcher implementation, defeating the caching precisely where it would be harmful.
## `fetchurl` and `fetchzip` {#fetchurl}
Two basic fetchers are `fetchurl` and `fetchzip`. Both of these have two required arguments, a URL and a hash. The hash is typically `sha256`, although many more hash algorithms are supported. Nixpkgs contributors are currently recommended to use `sha256`. This hash will be used by Nix to identify your source. A typical usage of fetchurl is provided below.
```nix
{ stdenv, fetchurl }:
stdenv.mkDerivation {
name = "hello";
src = fetchurl {
This file has been truncated. show original
Thank you for your help and indepth explanation. I agree that this should be in the documentation and have opened a Pull Request to do so here, Added fetchFromGitea to docs by jahway603 · Pull Request #165133 · NixOS/nixpkgs · GitHub