Convert an Elm project into Nix expressions.
It consists of multiple commands:
elm2nix convert
: Givenelm.json
in current directory, all dependencies are parsed and their sha256sum calculatedelm2nix snapshot
: Downloads snapshot of https://package.elm-lang.org/all-packages json and converts into binaryregistry.dat
used by elm-compiler as a cacheelm2nix init
: Generatesdefault.nix
that glues everything together
Supports Elm 0.19.1
Make sure you have up to date stable or unstable nixpkgs channel.
$ nix-env -i elm2nix
$ git clone https://github.com/domenkozar/elm2nix.git
$ cd elm2nix
$ nix-env -if .
$ git clone https://github.com/evancz/elm-todomvc.git
$ cd elm-todomvc
$ elm2nix init > default.nix
$ elm2nix convert > elm-srcs.nix
# generates ./registry.dat
$ elm2nix snapshot
$ nix-build
$ chromium ./result/Main.html
$ ./scripts/tests.sh
As it's considered experimental, it's generated for now. Might change in the future.
Instead of running elm2nix init
, create a default.nix
with the following derivation:
{ pkgs ? import <nixpkgs> {}
}:
let
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 --dist-dir $out index.html
'';
}