diff mbox series

[bug#55030,v2,22/34] gnu: elm: Support 'elm reactor'.

Message ID 1a6669a4b3f0364cb0686e4ff70a0cdc44b53de6.1652890702.git.philip@philipmcgrath.com
State Accepted
Headers show
Series gnu: elm: Update to 0.19.1. Add build system & importer. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Philip McGrath May 18, 2022, 6:11 p.m. UTC
* gnu/packages/elm.scm (elm): Rename to ...
(elm-sans-reactor): ... this new variable.
[synopsis, description]: Tweak.
(elm): New variable.
* guix/build-system/elm.scm (default-elm): Use elm-sans-reactor.
* doc/guix.texi (Build Systems)[elm-build-system]: Update accordingly.
---
 doc/guix.texi             |  7 ++--
 gnu/packages/elm.scm      | 75 +++++++++++++++++++++++++++++++++++++--
 guix/build-system/elm.scm |  2 +-
 3 files changed, 79 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/doc/guix.texi b/doc/guix.texi
index d7bc7523cd..282cddf798 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -8724,7 +8724,7 @@  Build Systems
 @samp{elm install}.
 
 The build system adds an Elm compiler package to the set of inputs.  The
-default compiler package (currently @code{elm}) can be overridden
+default compiler package (currently @code{elm-sans-reactor}) can be overridden
 using the @code{#:elm} argument.  Additionally, Elm packages needed by the
 build system itself are added as implicit inputs if they are not already
 present: to suppress this behavior, use the
@@ -8747,7 +8747,10 @@  Build Systems
 Elm @dfn{projects} which declare @code{@{ "type": "package" @}} in their
 @file{elm.json} files.  Using @code{elm-build-system} to build Elm
 @dfn{applications} (which declare @code{@{ "type": "application" @}}) is
-possible, but requires ad-hoc modifications to the build phases.
+possible, but requires ad-hoc modifications to the build phases.  For
+an example, see the definition of
+the @code{elm} package itself (because the front-end for the
+@samp{elm reactor} command is an Elm application).
 
 @item
 Elm supports multiple versions of a package coexisting simultaneously under
diff --git a/gnu/packages/elm.scm b/gnu/packages/elm.scm
index 8f92eea041..d515d68e8f 100644
--- a/gnu/packages/elm.scm
+++ b/gnu/packages/elm.scm
@@ -40,9 +40,9 @@  (define-module (gnu packages elm)
 ;; `elm reactor` exit with a useful error message if they aren't there.
 (define %reactor-root-base
   "share/elm/reactor-")
-(define-public elm
+(define-public elm-sans-reactor
   (package
-    (name "elm")
+    (name "elm-sans-reactor")
     (version "0.19.1")
     (source
      (origin
@@ -93,6 +93,77 @@  (define-public elm
            ghc-vector
            ghc-zip-archive))
     (home-page "https://elm-lang.org")
+    (synopsis "Minimal variant of @command{elm}")
+    (description
+     "This package provides a version of the Elm compiler without support for
+the @command{elm reactor} development command.")
+    (license license:bsd-3)))
+
+(define-public elm
+  (package
+    (name "elm")
+    (version (package-version elm-sans-reactor))
+    (source (package-source elm-sans-reactor))
+    (native-inputs (list elm-sans-reactor))
+    (inputs (list elm-sans-reactor
+                  elm-browser
+                  elm-core
+                  elm-html
+                  elm-http
+                  elm-json
+                  elm-project-metadata-utils
+                  elm-svg
+                  elm-explorations-markdown))
+    (build-system elm-build-system)
+    (arguments
+     (list
+      #:modules
+      `((srfi srfi-26)
+        ,@%elm-default-modules)
+      #:phases
+      #~(modify-phases %standard-phases
+          (delete 'stage)
+          (replace 'configure
+            (lambda* (#:key native-inputs inputs #:allow-other-keys)
+              (with-directory-excursion "reactor"
+                (patch-application-dependencies))))
+          (replace 'build
+            (lambda* (#:key native-inputs inputs #:allow-other-keys)
+              (with-directory-excursion "reactor"
+                (invoke (search-input-file (or native-inputs inputs)
+                                           "/bin/elm")
+                        "make"
+                        "--optimize"
+                        "src/NotFound.elm"
+                        "src/Errors.elm"
+                        "src/Index.elm"))))
+          (replace 'install
+            (lambda* (#:key inputs #:allow-other-keys)
+              (let* ((out-dir #$output)
+                     (bin-dir (string-append out-dir "/bin"))
+                     (reactor-dir (string-append out-dir
+                                                 "/"
+                                                 #$%reactor-root-base
+                                                 (getenv "GUIX_ELM_VERSION")))
+                     (reactor-subdir (string-append reactor-dir "/_elm")))
+                ;; We can't use a symlink here because Haskell's
+                ;; `getExecutablePath` follows all symlinks.
+                ;; Guix can make it a hard link later.
+                (install-file (search-input-file inputs ;; NOT native-inputs
+                                                 "/bin/elm")
+                              bin-dir)
+                (install-file "reactor/assets/favicon.ico" reactor-dir)
+                (for-each (cut install-file <> reactor-subdir)
+                          '("reactor/elm.js"
+                            "reactor/assets/styles.css"
+                            ;; TODO: these are source-code-pro v1.017 and
+                            ;; source-sans-pro v1.050: there may be breaking
+                            ;; changes in Guix's existing
+                            ;; font-adobe-source-{code,sans}-pro packages
+                            "reactor/assets/source-code-pro.ttf"
+                            "reactor/assets/source-sans-pro.ttf")))))
+          (delete 'validate-compiled))))
+    (home-page "https://elm-lang.org")
     (synopsis "Programming language for Web applications")
     (description
      "Elm is a statically-typed, purely-functional programming language for
diff --git a/guix/build-system/elm.scm b/guix/build-system/elm.scm
index 293bcbfb64..f5321f811b 100644
--- a/guix/build-system/elm.scm
+++ b/guix/build-system/elm.scm
@@ -101,7 +101,7 @@  (define (default-elm)
   "Return the default Elm package for builds."
   ;; Lazily resolve the binding to avoid a circular dependency.
   (let ((elm (resolve-interface '(gnu packages elm))))
-    (module-ref elm 'elm)))
+    (module-ref elm 'elm-sans-reactor)))
 
 (define (default-elm-core)
   "Return the default elm-core package."