nix-community / nixGL

A wrapper tool for nix OpenGL application [maintainer=@guibou]
677 stars 78 forks source link

Broken overlay definition #111

Closed stopbystudent closed 2 years ago

stopbystudent commented 2 years ago

110 broke the use of the nix flake in overlays. That is, it defines overlays in dependence of the system which it should not be. Consequently, trying to use the nixGL overlay yields the following error:

error: All overlays passed to nixpkgs must be functions

The solution would be to move overlay out of the eachDefaultSystem call. This will require a bit of restructuring so that the overlay can reference the package created in the eachDefaultSystem function.

Please note that #110 broke all uses of nixGL as an overlay by introducting that indirection. Your compatibility attribute overlay that references overlays.default does not help with that because it is still wrongly scoped.

guibou commented 2 years ago

Rha, damned. Thank yoau for reporting that!

I'll have a look ;)

carlthome commented 2 years ago

Complete nix novice here but calling nixpkgs.lib.attrValues on nixgl.overlay seems to at least run.

E.g. like this: https://github.com/tweag/jupyterWith#using-flakes

cmm commented 2 years ago

What I understand the forEachSupportedSystem thing to do is, it turns every output specification into a set with per-system attributes -- so whatever was formerly in nixgl.overlay is now in nixgl.overlay.x86_64-linux (or whatever your actual system is).

Which is why adding all those attributes' values to nixpkgs.overlays works too.

But yes, it seems the customary thing to do is to have just one overlay that adds packages for all supported systems, instead of an overlay per system.

guibou commented 2 years ago

Could you check that https://github.com/guibou/nixGL/pull/113 fixs the problem for you?

It should be as simple as changing the reference in your flake.nix from github:guibou/nixGL to github:guibou/nixGL/fix_overlays.

galenhuntington commented 2 years ago

This change is working for me. :+1:

I'm new to Nix, but this "if condition then true else false" looks redundant to me. That is, couldn't it be simply isIntelX86Platform = final.system == "x86_64-linux";?

guibou commented 2 years ago

This change is working for me. +1

I'm new to Nix, but this "if condition then true else false" looks redundant to me. That is, couldn't it be simply isIntelX86Platform = final.system == "x86_64-linux";?

Haha, yes, absolutely ;)

guibou commented 2 years ago

Merged and hence the issue is closed.

Thank you for reporting and for your suggestions. Please reopen if that's not perfectly fixed for you.

bbarker commented 1 month ago

I'm probably doing something wrong, but seem to be encountering this error.

I changed my flake as follows:

 {
   inputs = {
     nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
+    nixgl.url = "github:nix-community/nixGL";
     flake-utils.url = "github:numtide/flake-utils";
     rust-overlay.url = "github:oxalica/rust-overlay";
   };
-  outputs = { self, nixpkgs, flake-utils, rust-overlay }:
+  outputs = { self, nixpkgs, nixgl, flake-utils, rust-overlay }:
     flake-utils.lib.eachDefaultSystem
       (system:
         let
-          overlays = [ (import rust-overlay) ];
+          pkgsProto = import nixpkgs;
+          # isNixOS = pkgs.lib.hasPrefix "nixos" pkgs.stdenv.hostPlatform.system;
+          isNixOS = pkgsProto.lib.hasPrefix "nixos" pkgsProto.stdenv.hostPlatform.system;
+          overlays = [ (import rust-overlay) ] ++ (if isNixOS then [] else [
+            (import nixgl.overlay)
+          ]);
           pkgs = import nixpkgs {
             inherit system overlays;
           };
-          isNixOS = pkgs.lib.hasPrefix "nixos" pkgs.stdenv.hostPlatform.system;
         in
         with pkgs;

Sow now it looks like:

 {
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
    nixgl.url = "github:nix-community/nixGL";
    flake-utils.url = "github:numtide/flake-utils";
    rust-overlay.url = "github:oxalica/rust-overlay";
  };
  outputs = { self, nixpkgs, nixgl, flake-utils, rust-overlay }:
    flake-utils.lib.eachDefaultSystem
      (system:
        let
          pkgsProto = import nixpkgs;
          # isNixOS = pkgs.lib.hasPrefix "nixos" pkgs.stdenv.hostPlatform.system;
          isNixOS = pkgsProto.lib.hasPrefix "nixos" pkgsProto.stdenv.hostPlatform.system;
          overlays = [ (import rust-overlay) ] ++ (if isNixOS then [] else [
            (import nixgl.overlay)
          ]);
          pkgs = import nixpkgs {
            inherit system overlays;
          };
        in
        with pkgs;

Previously, this was working fine, including the rust overlay, but now I get:

$ nix develop --impure --show-trace
warning: Git tree '/home/bbarker/workspace/dotpenrose' is dirty
error:
       … <borked>

       … from call site

         at /nix/store/cryxp1zx3wgaih3lz3bnpzgqcn45mb4n-source/flake.nix:18:18:

           17|           ]);
           18|           pkgs = import nixpkgs {
             |                  ^
           19|             inherit system overlays;

       … while calling anonymous lambda

         at /nix/store/mcwr2j04fikfsrsaq76f4bviinvl6zql-source/pkgs/top-level/impure.nix:14:1:

           13|
           14| { # We put legacy `system` into `localSystem`, if `localSystem` was not passed.
             | ^
           15|   # If neither is passed, assume we are building packages on the current

       … from call site

         at /nix/store/mcwr2j04fikfsrsaq76f4bviinvl6zql-source/pkgs/top-level/impure.nix:87:1:

           86|
           87| import ./. (builtins.removeAttrs args [ "system" ] // {
             | ^
           88|   inherit config overlays localSystem;

       … while calling anonymous lambda

         at /nix/store/mcwr2j04fikfsrsaq76f4bviinvl6zql-source/pkgs/top-level/default.nix:19:1:

           18|
           19| { # The system packages will be built on. See the manual for the
             | ^
           20|   # subtle division of labor between these two `*System`s and the three

       … from call site

         at /nix/store/mcwr2j04fikfsrsaq76f4bviinvl6zql-source/pkgs/top-level/default.nix:55:5:

           54|   checked =
           55|     throwIfNot (lib.isList overlays) "The overlays argument to nixpkgs must be a list."
             |     ^
           56|     lib.foldr (x: throwIfNot (lib.isFunction x) "All overlays passed to nixpkgs must be functions.") (r: r) overlays

       … while calling 'throwIfNot'

         at /nix/store/mcwr2j04fikfsrsaq76f4bviinvl6zql-source/lib/trivial.nix:797:22:

          796|   */
          797|   throwIfNot = cond: msg: if cond then x: x else throw msg;
             |                      ^
          798|

       error: value is a function while a set was expected

I've also tried nixgl.overlay and (nixgl.overlay system) instead of (import nixgl.overlay), but seemingly with no better result.