Skip to content

mkElmWatchDerivation

James Leslie edited this page Apr 29, 2023 · 3 revisions

The overlay mkElmWatchDerivation provides a function mkElmWatchDerivation, which runs elm-watch and returns the built targets, in their relative directory. For example, if a target has an output build/main.js, then it will be built into $out/build.js. It is also important to note that this function can only build targets that output a relative path. If the output path begins with ., /, or ~, then this flake will ignore it.

This is the attribute set that the function takes in.

{
  # The name of the elm project.
  pname

  # The version of the elm project.
, version

  # The base directory of your elm project (most likely ./.).
, src

  # Optional: The elm project's elm.json file. Will default to
  # ${src}/elm.json
, elmJson ? "${src}/elm.json"

  # Optional: The arguments passed to elm-watch make. Either
  # "--optimize", "--debug" or "". Defaults to "--optimize".
, option ? "--optimize"

  # Optional: The target names to build. Leave this empty to build all
  # targets. Defaults to [].
, targets ? [] # List of strings
, ...
}

Here is an example flake using the overlay:

{
  description = "An elm-watch application, packaged with the mkElmWatchDerivation overlay.";

  inputs = {
    nixpkgs.url = github:nixos/nixpkgs/nixpkgs-unstable;
    mkElmDerivation.url = github:jeslie0/mkElmDerivation;
  };

  outputs = { self, nixpkgs, mkElmDerivation }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        overlays = [ mkElmDerivation.overlays.mkElmWatchDerivation ];
        inherit system;
      };
    in
      {
        packages.${system}.default = pkgs.mkElmWatchDerivation {
          pname = "my-elm-watch-app";
          version = "0.1.0";
          src = ./.;
        };
      };
}
Clone this wiki locally