nix-community / flakelight

Framework for simplifying flake setup [maintainer=@accelbread]
MIT License
177 stars 3 forks source link

Support devenv as default shell #1

Closed noverby closed 8 months ago

noverby commented 8 months ago

I'm trying to integrate flakelight with devenv, but flakelight does not seem to set pkgs for the default shell.

E.g. this works without any issues:

# nix/devShells.nix
{inputs, ...}: {
  test = {
    pkgs,
    bison,
  }:
    inputs.devenv.lib.mkShell {
      inherit inputs pkgs;
      modules = [
        {
          packages = [bison];
        }
      ];
    };
}

But setting the devenv shell as default makes pkgs not be exposed:

# nix/devShells.nix
{inputs, ...}: {
  default = {
    pkgs,
    bison,
  }:
    inputs.devenv.lib.mkShell {
      inherit inputs pkgs;
      modules = [
        {
          packages = [bison];
        }
      ];
    };
}

Returns error:

error: 'default' at /nix/store/mr9nzkj63fbn182x43xiz48vpzbr5yw7-source/nix/devShells.nix:2:13 called without required argument 'pkgs'
accelbread commented 8 months ago

Hi, thanks for the report; looking into this.

For future reference (once I set up unit tests), here is a minimal reproducer:

{
  inputs.flakelight.url = "github:accelbread/flakelight";
  outputs = { flakelight, ... }:
    flakelight ./. {
      devShells.default = { hello }: hello;
    };
}
accelbread commented 8 months ago

Fixed with fad306c58965fd33358c48f2b9d4931bd306cfb4 and e401f680302d4f9c353f4f08744bc69a1f903557.

The reason for the cryptic error was that the NixPkgs module system was merging the defined devshell with the built-in one. The merged function did not have named args, so callPackage did not provide args, and the merged function called the original package defs with no args.

Package definitions should not be merged since it does not make sense to do so, so fixed that by setting the merge function to mergeOneOption. Also made the built-in definition set with mkDefault, so that a user set default shell will take priority.