Skip to content

Document pinning nixpkgs in manual #27994

Closed

Description

@puffnfresh

I've heard from both @nuttycom and @cocreature that nixpkgs' documentation doesn't describe how to ensure reproducible derivations by pinning the version of nixpkgs.

My knowledge is that this is probably the best way to pin:

import ((import <nixpkgs> { }).fetchFromGitHub {
  owner = "NixOS";
  repo = "nixpkgs";
  rev = "32bcda741a9f58d376ad1f1de0b051571cddc3d2";
  sha256 = "1gcnx2b5jmfyhjhd3d7jgr1wrqyidxczj34d37hxmv4yx7x2722y";
}) { config = { }; }

Activity

  1. vyp commented on Aug 7, 2017

    @vyp
    Member

    Would you know how that compares to setting nix.nixPath?

  2. ocharles commented on Aug 7, 2017

    @ocharles
    Contributor

    I think the solution in the issue description is the best way. I don't see any need to use fetchTarball.

  3. vyp commented on Aug 7, 2017

    @vyp
    Member

    For reference, and if it helps anyone, my source for setting nix.nixPath and managing it with git method, is: http://anderspapitto.com/posts/2015-11-01-nixos-with-local-nixpkgs-checkout.html

    Except that has a typo on the line (the fourth "):

      nix.nixPath = [ "/etc/nixos" "nixos-config"=/etc/nixos/configuration.nix" ];
    

    Should be something like the following instead:

      nix.nixPath = [ "nixpkgs=/etc/nixos" "nixos-config=/etc/nixos/configuration.nix" ];
    

    And also I think it should be git fetch --all instead of just git fetch each time (so that all remotes are fetched).

  4. puffnfresh commented on Aug 7, 2017

    @puffnfresh
    MemberAuthor

    I think ideally there'd be a fetchNixpkgs function.

  5. domenkozar commented on Aug 7, 2017

    @domenkozar
    Member

    @ocharles fetchFromGitHub uses IFD, which then doesn't display all packages to be built upfront. So you first need to build pkgs.fetchFromGithub using the current NIX_PATH and then you can import further on with the new set.

    fetchTarball is a builtin, but it has a drawback that you can't use it with Hydra and need to pass it as an input (what why I usually accept pkgs input that is fetchTarball by default.

  6. FRidh commented on Aug 7, 2017

    @FRidh
    Member

    So that would have been the fetchNixpkgs @LnL7 had proposed (#26802), but that's IFD as @domenkozar pointed out. The proper solution is to use fetchTarball from Nix 1.12 which uses a hash (NixOS/nix#1382).

  7. ocharles commented on Aug 7, 2017

    @ocharles
    Contributor

    @domenkozar I don't entirely understand your comment. Yes, it uses IFD and that results in multiple phases, but beyond that I haven't seen any problems. It's not like a command has to be ran multiple times. What is the main problem?

  8. copumpkin commented on Aug 7, 2017

    @copumpkin
    Member

    I use that pattern all the time at work. I even proposed something to make it a bit smoother, but it didn't really go anywhere: #22058

    I also don't use fetchTarball since I want to be able to lock the version and treat it as a fixed-output derivation that I can cache somewhere, and no released version of Nix has that functionality for fetchTarball yet.

    Edit: to elaborate, I want to be able to cache the exact nixpkgs tarball with a known output hash because many of my machines can't hit github.com, so fetchTarball's attempts to hit the internet directly won't work.

  9. domenkozar commented on Aug 8, 2017

    @domenkozar
    Member

    @ocharles if Nix needs to download anything before evaluating pkgs.fetchFromGithub it won't print the full build plan, etc. It's the best we have now until in Nix 11.12 is released where builtins.fetchTarball accepts a hash so it doesn't redownload the tarball, but all of that happens at evaluation time eagerly.

  10. adelbertc commented on Aug 10, 2017

    @adelbertc
    Contributor

    Just tried @puffnfresh 's implementation today, seems to work. Only issue was an ergonomic one, I wasn't sure how to get the sha256 so I used nix-prefetch-git as suggested here to fetch the revision and get the hash, and then copy/pasted the output. A bit tedious, not sure if there's a better way.

  11. vyp commented on Aug 10, 2017

    @vyp
    Member

    @adelbertc For GitHub, nix-prefetch-url --unpack https://github.com/<owner>/<repo>/archive/<rev>.tar.gz >> file.nix, not sure if there's a better way.

  12. domenkozar commented on Aug 16, 2017

    @domenkozar
    Member

    Relevant: #21732

  13. puffnfresh commented on Dec 30, 2017

    @puffnfresh
    MemberAuthor

    I think that's fair enough, although it still seems to be an IFD under 1.11

  14. CMCDragonkai commented on Nov 26, 2018

    @CMCDragonkai
    Member

    Can the documentation be updated to show you to pin the same nixpkgs to both the configuration.nix and the nix.nixPath = [ "nixpkgs=??" ];.

    I currently have something like:

    { config, ... }:
      let pkgs = import ./nixpkgs { config.allowUnfree = true; }; in
      {
        nix.nixPath = [ "nixpkgs=/etc/nixos/nixpkgs" ];
      }
    

    But I if instead I was using https://github.com/nixos/nixpkgs/archive/ca2ba44cab47767c8127d1c8633e2b581644eb8f.tar.gz, then how to get this used in the nix.nixPath "nixpkgs=??"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions