Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix-shell --pure usage doesn't work for the full niv API? #222

Open
rpearce opened this issue Apr 4, 2020 · 3 comments
Open

nix-shell --pure usage doesn't work for the full niv API? #222

rpearce opened this issue Apr 4, 2020 · 3 comments

Comments

@rpearce
Copy link

rpearce commented Apr 4, 2020

Hi, I am so grateful for this tool and am soon to write some blog posts that detail using it for various types of projects!

Some notes before my question:

  • ✅ niv works great as a system-wide install
  • ✅ niv works great with nix-shell --packages niv --run "niv ..."

But when I use nix-shell --pure (a pure environment), I run into this issue:

λ nix-shell --pure --packages niv --run "niv add NixOS/nixpkgs-channels --name nixpkgs --branch nixpkgs-unstable"
Adding package nixpkgs
  FATAL: One or more packages failed to update:
  nixpkgs: nix-prefetch-url: readCreateProcessWithExitCode: runInteractiveProcess: exec: does not exist (No such file or directory)
ERROR: ExitFailure 1

The same thing happens if I go into interactive shell mode (naturally):

λ nix-shell --pure --packages niv

[nix-shell:/path/to/project]$ niv add NixOS/nixpkgs-channels --name nixpkgs --branch nixpkgs-unstable
Adding package nixpkgs
  FATAL: One or more packages failed to update:
  nixpkgs: nix-prefetch-url: readCreateProcessWithExitCode: runInteractiveProcess: exec: does not exist (No such file or directory)
ERROR: ExitFailure 1

However, if I use the drop command, that works fine (given I've added a package in a different way):

λ nix-shell --pure --packages niv --run "niv drop nixpkgs"
Dropping package: nixpkgs

Can you please help me figure out what I'm doing wrong here, or if this is an issue?


Here's what my example release.nix looks like for a haskell project:

{ compiler ? "ghc881" }:

let
  sources = import ./nix/sources.nix;
  pkgs = import sources.nixpkgs { config = { }; };
  haskellPackages = pkgs.haskell.packages.${compiler};
  project = haskellPackages.callPackage ./project.nix { };
in
  {
    project = project;

    shell = haskellPackages.shellFor {
      packages = p: with p; [
        project
      ];
      buildInputs = with haskellPackages; [
        cabal-install
        hlint
        ghcid
        ormolu
        niv
      ];
      withHoogle = true;
    };
  }

If I add pkgs.nix to buildInputs,

buildInputs = with haskellPackages; [
  cabal-install
  hlint
  ghcid
  ormolu
  niv
+ pkgs.nix
];

I get this response when running nix-shell --pure

[nix-shell:~/projects/timetrack-cli]$ niv add nixpkgs -o NixOS -r nixpkgs-channels -b nixpkgs-unstable
Adding package nixpkgs
  FATAL: Could not read the output of 'nix-prefetch-url'. This is a bug. Please create a
  ticket:
    https://github.com/nmattia/niv/issues/new
  Thanks! I'll buy you a beer.
  stdout:
  stderr:
  error: unable to download 'https://github.com/NixOS/nixpkgs-channels/archive/05f0934825c2a0750d4888c4735f9420c906b388.tar.gz': Problem with the SSL CA cert (path? access rights?) (77)
  FATAL: One or more packages failed to update:
  nixpkgs: ExitFailure 1
ERROR: ExitFailure 1

@utdemir mentioned that something like cacert might need to be something that is a runtime dependency for niv, and adding pkgs.nix and pkgs.cacert to the buildInputs got it working.

buildInputs = with haskellPackages; [
  cabal-install
  hlint
  ghcid
  ormolu
  niv
+ pkgs.nix
+ pkgs.cacert
];

In short, do pkgs.cacert and something else need to be runtime dependencies?

@rpearce rpearce changed the title nix-shell --pure usage? nix-shell --pure usage doesn't work? Apr 4, 2020
@rpearce rpearce changed the title nix-shell --pure usage doesn't work? nix-shell --pure usage doesn't work all the time? Apr 4, 2020
@rpearce rpearce changed the title nix-shell --pure usage doesn't work all the time? nix-shell --pure usage doesn't work for the full niv API? Apr 4, 2020
@jeff-hykin
Copy link

I had the same issue, and .nix and .cacert worked for me as well.

@nmattia
Copy link
Owner

nmattia commented Sep 1, 2020

Wops, missed the first notification! Yes, niv uses nix-prefetch-url, which is part of the pkgs.nix derivation. We could reimplement it but that'd open a can of worms.

I guess niv should depend on cacert and nix at runtime, but I'm not 100% sure what's the correct way to override a Haskell package in nixpkgs is; I'll ask around.

@rpearce
Copy link
Author

rpearce commented Sep 1, 2020

@nmattia What are you trying to override, specifically? I know a couple of things about overriding haskell packages in nixpkgs

Example:

let
  sources = import ./nix/sources.nix;
in
{ compiler ? "ghc883"
, pkgs ? import sources.nixpkgs { }
}:

let
  inherit (pkgs.lib.trivial) flip pipe;
  inherit (pkgs.haskell.lib) appendPatch appendConfigureFlags;

  haskellPackages = pkgs.haskell.packages.${compiler}.override {
    overrides = hpNew: hpOld: {
      hakyll =
        pipe
           hpOld.hakyll
           [ (flip appendPatch ./hakyll.patch)
             (flip appendConfigureFlags [ "-f" "watchServer" "-f" "previewServer" ])
           ];

      # ...
    };
  };
in # ...

Also, lots of good stuff here for Haskell & Nix: https://github.com/Gabriel439/haskell-nix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants