mlabs-haskell / lambda-buffers

LambdaBuffers toolkit for sharing types and their semantics between different languages
https://mlabs-haskell.github.io/lambda-buffers/
Apache License 2.0
29 stars 0 forks source link

Updating packages #82

Closed bladyjoker closed 1 year ago

bladyjoker commented 1 year ago

DONE

bladyjoker commented 1 year ago

pre-commit-hook.nix provides its own flake-parts module, here an example of how to use it. Again, what you did is not wrong but you are not properly exploiting flake-parts.

Check out https://github.com/mlabs-haskell/lambda-buffers/pull/82/commits/31d38ac5e548cd6394484d19014a964b1e095e21 where I tried to do a module on pre-commit stuff.

bladyjoker commented 1 year ago

You define a pkgs at line 27 when you have pkgs as perSystem's argument. You probably do this because you need a pkgs "instance" with some overlays applied but this means that you would need to redo this in every module. I faced the same problem in the past and I came up with something like the following. It's also a nice example on how to use flake-parts idiomatically.

Ok, that looks proper. I still don't know exactly how I would extract 'common' stuff into a new module, concretely:

  1. All haskell modules should use the overlaid pkgs,
  2. All modules should append the pre-commit installationScript to their shellHook
  3. All haskell modules should use a specific compiler and index-state

I imagine I need to create a small module with default options and then instantiate such a module.

bladyjoker commented 1 year ago

If you look at all the build.nix files in haskell directories you'll see:

{ pkgs
, haskell-nix
, mlabs-tooling
, compiler-nix-name
, index-state
, compilerHsPb
, commonTools
, shellHook
}:
let
  inherit pkgs;
  project = {
    src = ./.;

    name = "lambda-buffers-compiler";

    inherit compiler-nix-name index-state;

    extraHackage = [
      "${compilerHsPb}"
    ];

    modules = [
      (_: {
        packages = {
          allComponent.doHoogle = true;
          allComponent.doHaddock = true;

          # Enable strict compilation
          lambda-buffers-compiler.configureFlags = [ "-f-dev" ];
        };
      })
    ];

    shell = {

      withHoogle = true;

      exactDeps = true;

      nativeBuildInputs = [ pkgs.swiPrologWithGui ] ++ builtins.attrValues commonTools;

      tools = {
        cabal = { };
        haskell-language-server = { };
      };

      shellHook = ''
        export LC_CTYPE=C.UTF-8
        export LC_ALL=C.UTF-8
        export LANG=C.UTF-8
        ${shellHook}
      '';
    };
  };
in
{
  hsNixProj = haskell-nix.cabalProject' [
    mlabs-tooling.lib.mkHackageMod
    project
  ];
}

which is tedious to maintain. I'd ideally refactor all that in a module and then have my build.nix files just specify the 'uncommon' stuff, here that would be:

project = {
      name = "lambda-buffers-compiler";     
      nativeBuildInputs = [ pkgs.swiPrologWithGui ] ++ builtins.attrValues commonTools;
}
bladyjoker commented 1 year ago

Thanks @aciceri