Creating a Nix package for a basic Liveview app

Simple question from someone who loves both NixOS and Elixir…

Is there someone around here that is able to do these two simple things:

  • Generate a basic Liveview app
  • Package it for Nix, ideally in a flake

That’s it… no extra code whatsoever. I’ve been spending a unholy amount of time trying to realize that achievement but have been failing so far.

The main problem revolves around the fact that the heroicons dependency is directly linked to GitHub instead of the hex package manager.

My whole infra is based on NixOS, so, I am considering quitting Elixir just to be able to get things done.

2 Likes

Do you mid sharing a minimal project that shows the problem?

I do not remember having had any problems when I packaged a small, fresh from the generator, application about a year ago.

2 Likes

I have such a project here: GitHub - Munksgaard/flakify

Right now, it just creates a flake.nix containing a devshell, but I have plans to extend it with a package output building the phoenix application.

2 Likes

I just made the simplest possible way to achieve what I am talking about here:

In short, it’s a brand new Phoenix Liveview app with no extra code, along with 3 nix files.

It’s all explained in the README.md, including the output of a failed attempt.

1 Like

Making a development environment is working great.

Works out of the box with the above repo just by typing nix develop.

Problem arises when I try to create a derivation out of the app.

Yep. That’s on my todo-list. I’ll see if I can get something workable out later this week.

1 Like

A working fork or pull request of this very project would be VERY appreciated. Thanks!

1 Like

I have a setup here that I use for deployments: GitHub - Zurga/phoenix_nix

1 Like

I’ve just released version v0.3.0 of flakify. Take a look: Flakify — flakify v0.3.0

2 Likes

This is pretty cool! I might incorporate some of your ideas in flakify, if you don’t mind.

Yes, sure. Send me a message if you have any questions.

1 Like

In theory, this is exactly what I needed, thank you very much!

Although, it actually crashes on my plain Phoenix Liveview app with added nix files: GitHub - RooSoft/nix_package: Attempt to package a Phoenix LiveView app for Nix

Steps I made (note that I started by removing all nix files):

rm *.nix mix archive.install hex igniter_new mix igniter.install flakify --package 

Result:

** (Protocol.UndefinedError) protocol Enumerable not implemented for type Rewrite (a struct). This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Req.Response.Async, Stream 

Maybe adding to the docs that mix archive.install hex igniter_new is required. I had to figure out that part as I’ve never used igniter in the past.

Works perfectly on brand new projects, though… back at getting things done.

Thank you @munksgaard!

1 Like

That’s strange. I didn’t get any errors when I tried to run it in your repo. Do you have any more details on the error, such as a stack trace?

Nevermind… maybe I was in a strange shell state.

Working flawlessly now. Huge thanks to you! :heart:

2 Likes

The project has been updated with code generated by flakify and is thus now in a working state.

1 Like

That’s great to hear, thanks for letting me know.

You mention in your original post that your infra is based on NixOS. Can you go into more depth on what it is that you desire? I think there’s a potential for Flakify to support generating NixOS modules or even deploy-rs based deployments, but what does your setup look like? What do you need?

3 Likes