cachix / elm2nix

Convert Elm project into Nix expressions
BSD 3-Clause "New" or "Revised" License
109 stars 17 forks source link

error trying to follow steps for parcel #49

Open goosetherumfoodle opened 1 year ago

goosetherumfoodle commented 1 year ago

I have a barebones elm app I'm trying to build with parcel using the steps in the readme here. I had to update the fetchElmDeps attributes as the readme was outdated.

      configurePhase = nixpkgs.legacyPackages.${system}.elmPackages.fetchElmDeps {
        elmVersion = "0.19.1";
        elmPackages = import ./elm-srcs.nix;
        registryDat = ./registry.dat;
      };

I then followed the steps at https://blog.hercules-ci.com/elm/2019/01/03/elm2nix-0.1/ to generate elm-srcs.nix, registry.dat and versions.dat. (The new fetchElmDeps doesn't seem to require versions.dat, is that just no longer used?)

But running nix build throws an error during the configurePhase:

@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
mv: cannot copy a directory, '/build', into itself, '/build/temp'
greglearns commented 1 year ago

+1 Did you ever figure out how to do this with parcel? Would love to hear a solution -- trying to solve this now myself.

sandydoo commented 1 year ago

Here's an example of how to get a build with the current versions of parcel and yarn2nix:

{
  description = "A very basic flake";

  outputs = { self, nixpkgs }: {
    # A dev shell to use elm2nix
    devShells.aarch64-linux.default = 
      let pkgs = nixpkgs.legacyPackages.aarch64-linux;
      in pkgs.mkShell {
        packages = [ pkgs.elm2nix ];
      };

    packages.aarch64-linux.default = 
      let
        pkgs = nixpkgs.legacyPackages.aarch64-linux;

        yarnPkg = pkgs.mkYarnPackage {
          name = "myproject-node-packages";
          src = pkgs.lib.cleanSourceWith {
            src = ./.;
            name = "myproject-node-packages.json";
            filter = name: type: baseNameOf (toString name) == "package.json";
          };
          yarnLock = ./yarn.lock;
          publishBinsFor = ["parcel"];
        };
      in pkgs.stdenv.mkDerivation {
        name = "myproject-frontend";
        src = pkgs.lib.cleanSource ./.;

        buildInputs = with pkgs.elmPackages; [
          elm
          elm-format
          yarnPkg
          pkgs.yarn
        ];

        patchPhase = ''
          rm -rf elm-stuff
          ln -sf ${yarnPkg}/node_modules .
        '';

        shellHook = ''
          ln -fs ${yarnPkg}/node_modules .
        '';

        configurePhase = pkgs.elmPackages.fetchElmDeps {
          elmPackages = import ./elm-srcs.nix;
          elmVersion = "0.19.1";
          registryDat = ./registry.dat;
        };

        installPhase = ''
          mkdir -p $out
          parcel build index.html --dist-dir $out
        '';
      };
  };
}