swarm-game / swarm

Resource gathering + programming game
Other
837 stars 52 forks source link

Nix setup #254

Closed sureyeaah closed 3 years ago

sureyeaah commented 3 years ago

Is your feature request related to a problem? Please describe. I am on Nixos but am not sure how to setup swarm.

Describe the solution you'd like A flake.nix/shell.nix with the project building and HLS working.

Describe alternatives you've considered I tried using IOHK haskell nix setup but failed so far.

I crated this flake.nix:

{
  description = "Swarm";
  inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
  inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  outputs = { self, nixpkgs, flake-utils, haskellNix }:
    flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system:
    let
      overlays = [ haskellNix.overlay
        (final: prev: {
          # This overlay adds our project to pkgs
          swarmProject =
            final.haskell-nix.project' {
              src = ./.;
              compiler-nix-name = "ghc8107";
              # This is used by `nix develop .` to open a shell for use with
              # `cabal`, `hlint` and `haskell-language-server`
              shell.tools = {
                cabal = {};
                hlint = {};
                haskell-language-server = {};
              };
              # Non-Haskell shell tools go here
              shell.buildInputs = with pkgs; [
                nixpkgs-fmt
              ];
              # This adds `js-unknown-ghcjs-cabal` to the shell.
              shell.crossPlatform = p: [p.ghcjs];
              projectFileName = "cabal.project";
            };
        })
      ];
      pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };
      flake = pkgs.swarmProject.flake {
        # This adds support for `nix build .#js-unknown-ghcjs-cabal:swarm:exe:swarm`
        crossPlatforms = p: [p.ghcjs];
      };
    in flake // {
      # Built by `nix build .`
      defaultPackage = flake.packages."swarm:exe:swarm";
    });
}

nix build . failed with:

trace: No index state specified for haskell-project, using the latest index state that we know about (2021-10-17T00:00:00Z)!
trace: WARNING: No sha256 found for source-repository-package https://github.com/colinhect/hsnoise 4ccff11dea7e8d94e6a5fcaf8f43857bd65bd72d download may fail in restricted mode (hydra)
error: in pure evaluation mode, 'fetchTree' requires an immutable input, at /nix/store/902xmngbx33f3m8jl74sr1llkd2cld24-source/lib/call-cabal-project-to-nix.nix:183:25
(use '--show-trace' to show detailed location information)

I added the following:

              sha256map =
                { "https://github.com/colinhect/hsnoise"."4ccff11dea7e8d94e6a5fcaf8f43857bd65bd72d" = "054az3r243xp1wrbha2fjbl6syr99765d3rrp5an98lkpmfvxc38"; };

But that led to this error:

trace: No index state specified for haskell-project, using the latest index state that we know about (2021-10-17T00:00:00Z)!
error: attribute 'https://github.com/mokus0/th-extras' missing

       at /nix/store/902xmngbx33f3m8jl74sr1llkd2cld24-source/modules/cabal-project.nix:111:37:

          110|       default = if config.sha256map != null
          111|         then { location, tag, ...}: config.sha256map.${location}.${tag}
             |                                     ^
          112|         else _: null;
(use '--show-trace' to show detailed location information)
byorgey commented 3 years ago

Hi @sureyeaah , check out #80 and #169 , hopefully there's enough info there for you to figure it out!

TristanCacqueray commented 3 years ago

@sureyeaah it seems like you can try adding the sha256 in the cabal.project file as documented in https://input-output-hk.github.io/haskell.nix/tutorials/source-repository-hashes/#cabalproject

sureyeaah commented 3 years ago

Thanks Brent and Tristan, gonna follow those guides.