Skip to content

Setting defaults.packages.<package-name> disables autowire #390

@Balint66

Description

@Balint66

Hello there!

I'm trying to set defaults.packages to be my local packages, and I'm able to do so, but then it seems like the autoWire attribute does not work.

Here is my flake.nix with the relevant parts:

{
    inputs = {
        # ...
        haskell-flake.url = "github:srid/haskell-flake";
        # ...
    };
    outputs = inp@{flake-parts, ...} : flake-parts.lib.mkFlake { inputs = inp; }  ({config, ... } : let
        conf = config;
    in {
        systems = [ "x86_64-linux"];
        imports = [
            inp.haskell-flake.flakeModule
            # ...
          ];
        flake = {
            haskellFlakeProjectModules.default = { pkgs, config, ... }: {
                         defaults.enable = true;
                         defaults.packages = {
                               eta-common = {
                                       source = ./common;
                                       local.toCurrentProject = true;
                                       local.toDefinedProject = true;
                                  };
                                  eta-frontend = {
                                      source = ./frontend;
                                      local.toCurrentProject = true;
                                      local.toDefinedProject = true;
                                  };
                         };
                         # ...
                         devShell = {
                           hlsCheck.enable = false;
                         };
            
                         # What should haskell-flake add to flake outputs?
                         autoWire = [ "packages" "apps" "checks" ]; # Wire all but the devShell
                       };
        };
        perSystem = { self', system, lib, config, pkgs, ... }: {

            haskellProjects.default = {
                imports = [
                  conf.flake.haskellFlakeProjectModules.default
                ];
                defaults.packages = {
                    eta-backend = {
                        source = ./backend;
                        local.toCurrentProject = true;
                        local.toDefinedProject = true;
                    };
                 };
                defaults.devShell.tools = hp: with hp; {
                   inherit
                     haskell-language-server;
                };
                basePackages = pkgs.haskell.packages.ghc983;
                # ...
                # Does not take effect
                autoWire = [ "packages" "apps" "checks" ];
              };
            haskellProjects.ghcjs = {
                imports = [
                  conf.flake.haskellFlakeProjectModules.default
                ];
                basePackages = pkgs.pkgsCross.ghcjs.haskell.packages.ghc983;
                autoWire = [];
                # ...
              };
            # Needed, because `autoWire` does not work
            # `packages` is empty here, but `finalPackages` contains the needed packages
            packages.default = config.haskellProjects.default.outputs.finalPackages.eta-backend;
            packages.frontend = config.haskellProjects.default.outputs.finalPackages.eta-frontend;
            # `autoWire` is disabled for ghcjs
            packages.frontendJS = config.haskellProjects.ghcjs.outputs.finalPackages.eta-frontend;

            # apps here is empty
            apps = config.haskellProjects.default.outputs.apps;
            # ...
         };   
    }); 
}

I've tried to go over the source code, but I was unable to pinpoint where the problem occurs.

I've read in the discussions that I should use packages instead of defaults.packages but as I understand it, that would prevent autowireing too.

I'm aware that I could use a cabal.project file for my multi-project, but as you can see, I'd like to exclude the backend package from building when I'm using the javascript ghc backend and with the basic support for the project files this is not possible.

Thank you in advance for your help, and for your work on this great module!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions