Hot reload for Elm application #6

Merged
Yehowshua merged 3 commits from nix-frontend-hot-reload into main 2025-02-02 20:58:57 +00:00
2 changed files with 25 additions and 2 deletions
Showing only changes of commit 158174d756 - Show all commits

View file

@ -99,6 +99,29 @@
} }
) )
) { }; ) { };
elm-go = prev.callPackage (
{
lib,
buildNpmPackage,
elmPackages,
}:
buildNpmPackage {
name = "elm-go";
version = "5.0.20";
src = pkgs.fetchFromGitHub {
owner = "lucamug";
repo = "elm-go";
rev = "9a7bd8c980a03b026128fcd626b9395b4e2cb1e0";
sha256 = "sha256-B5Cngv8EGOY79u9aZeixA3EBt8rIc6bkYA4zoqycpk8=";
};
npmDepsHash = "sha256-0LfLpUbav8cVoZ9/Cjb7Mr8jdo1/KjVcjR4lcYB3AzY=";
dontNpmBuild = true;
makeWrapperArgs = [
"--suffix PATH : ${lib.makeBinPath [ elmPackages.elm ]}"
];
}
) { };
azkarim marked this conversation as resolved Outdated

So you're technically not supposed to install things inside nix build files that require internet access. To fix this, we should either use elmPackages.elm-live or have @Artturin package up the elm-live fork, elm-go.

So you're technically not supposed to install things inside nix build files that require internet access. To fix this, we should either use [elmPackages.elm-live](https://search.nixos.org/packages?channel=24.11&show=elmPackages.elm-live&from=0&size=50&sort=relevance&type=packages&query=elm-live) or have @Artturin package up the elm-live fork, [elm-go](https://github.com/lucamug/elm-go).

I will add elmPackages.elm-live

I will add `elmPackages.elm-live`

So you're technically not supposed to install things inside nix build files that require internet access. To fix this, we should either use elmPackages.elm-live or have @Artturin package up the elm-live fork, elm-go.

This is a mkShell shellHook, which runs commands outside the build sandbox so using the internet is fine but running a package managers install commands is still unhygienic.

Here's a patch adding elm-go which can then be used with pkgs.elm-go

diff --git a/flake.nix b/flake.nix
index aa446c5..59789cc 100644
--- a/flake.nix
+++ b/flake.nix
@@ -99,6 +99,29 @@
                   }
                 )
               ) { };
+
+              elm-go = prev.callPackage (
+                {
+                  lib,
+                  buildNpmPackage,
+                  elmPackages,
+                }:
+                buildNpmPackage {
+                  name = "elm-go";
+                  version = "5.0.20";
+                  src = pkgs.fetchFromGitHub {
+                    owner = "lucamug";
+                    repo = "elm-go";
+                    rev = "9a7bd8c980a03b026128fcd626b9395b4e2cb1e0";
+                    sha256 = "sha256-B5Cngv8EGOY79u9aZeixA3EBt8rIc6bkYA4zoqycpk8=";
+                  };
+                  npmDepsHash = "sha256-0LfLpUbav8cVoZ9/Cjb7Mr8jdo1/KjVcjR4lcYB3AzY=";
+                  dontNpmBuild = true;
+                  makeWrapperArgs = [
+                    "--suffix PATH : ${lib.makeBinPath [ elmPackages.elm ]}"
+                  ];
+                }
+              ) { };
             })
           ];
         };
> So you're technically not supposed to install things inside nix build files that require internet access. To fix this, we should either use [elmPackages.elm-live](https://search.nixos.org/packages?channel=24.11&show=elmPackages.elm-live&from=0&size=50&sort=relevance&type=packages&query=elm-live) or have @Artturin package up the elm-live fork, [elm-go](https://github.com/lucamug/elm-go). This is a `mkShell` `shellHook`, which runs commands outside the build sandbox so using the internet is fine but running a package managers install commands is still unhygienic. Here's a patch adding elm-go which can then be used with `pkgs.elm-go` ```diff diff --git a/flake.nix b/flake.nix index aa446c5..59789cc 100644 --- a/flake.nix +++ b/flake.nix @@ -99,6 +99,29 @@ } ) ) { }; + + elm-go = prev.callPackage ( + { + lib, + buildNpmPackage, + elmPackages, + }: + buildNpmPackage { + name = "elm-go"; + version = "5.0.20"; + src = pkgs.fetchFromGitHub { + owner = "lucamug"; + repo = "elm-go"; + rev = "9a7bd8c980a03b026128fcd626b9395b4e2cb1e0"; + sha256 = "sha256-B5Cngv8EGOY79u9aZeixA3EBt8rIc6bkYA4zoqycpk8="; + }; + npmDepsHash = "sha256-0LfLpUbav8cVoZ9/Cjb7Mr8jdo1/KjVcjR4lcYB3AzY="; + dontNpmBuild = true; + makeWrapperArgs = [ + "--suffix PATH : ${lib.makeBinPath [ elmPackages.elm ]}" + ]; + } + ) { }; }) ]; }; ```

