Cannot nixpkgs.callPackage the default.nix #32

Open
opened 2022-02-13 21:35:05 +00:00 by Quoteme · 5 comments
Quoteme commented 2022-02-13 21:35:05 +00:00 (Migrated from github.com)

I put

(import
  (
    let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
    fetchTarball {
      url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
      sha256 = lock.nodes.flake-compat.locked.narHash;
    }
  )
  { src = ./.; }
).defaultNix

in my default.nix and also

inputs.flake-compat = {
  url = github:edolstra/flake-compat;
  flake = false;
};

in my flake.nix. But when I try putting this in my configuration.nix

neovim-luca = (pkgs.callPackage (pkgs.fetchFromGitHub {
    owner = "quoteme";
    repo = "neovim-luca";
    rev = "d85f02952e35d0fd2afa783adb3e93d08fdd03d9";
    sha256 = "sha256-sPX1RaR3H4Hs2YEetdjI7b4UxBC4UxIkvOl1LIYSZuM=";
  }) {});

and doing sudo nixos-rebuild switch I get the following error:

building Nix...
building the system configuration...
error: attempt to call something which is not a function but a set

       at /nix/store/34br6qh4x4hjj15jjnbiivwgdhz4ci5a-nixos/nixos/lib/customisation.nix:69:16:

           68|     let
           69|       result = f origArgs;
             |                ^
           70|
(use '--show-trace' to show detailed location information)

nix-build works fine. But callPackage does not work. How can I fix this?

I put ``` (import ( let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in fetchTarball { url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; sha256 = lock.nodes.flake-compat.locked.narHash; } ) { src = ./.; } ).defaultNix ``` in my default.nix and also ``` inputs.flake-compat = { url = github:edolstra/flake-compat; flake = false; }; ``` in my flake.nix. But when I try putting this in my configuration.nix ``` neovim-luca = (pkgs.callPackage (pkgs.fetchFromGitHub { owner = "quoteme"; repo = "neovim-luca"; rev = "d85f02952e35d0fd2afa783adb3e93d08fdd03d9"; sha256 = "sha256-sPX1RaR3H4Hs2YEetdjI7b4UxBC4UxIkvOl1LIYSZuM="; }) {}); ``` and doing `sudo nixos-rebuild switch` I get the following error: ``` building Nix... building the system configuration... error: attempt to call something which is not a function but a set at /nix/store/34br6qh4x4hjj15jjnbiivwgdhz4ci5a-nixos/nixos/lib/customisation.nix:69:16: 68| let 69| result = f origArgs; | ^ 70| (use '--show-trace' to show detailed location information) ``` `nix-build` works fine. But callPackage does not work. How can I fix this?
Radvendii commented 2022-02-28 16:18:38 +00:00 (Migrated from github.com)

The default.nix at the root of a project is not supposed to be called with with callPackage. This is a little bit confusing (at least it was for me), but let me try to explain:

There are two types of default.nix files that are commonly used. The ones (typically at the root of a project) that get fed into nix-build, and the ones (typically in nixpkgs) that get fed into callPackage.

nix-build expects a file with just a derivation in it. callPackage expects a function from things in nixpkgs to a derivation.

In other words, you should be able to just remove pkgs.callPackage, since your default.nix is just a derivation, it's not a function that needs to be applied to anything.

The `default.nix` at the root of a project is not supposed to be called with with `callPackage`. This is a little bit confusing (at least it was for me), but let me try to explain: There are two types of `default.nix` files that are commonly used. The ones (typically at the root of a project) that get fed into `nix-build`, and the ones (typically in `nixpkgs`) that get fed into `callPackage`. `nix-build` expects a file with just a derivation in it. `callPackage` expects a function from things in `nixpkgs` to a derivation. In other words, you should be able to just remove `pkgs.callPackage`, since your `default.nix` is just a derivation, it's not a function that needs to be applied to anything.
dpc commented 2022-06-28 07:30:08 +00:00 (Migrated from github.com)

@Radvendii Hi. I'm glad I've found your comment. I had the same issues as OP. However when I apply your suggestion I get another error:

> nix develop
error: builder for '/nix/store/r8rbia8zx7v66vwfsykd0s0k6iraa9jz-nix-shell-env.drv' failed with exit code 2;
       last 1 log lines:
       > /nix/store/1fl42m4278x5d0wywih5dcd1zbfs8aib-default.nix: line 4: syntax error near unexpected token `('
       For full logs, run 'nix log /nix/store/r8rbia8zx7v66vwfsykd0s0k6iraa9jz-nix-shell-env.drv'.

6a31b6fba0/infra/flake.nix (L18)

I had to remove {} as well. Is there anything else that is obvious that I'm missing? (I'm still a Nix noob)

@Radvendii Hi. I'm glad I've found your comment. I had the same issues as OP. However when I apply your suggestion I get another error: ``` > nix develop error: builder for '/nix/store/r8rbia8zx7v66vwfsykd0s0k6iraa9jz-nix-shell-env.drv' failed with exit code 2; last 1 log lines: > /nix/store/1fl42m4278x5d0wywih5dcd1zbfs8aib-default.nix: line 4: syntax error near unexpected token `(' For full logs, run 'nix log /nix/store/r8rbia8zx7v66vwfsykd0s0k6iraa9jz-nix-shell-env.drv'. ``` https://github.com/rustshop/rustshop/blob/6a31b6fba00d94da117af893b49524ab42c74f29/infra/flake.nix#L18 I had to remove `{}` as well. Is there anything else that is obvious that I'm missing? (I'm still a Nix noob)
dpc commented 2022-06-28 08:08:09 +00:00 (Migrated from github.com)

After playing with repl I'm even more confused: https://discourse.nixos.org/t/different-result-on-import-path-default-nix-in-flake-nix-vs-repl/19997 - I'm able to get the derivation in nix repl (with (import ./path/default.nix).default but not in my flake.nix.

After playing with repl I'm even more confused: https://discourse.nixos.org/t/different-result-on-import-path-default-nix-in-flake-nix-vs-repl/19997 - I'm able to get the derivation in `nix repl` (with `(import ./path/default.nix).default` but not in my `flake.nix`.
dpc commented 2022-06-28 23:03:06 +00:00 (Migrated from github.com)

I think it is breaking because builtins.currentsystem

Edit: I was right! Here is the workaround that worked for me: 26824e3eb1

I think it is breaking because `builtins.currentsystem` **Edit**: I was right! Here is the workaround that worked for me: https://github.com/rustshop/rustshop/commit/26824e3eb119b8cb5cdfcedddf291853344673a1
abathur commented 2022-11-10 03:33:30 +00:00 (Migrated from github.com)

In case it helps someone else, I ran into both of the error messages in this thread trying to figure out how to use the default flake output in a normal ci.nix that I need to nix-build. I might still be holding it wrong, but I ended up getting it working by just using:

lilgit = (builtins.getFlake (toString ./.)).packages.${builtins.currentSystem}.default;
In case it helps someone else, I ran into both of the error messages in this thread trying to figure out how to use the default flake output in a normal `ci.nix` that I need to `nix-build`. I might still be holding it wrong, but I ended up getting it working by just using: ```nix lilgit = (builtins.getFlake (toString ./.)).packages.${builtins.currentSystem}.default; ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/flake-compat#32
No description provided.