• Stars
    star
    105
  • Rank 317,145 (Top 7 %)
  • Language
    Haskell
  • License
    BSD 3-Clause "New...
  • Created over 6 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convert Elm project into Nix expressions

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 https://package.elm-lang.org/all-packages json and converts into binary registry.dat used by elm-compiler as a cache
  • 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
# generates ./registry.dat
$ elm2nix snapshot
$ 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 do I use elm2nix with ParcelJS and Yarn?

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
  '';
}

More Repositories

1

devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
Nix
3,227
star
2

cachix

Command line client for Nix binary cache hosting:
Haskell
733
star
3

git-hooks.nix

Seamless integration of https://pre-commit.com git hooks with Nix.
Nix
434
star
4

install-nix-action

Installs Nix on GitHub Actions for the supported platforms: Linux and macOS.
Shell
418
star
5

cachix-action

Build software only once and put it in a global cache
TypeScript
209
star
6

nixpkgs-python

All Python versions, kept up-to-date on hourly basis using Nix.
Nix
106
star
7

ghcide-nix

Nix installation for ghcide
Nix
76
star
8

docs.cachix.org

Documentation for Cachix service.
Python
58
star
9

cachix-deploy-hetzner-dedicated

Bootstrap Hetzner Dedicated machines with a single command and deploy using GitHub Actions
Nix
22
star
10

stamina.hs

Retrying for humans using Haskell.
Haskell
20
star
11

haskell-release-action

Automation for releasing haskell packages
17
star
12

paddle

Haskell API for Paddle payments
Haskell
11
star
13

nixpkgs-unfree-redistributable

Nix
6
star
14

cachix-ci-agents

self-hosted github runners
Nix
6
star
15

katip-raven

Katip scribe for raven client (https://sentry.io)
Haskell
5
star
16

cachix-deploy-flake

Functions to help manage Cachix Deploy when using flakes.
Nix
5
star
17

clickhouse-haskell

Haskell
4
star
18

websockets-simple

High-level library for Client/Server websocket communication in Haskell
Haskell
3
star
19

mixpanel-client

Haskell client implementation of mixpanel HTTP api
Haskell
3
star
20

fastspring

Haskell API for https://fastspring.com/
Haskell
3
star
21

cachix-deploy-terraform

HCL
2
star
22

buildkite-example

2
star
23

travis-ci-example

Nix
2
star
24

circleci-example

Nix
2
star
25

feedback

Feedback about https://cachix.org service
2
star
26

cachix-deploy-amis

AMIs for using Cachix Deploy
HCL
1
star
27

haskell-wishlist

Things we wish Haskell had
1
star
28

cachix-deploy-aws

HCL
1
star
29

parse-range-header.js

TypeScript
1
star
30

fastcdc-rs2hs

A Haskell wrapper around fastcdc-rs.
Haskell
1
star