So you're technically not supposed to install things inside nix build files that require internet access. To fix this, we should either use elmPackages.elm-live or have @Artturin package up the elm-live fork, elm-go.

This is a mkShell shellHook, which runs commands outside the build sandbox so using the internet is fine but running a package managers install commands is still unhygienic.

Here's a patch adding elm-go which can then be used with pkgs.elm-go

diff --git a/flake.nix b/flake.nix
index aa446c5..59789cc 100644
--- a/flake.nix
+++ b/flake.nix
@@ -99,6 +99,29 @@
                   }
                 )
               ) { };
+
+              elm-go = prev.callPackage (
+                {
+                  lib,
+                  buildNpmPackage,
+                  elmPackages,
+                }:
+                buildNpmPackage {
+                  name = "elm-go";
+                  version = "5.0.20";
+                  src = pkgs.fetchFromGitHub {
+                    owner = "lucamug";
+                    repo = "elm-go";
+                    rev = "9a7bd8c980a03b026128fcd626b9395b4e2cb1e0";
+                    sha256 = "sha256-B5Cngv8EGOY79u9aZeixA3EBt8rIc6bkYA4zoqycpk8=";
+                  };
+                  npmDepsHash = "sha256-0LfLpUbav8cVoZ9/Cjb7Mr8jdo1/KjVcjR4lcYB3AzY=";
+                  dontNpmBuild = true;
+                  makeWrapperArgs = [
+                    "--suffix PATH : ${lib.makeBinPath [ elmPackages.elm ]}"
+                  ];
+                }
+              ) { };
             })
           ];
         };

@Artturin Thanks

> > So you're technically not supposed to install things inside nix build files that require internet access. To fix this, we should either use [elmPackages.elm-live](https://search.nixos.org/packages?channel=24.11&show=elmPackages.elm-live&from=0&size=50&sort=relevance&type=packages&query=elm-live) or have @Artturin package up the elm-live fork, [elm-go](https://github.com/lucamug/elm-go). > > This is a `mkShell` `shellHook`, which runs commands outside the build sandbox so using the internet is fine but running a package managers install commands is still unhygienic. > > Here's a patch adding elm-go which can then be used with `pkgs.elm-go` > > ```diff > diff --git a/flake.nix b/flake.nix > index aa446c5..59789cc 100644 > --- a/flake.nix > +++ b/flake.nix > @@ -99,6 +99,29 @@ > } > ) > ) { }; > + > + elm-go = prev.callPackage ( > + { > + lib, > + buildNpmPackage, > + elmPackages, > + }: > + buildNpmPackage { > + name = "elm-go"; > + version = "5.0.20"; > + src = pkgs.fetchFromGitHub { > + owner = "lucamug"; > + repo = "elm-go"; > + rev = "9a7bd8c980a03b026128fcd626b9395b4e2cb1e0"; > + sha256 = "sha256-B5Cngv8EGOY79u9aZeixA3EBt8rIc6bkYA4zoqycpk8="; > + }; > + npmDepsHash = "sha256-0LfLpUbav8cVoZ9/Cjb7Mr8jdo1/KjVcjR4lcYB3AzY="; > + dontNpmBuild = true; > + makeWrapperArgs = [ > + "--suffix PATH : ${lib.makeBinPath [ elmPackages.elm ]}" > + ]; > + } > + ) { }; > }) > ]; > }; > ``` @Artturin Thanks
}) })
]; ];
}; };
@ -114,7 +137,7 @@
mkShell { mkShell {
inputsFrom = [ example-spa-elm-app ]; inputsFrom = [ example-spa-elm-app ];
buildInputs = [ buildInputs = [
elmPackages.elm-live elm-go
]; ];
}; };
} }

View file

@ -21,7 +21,7 @@ endif
serve: serve:
ifeq ($(DEBUG),1) ifeq ($(DEBUG),1)
elm-live src/Main.elm --port=8000 --dir=../public --start-page=index.html -- --output=../public/elm.min.js elm-go src/Main.elm --port=8000 --dir=../public --start-page=index.html -- --output=../public/elm.min.js
else ifeq ($(RELEASE),1) else ifeq ($(RELEASE),1)
$(error Cannot use serve target with RELEASE=1) $(error Cannot use serve target with RELEASE=1)
endif endif