elm2nix

Turn your Elm project into buildable Nix project

https://github.com/domenkozar/elm2nix#readme

Version on this page:0.3.0
LTS Haskell 21.25:0.3.1
Stackage Nightly 2024-10-05:0.4.0
Latest on Hackage:0.4.0

See all snapshots elm2nix appears in

BSD-3-Clause licensed by Domen Kozar
Maintained by [email protected]
This version can be pinned in stack with:elm2nix-0.3.0@sha256:660021d5a0bdaed1e46a95ca92f14c807126dcf95d6356a2ee50b434df757587,1882

Module documentation for 0.3.0

elm2nix

Build Status Hackage

Convert an Elm project into Nix expressions.

It consists of multiple commands:

  • elm2nix convert: Given elm.json in current directory, all dependencies are parsed and their sha256sum calculated
  • elm2nix snapshot: Downloads snapshot of http://package.elm-lang.org into versions.dat
  • elm2nix init: Generates default.nix that glues everything together

Assumptions

Supports Elm 0.19.1

Installation

From nixpkgs (recommended)

Make sure you have up to date stable or unstable nixpkgs channel.

$ nix-env -i elm2nix

From source

$ git clone https://github.com/domenkozar/elm2nix.git
$ cd elm2nix
$ nix-env -if .

Usage

$ git clone https://github.com/evancz/elm-todomvc.git
$ cd elm-todomvc
$ elm2nix init > default.nix
$ elm2nix convert > elm-srcs.nix
$ elm2nix snapshot > versions.dat
$ nix-build
$ chromium ./result/Main.html

Running tests (as per CI)

$ ./scripts/tests.sh

FAQ

Why is mkDerivation inlined into default.nix?

As it’s considered experimental, it’s generated for now. Might change in the future.

How to use with ParcelJS and Yarn?

Instead of running elm2nix init, use something like:

{ pkgs ? import <nixpkgs> {}
}:

let
  yarnPkg = pkgs.yarn2nix.mkYarnPackage {
    name = "myproject-node-packages";
    packageJSON = ./package.json;
    unpackPhase = ":";
    src = null;
    yarnLock = ./yarn.lock;
    publishBinsFor = ["parcel-bundler"];
  };
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;
    versionsDat = ./versions.dat;
  };

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

Changes

Changelog for elm2nix

0.3.0 (2022-09-06)

  • Prevent duplicates between src and test dependencies (@gpampara)
  • #48 Aeson 2 support (@gpampara)

0.2.1 (2020-11-22)

  • #40 Fix compatibility with newer versions of uglify.js (@turboMaCk)
  • #39 Switch to unversioned collection nodePackages for npm dependencies in default.nix (@ShrykeWindgrace)

0.2 (2019-12-28)

  • #35 Elm 0.19.1 support (@gpampara)

0.1.2 (2019-10-29)

  • #33 Minification of JS output (@turboMaCk)
  • #32 Make it possible to target JS output (@turboMaCk)
  • #31 Fetch test-dependencies (@prasmussen)

0.1.1 (2019-02-19)

Changes

  • #22 Support req-0.1.0.0 (@domenkozar)

0.1.0 (2018-12-28)

  • Initial release (@domenkozar)