haskell-flake icon indicating copy to clipboard operation
haskell-flake copied to clipboard

Add documentation on manually specifying packages option when parsing cabal.project fails

Open ParetoOptimalDev opened this issue 2 years ago • 3 comments

Ideally I would have been able to search one of the error message texts:

A default value for packages cannot be auto-determined

or

Please specify the packages option manually or change your project configuration (cabal.project).

Perhaps this would belong in https://zero-to-flakes.com/gotchas

ParetoOptimalDev avatar Jul 26 '23 16:07 ParetoOptimalDev

Perhaps this would belong in https://zero-to-flakes.com/gotchas

It should be in haskell-flake docs itself ... possibly a setup.md under https://github.com/srid/haskell-flake/tree/master/doc/guide

srid avatar Jul 26 '23 18:07 srid

I would follow those instructions and add how to do this but I'm actually not sure :laughing:

Going by this from the comment in the scaffolded flake.nix:

          # Note that local packages are automatically included in `packages`
          # (defined by `defaults.packages` option).

leads me to these docs: https://flake.parts/options/haskell-flake.html#opt-perSystem.haskellProjects.name.defaults.packages

And seeing that packages seems to be "lazy attribute set of module" I should be able to follow the packages exmaple from the scaffolded flake.nix:

          # packages = { 
          #   aeson.source = "1.5.0.0"; # Hackage version override
          #   shower.source = inputs.shower; 
          # };

My guess I haven't been able to test yet is:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    haskell-flake.url = "github:srid/haskell-flake";
  };
  outputs = inputs@{ self, nixpkgs, flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      systems = nixpkgs.lib.systems.flakeExposed;
      imports = [ inputs.haskell-flake.flakeModule ];

      perSystem = { self', pkgs, ... }: {

        haskellProjects.default = {

          defaults.packages = {
            myproject.source = "0.0.1";
          };

        };

        packages.default = self'.packages.myproject;
      };
    };
}

I'm assuming though that if the cabal.project file can't be parsed there might still be things broken anyway though.

ParetoOptimalDev avatar Aug 02 '23 18:08 ParetoOptimalDev

I think what you want is:

      perSystem = { self', pkgs, ... }: {

        haskellProjects.default = {

          defaults.packages = {}; # Disable default packages
          packages = {
            myproject.source = "0.0.1";
          };

        };

        packages.default = self'.packages.myproject;
      };

(Of course you want to use something like myproject.source = ./myproject if you are trying to build a local package, rather than something from Hackage).

srid avatar Aug 03 '23 15:08 srid