-
-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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 into default.nix: 'with import <nixpkgs> {};' ignored, but the same given on cmdline worked #172061
Comments
You are not doing the same. Notice the with import <nixpkgs> {}; callPackage ./default.nix {} What Avoiding the let
pkgs = import <nixpkgs> {};
in
pkgs.callPackage ./default.nix {} which is the same as: let
pkgs = import <nixpkgs> {};
in
pkgs.callPackage (import ./default.nix) {} which further expands to: let
pkgs = import <nixpkgs> {};
in
pkgs.callPackage
(
with import <nixpkgs> {};
{ lib, stdenv, fetchFromGitHub, pkg-config, xorg }:
/* ... */
)
{} Assuming every used variable is available as one of the arguments, the let
pkgs = import <nixpkgs> {};
in
pkgs.callPackage
(
{ lib, stdenv, fetchFromGitHub, pkg-config, xorg }:
/* ... */
)
{} Now we can see substitute out let
pkgs = import <nixpkgs> {};
in
(
{ lib, stdenv, fetchFromGitHub, pkg-config, xorg }:
/* ... */
)
(
{
lib = pkgs.lib;
stdenv = pkgs.stdenv;
fetchFromGitHub = pkgs.fetchFromGitHub;
pkg-config = pkgs.pkg-config;
xorg = pkgs.xorg;
}
// {} # This is the second argument of `callPackage`
) Whereas, if you just call Resolving import ./default.nix you get with import <nixpkgs> {};
{ lib, stdenv, fetchFromGitHub, pkg-config, xorg }:
/* ... */ The
|
The thing is: I'm pretty sure, the other day my default.nix was working without trouble VS. you basically saying it's impossible to run my default.nix without callPackage ?! Need some more time to digest your post, though. By the way, my default.nix is the one in nixpkgs from spectrwm, with-statement added on top of it. And, I know I build it from source nix-shelling into the project, asaid default.nix. I can show the executable with nix-store-paths in it ... |
So, how to call the function in my default.nix and not from command line? When I try to use callPackage inside the file, I get: error: syntax error, unexpected ',', expecting '.' or '='
at /home/rtb/code/spectrwm/default.nix:8:6:
7| callpackage
8| { lib, stdenv, fetchFromGitHub, pkg-config, xorg }: and just passing pkgs directly after the function definition, like below, doesn't help either: let
pkgs = import <nixpkgs> {};
in
{ lib, stdenv, fetchFromGitHub, pkg-config, xorg }:
stdenv.mkDerivation {
pname = "spectrwm";
version = "3.4.1";
[...]
meta = with lib; {
description = "A tiling window manager";
homepage = "https://github.com/conformal/spectrwm";
maintainers = with maintainers; [ christianharke ];
license = licenses.isc;
platforms = platforms.all;
longDescription = ''
spectrwm is a small dynamic tiling window manager for X11. It
tries to stay out of the way so that valuable screen real estate
can be used for much more important stuff. It has sane defaults
and does not require one to learn a language to do any
configuration. It was written by hackers for hackers and it
strives to be small, compact and fast.
'';
};
} pkgs |
If you have a function, you must pass arguments it needs, just like in any other programming language.
That is because you are missing parentheses around the function you want to pass as the first argument of
The store paths will be identical when the produced derivation is the same. It does not really matter how you pass around variables, as long as the same arguments are passed to
Well, if you have the function, you must pass it the arguments. But function arguments are not the only way to set “variables”. You can remove/comment out the function head and define the “variables” explicitly: let
pkgs = import <nixpkgs> {};
lib = pkgs.lib;
stdenv = pkgs.stdenv;
fetchFromGitHub = pkgs.fetchFromGitHub;
pkg-config = pkgs.pkg-config;
xorg = pkgs.xorg;
in
# { lib, stdenv, fetchFromGitHub, pkg-config, xorg }:
/* ... */ Or you can introduce them implicitly using the
|
Are you already a computer science professor or a you just training? :) |
Related issue: #209635 |
@jtojnar -- if you're back to coming back to this -- I would expect the following to work in light of your comment, but I get a different error:
|
If you are packaging an OCaml library (that will end up in On the other hand, if you are packaging an OCaml program, you should take Similar advice applies for other languages with libraries not in the top-level package set. For example, Python 3 packages are inside |
Amazing -- thank you so much. Works perfectly: nix-shell -p 'with (import <nixpkgs> {}); pkgs.ocamlPackages.callPackage ./default.nix {}' |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/how-to-get-latest-version-of-packages/33520/11 |
Describe the bug
nix-shell into default.nix: 'with import {};' ignored, but the same given on cmdline worked
Steps To Reproduce
default.nix:
nix-shell
on the above: lib's value non-existantExpected behavior
Expected bahavior was seen with:
nix-shell -E 'with import <nixpkgs> {}; callPackage ./default.nix {}'
-> lib and the other references have their value and nix-shell is available!
Metadata
The text was updated successfully, but these errors were encountered: