Clash error Could not find module ‘GHC.TypeLits.KnownNat.Solver’

this my flake.nix


  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };
  outputs = {
    self,
    nixpkgs,
    flake-utils,
  }:
    flake-utils.lib.eachDefaultSystem
    (
      system: let
        pkgs = import nixpkgs {
          inherit system;
          config.allowBroken = true;
        };
      in {
        # flake contents here
        devShells = {
          default = pkgs.mkShell {
            buildInputs = with pkgs; [
              pkg-config
              cabal-install
              ghc
              haskellPackages.clash-ghc
              haskellPackages.ghc-typelits-knownnat
            ];
          };
        };
      }
    );
}

when i run clash --interactive FIR.hs it error, the FIR.hs is from https://raw.github.com/clash-lang/clash-compiler/master/examples/FIR.hs

❯ clash --interactive FIR.hs

when making flags consistent: warning:
    Optimization flags are incompatible with the byte-code interpreter; optimization flags ignored.
Clashi, version 1.8.1 (using clash-lib, version 1.8.1):
https://clash-lang.org/  :? for help
<command line>: Could not find module ‘GHC.TypeLits.KnownNat.Solver’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.

I don’t think it generally makes sense to add the ghc-typelits-knownnat Haskell package here. It won’t really “do anything” here.

I don’t know anything about clash, but my guess is that clash has some sort of internal GHC it is using to do something. You need to somehow make sure that internal clash GHC has a package database with ghc-typelits-knownnat available.

Since I’m not sure how clash works, I’m not sure exactly what to suggest, but the first thing I might try is:

        devShells = {
          default = pkgs.mkShell {
            buildInputs = with pkgs; [
              pkg-config
              cabal-install
              (haskellPackages.ghcWithPackages (p: [p.ghc-typelits-knownnat]))
              haskellPackages.clash-ghc
            ];
          };

From within your devshell, you should be able to run ghc-pkg list and confirm that the ghc-typelits-knownnat package is available. This should hopefully make it available when you run clash (but again, I have no idea how clash works, so this suggestion might be completely incorrect).

yes, i try it,it works, thanks.

1 Like