diff options
author | William Carroll <wpcarro@gmail.com> | 2020-04-17T23·10+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-04-17T23·10+0100 |
commit | 39d084e493c80952d59cbcc92ea67f344e543298 (patch) | |
tree | e6c867937521644c7d5ffb0f4d4cb8bb2da53ae1 | |
parent | 277ad983d4d9caf51679d3c1c615ecc7134539be (diff) |
Use elm2nix to (attempt to) deploy learnpianochords.app
After a few failed attempts at deploying my Elm application on NixOS, I'm trying elm2nix, which some NixOS and Elm users created to attempt to solve some of the issues that I ran into earlier today. Elm tries to write to $HOME, which NixOS doesn't like. I typically prefer to avoid things like cabal2nix, elm2nix, node2nix because I don't like the workflow that they suggest, but I'm so eager to deploy this application, that I'm trying it.
-rw-r--r-- | website/sandbox/chord-drill-sergeant/default.nix | 70 | ||||
-rw-r--r-- | website/sandbox/chord-drill-sergeant/elm-srcs.nix | 67 | ||||
-rw-r--r-- | website/sandbox/chord-drill-sergeant/index.html | 2 | ||||
-rw-r--r-- | website/sandbox/chord-drill-sergeant/registry.dat | bin | 0 -> 93710 bytes |
4 files changed, 121 insertions, 18 deletions
diff --git a/website/sandbox/chord-drill-sergeant/default.nix b/website/sandbox/chord-drill-sergeant/default.nix index 7ea92c29f5c1..98f548e359d4 100644 --- a/website/sandbox/chord-drill-sergeant/default.nix +++ b/website/sandbox/chord-drill-sergeant/default.nix @@ -1,24 +1,60 @@ -{ pkgs, ... }: +{ pkgs ? <nixpkgs>, ... }: -pkgs.stdenv.mkDerivation { +with pkgs; + +let + mkDerivation = + { srcs ? ./elm-srcs.nix + , src + , name + , srcdir ? "./src" + , targets ? [] + , registryDat ? ./registry.dat + , outputJavaScript ? false + }: + stdenv.mkDerivation { + inherit name src; + + buildInputs = [ elmPackages.elm ] + ++ lib.optional outputJavaScript nodePackages_10_x.uglify-js; + + buildPhase = pkgs.elmPackages.fetchElmDeps { + elmPackages = import srcs; + elmVersion = "0.19.1"; + inherit registryDat; + }; + + installPhase = let + elmfile = module: "${srcdir}/${builtins.replaceStrings ["."] ["/"] module}.elm"; + extension = if outputJavaScript then "js" else "html"; + in '' + mkdir -p $out/share/doc + ${lib.concatStrings (map (module: '' + echo "compiling ${elmfile module}" + elm make ${elmfile module} --output $out/${module}.${extension} --docs $out/share/doc/${module}.json + ${lib.optionalString outputJavaScript '' + echo "minifying ${elmfile module}" + uglifyjs $out/${module}.${extension} --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' \ + | uglifyjs --mangle --output=$out/${module}.min.${extension} + ''} + '') targets)} + ''; + }; + mainDotElm = mkDerivation { + name = "elm-app-0.1.0"; + srcs = ./elm-srcs.nix; + src = ./.; + targets = ["Main"]; + srcdir = "./src"; + outputJavaScript = true; + }; +in stdenv.mkDerivation { name = "learn-piano-chords"; + buildInputs = []; src = ./.; - buildInputs = with pkgs; [ - elmPackages.elm - nodejs - ]; - outputHashMode = "recursive"; - outputHashAlgo = "sha256"; - outputHash = "0diya7q8ird56jsbf2p49fyvldsay6m9z251zr2rq1i4qs7idy0j"; - phases = [ "unpackPhase" "buildPhase" ]; buildPhase = '' - export NIX_REDIRECTS=/etc/protocols=${pkgs.iana-etc}/etc/protocols - export LD_PRELOAD=${pkgs.libredirect}/lib/libredirect.so - export SYSTEM_CERTIFICATE_PATH=${pkgs.cacert}/etc/ssl/certs - mkdir -p $out - cp index.html $out - elm make src/Main.elm --optimize --output=$out/elm.js - npx tailwindcss build index.css -o $out/output.css + cp index.html output.css ${mainDotElm}/Main.min.js $out ''; + dontInstall = true; } diff --git a/website/sandbox/chord-drill-sergeant/elm-srcs.nix b/website/sandbox/chord-drill-sergeant/elm-srcs.nix new file mode 100644 index 000000000000..2823b430f887 --- /dev/null +++ b/website/sandbox/chord-drill-sergeant/elm-srcs.nix @@ -0,0 +1,67 @@ +{ + + "elm-community/maybe-extra" = { + sha256 = "0qslmgswa625d218djd3p62pnqcrz38f5p558mbjl6kc1ss0kzv3"; + version = "5.2.0"; + }; + + "elm/html" = { + sha256 = "1n3gpzmpqqdsldys4ipgyl1zacn0kbpc3g4v3hdpiyfjlgh8bf3k"; + version = "1.0.0"; + }; + + "elm-community/random-extra" = { + sha256 = "1dg2nz77w2cvp16xazbdsxkkw0xc9ycqpkd032faqdyky6gmz9g6"; + version = "3.1.0"; + }; + + "elm/svg" = { + sha256 = "1cwcj73p61q45wqwgqvrvz3aypjyy3fw732xyxdyj6s256hwkn0k"; + version = "1.0.1"; + }; + + "elm/browser" = { + sha256 = "0nagb9ajacxbbg985r4k9h0jadqpp0gp84nm94kcgbr5sf8i9x13"; + version = "1.0.2"; + }; + + "elm/core" = { + sha256 = "19w0iisdd66ywjayyga4kv2p1v9rxzqjaxhckp8ni6n8i0fb2dvf"; + version = "1.0.5"; + }; + + "elm-community/list-extra" = { + sha256 = "1ayv3148drynqnxdfwpjxal8vwzgsjqanjg7yxp6lhdcbkxgd3vd"; + version = "8.2.3"; + }; + + "elm/random" = { + sha256 = "138n2455wdjwa657w6sjq18wx2r0k60ibpc4frhbqr50sncxrfdl"; + version = "1.0.0"; + }; + + "elm/time" = { + sha256 = "0vch7i86vn0x8b850w1p69vplll1bnbkp8s383z7pinyg94cm2z1"; + version = "1.0.0"; + }; + + "elm/json" = { + sha256 = "0kjwrz195z84kwywaxhhlnpl3p251qlbm5iz6byd6jky2crmyqyh"; + version = "1.1.3"; + }; + + "owanturist/elm-union-find" = { + sha256 = "13gm7msnp0gr1lqia5m7m4lhy3m6kvjg37d304whb3psn88wqhj5"; + version = "1.0.0"; + }; + + "elm/url" = { + sha256 = "0av8x5syid40sgpl5vd7pry2rq0q4pga28b4yykn9gd9v12rs3l4"; + version = "1.0.0"; + }; + + "elm/virtual-dom" = { + sha256 = "0q1v5gi4g336bzz1lgwpn5b1639lrn63d8y6k6pimcyismp2i1yg"; + version = "1.0.2"; + }; +} diff --git a/website/sandbox/chord-drill-sergeant/index.html b/website/sandbox/chord-drill-sergeant/index.html index d2218ea1905a..861ed1479522 100644 --- a/website/sandbox/chord-drill-sergeant/index.html +++ b/website/sandbox/chord-drill-sergeant/index.html @@ -4,7 +4,7 @@ <meta charset="UTF-8" /> <title>Chord Drill Sergeant</title> <link rel="stylesheet" href="./output.css" /> - <script src="./elm.js"></script> + <script src="./Main.min.js"></script> </head> <body class="font-serif"> <div id="mount"></div> diff --git a/website/sandbox/chord-drill-sergeant/registry.dat b/website/sandbox/chord-drill-sergeant/registry.dat new file mode 100644 index 000000000000..a73307ccda04 --- /dev/null +++ b/website/sandbox/chord-drill-sergeant/registry.dat Binary files differ |