Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of sha256 in nixpkgs.fetchgit? Where does the value come from?

Tags:

nix

I would like to add a package from github, just like in the example below, but I do not know where can I get the sha256 hash needed (as shown below) for any given github source.

Can someone explain please where is the sha256 coming from and how can I get that sha256 value for a given github codebase ?

       ghcjs-jquery = self.callPackage ({ mkDerivation, data-default, ghcjs-base, ghcjs-dom, text }:
          mkDerivation {
            pname = "ghcjs-jquery";
            version = "0.1.0.0";
            src = nixpkgs.fetchgit {
              url = git://github.com/ghcjs/ghcjs-jquery;
              rev = "c5eeeafcf81c0d3237b8b9fcb98c4b3633a1297f";
              sha256 = "3b2de54224963ee17857a9737b65d49edc423e06ad7e9c9b85d9f69ca923676a";
            };
            buildDepends = [
              data-default ghcjs-base ghcjs-dom text
            ];
            jailbreak = true;
            license = null;
          }
        ) {};

https://github.com/ryantrinkle/try-reflex/blob/ghcjs-improved-base/default.nix#L49

ps, this is what I got on IRC as answer:

joco42> what does this sha256 attribute mean in this nix expression ? https://github.com/ryantrinkle/try-reflex/blob/ghcjs-improved-base/default.nix#L49
8:24 PM <joco42> where does it come from ?
8:24 PM <pikajude> that's the sha256 hash of that git checkout
8:25 PM  → obadz and ldng joined  ⇐ obadz- quit  
8:29 PM <joco42> pikajude: ok, cool how can i get that ?
8:30 PM <pikajude> nix-prefetch-git in the nix-prefetch-scripts package
8:30 PM <joco42> many thanks pikajude 
like image 303
jhegedus Avatar asked Jul 27 '15 17:07

jhegedus


People also ask

What is Nixpkg?

Overview of Nixpkgs. The Nix Packages collection (Nixpkgs) is a set of thousands of packages for the Nix package manager, released under a permissive MIT/X11 license. Packages are available for several platforms, and can be used with the Nix package manager on most GNU/Linux distributions as well as NixOS.

What is special about NixOS?

NixOS is a Linux distro built around the Nix package system. Nix is built around the idea of immutability. It makes all packages immutable by giving them their own directory identified by a hash that is derived from ALL of that package's dependencies.

How does NixOS work?

Nix ensures that package dependency specifications are complete. Under Nix, a build process will only find resources that have been declared explicitly as dependencies. There's no way it can build until everything it needs has been correctly declared. If it builds, you will know you've provided a complete declaration.

What is the nix store?

Nix stores all packages into a common place called the Nix store, usually located at /nix/store . Each package is stored in a unique subdirectory in the store, and each package has its own tree structure. For example, a SimGrid package might be stored in /nix/store/l5rah62vpsr3ap63xmk197y0s1l6g2zx-simgrid-3.22. 2 .


2 Answers

As I was advised on IRC:

>nix-prefetch-git https://github.com/ghcjs/ghcjs-dom
Initialized empty Git repository in /tmp/user/1000/git-checkout-tmp-uxoKqy9s/git-export/.git/
remote: Counting objects: 1070, done.
remote: Compressing objects: 100% (236/236), done.
remote: Total 1070 (delta 858), reused 932 (delta 829), pack-reused 0
Receiving objects: 100% (1070/1070), 580.67 KiB | 911.00 KiB/s, done.
Resolving deltas: 100% (858/858), done.
From https://github.com/ghcjs/ghcjs-dom
 * branch            HEAD       -> FETCH_HEAD
Switched to a new branch 'fetchgit'
git revision is 8b9c64e78e838de95ef1b61f15c0bd7068d45d84
git human-readable version is -- none --
Commit date is 2015-06-08 03:53:22 +1200
removing `.git'...
hash is d05d04cad4aea829dddcf341ed4656d9828713d271f15c94414a74041188bac8
path is /nix/store/kcgbwampbp7qcyxqp4ag8rx2prxnsc19-git-export
d05d04cad4aea829dddcf341ed4656d9828713d271f15c94414a74041188bac8
like image 98
jhegedus Avatar answered Oct 11 '22 06:10

jhegedus


nix-hash is what you probably need: https://www.mankier.com/1/nix-hash

Use this command to compute the sha256 to be used with fetchurl or such:

$ nix-hash --flat --base32 --type sha256 your-file.zip
like image 2
Nawaz Avatar answered Oct 11 '22 04:10

Nawaz