'fetchurl' Requires A 'sha256' Argument
Describe the Issue
When attempting to use nix develop
, you may encounter an error that reads:
evaluation warning: wheel url 'https://download.pytorch.org/whl/sympy-1.13.3-py3-none-any.whl' missing hash, falling back to builtins.fetchurl
error:
… while calling the 'derivationStrict' builtin
at <nix/derivation-internal.nix>:34:12:
33|
34| strict = derivationStrict drvAttrs;
| ^
35|
… while evaluating derivation 'wombot'
whose name attribute is located at /nix/store/707m8gfbdyxhg1sgkiw5x9zh84ya012r-source/pkgs/stdenv/generic/make-derivation.nix:438:13
… while evaluating attribute 'NIX_PYPROJECT_DEPS' of derivation 'wombot'
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: in pure evaluation mode, 'fetchurl' requires a 'sha256' argument
This error message indicates that the fetchurl
function, which is used to download files from the internet, is missing a required sha256
argument. This argument is necessary to verify the integrity of the downloaded file.
Additional Context
The issue you are experiencing is likely related to the flake.nix
and pyproject.toml
files in your project. These files are used to define the dependencies and build process for your project, and they may be causing the fetchurl
function to fail.
Understanding the Error
To resolve this error, you need to understand why the fetchurl
function is failing. The error message indicates that the sha256
argument is missing, which means that the file being downloaded does not have a valid hash.
Resolving the Error
To resolve this error, you need to add the sha256
argument to the fetchurl
function. This can be done by adding a sha256
attribute to the fetchurl
call, like this:
fetchurl {
url = "https://download.pytorch.org/whl/sympy-1.13.3-py3-none-any.whl";
sha256 = "your_sha256_hash_here";
}
Replace your_sha256_hash_here
with the actual hash of the file being downloaded.
Finding the SHA256 Hash
To find the SHA256 hash of a file, you can use the nix-prefetch-url
command. This command will download the file and calculate its SHA256 hash.
nix-prefetch-url https://download.pytorch.org/whl/sympy-1.13.3-py3-none-any.whl
This will output the SHA256 hash of the file, which you can then use in your fetchurl
call.
Example Use Case
Here is an example of how you might use the fetchurl
function with a sha256
argument in your flake.nix
file:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkDerivation {
name = "wombot";
src = pkgs.fetchurl {
url = "https://download.pytorch.org/whl/sympy-1.13.3-py3-none-any.whl";
sha256 = "your_sha256_hash_here";
};
buildInputs = [ pkgs.python3 ];
}
Replace your_sha256_hash_here
with the actual hash of the file being downloaded.
Conclusion
In conclusion, the fetchurl
function requires a sha256
argument to verify the integrity of the downloaded file. To resolve the error, you need to add the sha256
argument to the fetchurl
function and replace your_sha256_hash_here
with the actual hash of the file being downloaded. You can find the SHA256 hash of a file using the nix-prefetch-url
command.
Troubleshooting Tips
- Make sure that the
sha256
argument is correctly formatted and contains the actual hash of the file being downloaded. - Check that the file being downloaded is not corrupted or incomplete.
- Verify that the
fetchurl
function is being called correctly and that thesha256
argument is being passed to it.
Related Issues
- #175: This issue is related to the same
flake.nix
andpyproject.toml
files as the original issue.
Commit Message
Here is an example of a commit message that you might use to resolve this issue:
fix: add sha256 argument to fetchurl function
Add the sha256 argument to the fetchurl function to resolve the error.
Replace your_sha256_hash_here with the actual hash of the file being downloaded.
```<br/>
**'fetchurl' requires a 'sha256' argument: Q&A**
=====================================================
### Q: What is the 'fetchurl' function in Nix?
A: The `fetchurl` function in Nix is used to download files from the internet. It is a built-in function in Nix that allows you to download files from a URL and store them in a Nix store.
### Q: Why does the 'fetchurl' function require a 'sha256' argument?
A: The `fetchurl` function requires a `sha256` argument to verify the integrity of the downloaded file. This is a security feature that ensures that the file being downloaded is not corrupted or tampered with.
### Q: How do I find the SHA256 hash of a file?
A: You can use the `nix-prefetch-url` command to find the SHA256 hash of a file. This command will download the file and calculate its SHA256 hash.
### Q: What is the format of the SHA256 hash?
A: The SHA256 hash is a 64-character hexadecimal string that represents the digital fingerprint of the file. It is usually represented in the format `your_sha256_hash_here`.
### Q: How do I add the SHA256 hash to the 'fetchurl' function?
A: You can add the SHA256 hash to the `fetchurl` function by adding a `sha256` attribute to the `fetchurl` call. For example:
```nix
fetchurl {
url = "https://download.pytorch.org/whl/sympy-1.13.3-py3-none-any.whl";
sha256 = "your_sha256_hash_here";
}
Replace your_sha256_hash_here
with the actual hash of the file being downloaded.
Q: What if I don't have the SHA256 hash of the file?
A: If you don't have the SHA256 hash of the file, you can use the nix-prefetch-url
command to find it. This command will download the file and calculate its SHA256 hash.
Q: Can I use a different hash algorithm instead of SHA256?
A: No, the fetchurl
function requires a SHA256 hash. You cannot use a different hash algorithm.
Q: What if I'm using a flake.nix file and I don't see the 'fetchurl' function?
A: If you're using a flake.nix file and you don't see the fetchurl
function, it's likely because you're using a newer version of Nix that has deprecated the fetchurl
function. In this case, you can use the fetchurl
function from the nixpkgs
repository instead.
Q: Can I use the 'fetchurl' function in a pure evaluation mode?
A: No, the fetchurl
function cannot be used in a pure evaluation mode. This is because the fetchurl
function requires a SHA256 hash to verify the integrity of the downloaded file, and this hash is not available in a pure evaluation mode.
Q: What if I'm getting an error that says "in pure evaluation mode, 'fetchurl' requires a 'sha256' argument"?
A: If you're getting an error that says "in pure evaluation mode, 'fetchurl' requires a 'sha256' argument", it's likely because you're using the fetchurl
function in pure evaluation mode without providing a SHA256 hash. To resolve this error, you need to provide a SHA256 hash or use a different function that does not require a SHA256 hash.
Q: Can I use the 'fetchurl' function to download a file from a HTTPS URL?
A: Yes, you can use the fetchurl
function to download a file from a HTTPS URL. However, you need to make sure that the HTTPS URL is properly formatted and that the file is not corrupted or tampered with.
Q: What if I'm getting an error that says "fetchurl: unable to verify the integrity of the downloaded file"?
A: If you're getting an error that says "fetchurl: unable to verify the integrity of the downloaded file", it's likely because the SHA256 hash of the file is not correct or the file is corrupted or tampered with. To resolve this error, you need to check the SHA256 hash of the file and make sure that it is correct.