Giter Club home page Giter Club logo

nix-beam-flakes's Introduction

Nix tooling for Flakes and BEAM Languages

Table of Contents

Project Status

Warning

Please note that this project is in low-maintenance mode. For more details on what this means in practice, please see issue #53.

Requirements

  • Nix with Flakes support
  • flake-parts
  • direnv (Optional)

Features

  • Automatic packaging for ~any finalized, tagged release of both Erlang/OTP and Elixir
    • Package definitions are based on upstream nixpkgs definitions with src overrides
    • Packages will be added to your own flake's outputs, and can be consumed by other Nix code
  • Declarative, automatic devShell creation using these packages (with opt-out)
    • Opt-in support for elixir-ls and erlang_ls LSP servers
  • Elixir-ecosystem-aware Nix helpers
  • A small number of Elixir applications usable directly via nix run (see below)
  • Flake Templates

Packages

phx_new

Want to start a new Phoenix project? Don't have a global install of Elixir/Mix? This can help. Pairs well with flake templates below.

nix run github:shanesveller/nix-beam-flakes#phx_new -- --help

livebook

nix run github:shanesveller/nix-beam-flakes#livebook -- server

Usage

Via Flake Template

nix flake init -t github:shanesveller/nix-beam-flakes#default
# or
nix flake init -t github:shanesveller/nix-beam-flakes#phoenix

At the time of writing there is no meaningful distinction between the two, but they will diverge as I continue to implement speciality support for the needs of a Phoenix project.

Manually Via flake-parts

Please review the documentation for flake-parts here if you are new to this library/paradigm.

A complete example:

{
  description = "My Elixir application";

  inputs = {
    beam-flakes.url = "github:shanesveller/nix-beam-flakes";
    beam-flakes.inputs.flake-parts.follows = "flake-parts";
    flake-parts.url = "github:hercules-ci/flake-parts";
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  };

  outputs = {
    self,
    beam-flakes,
    flake-parts,
    ...
  }:
    flake-parts.lib.mkFlake {inherit self;} {
      imports = [beam-flakes.flakeModule];

      systems = ["aarch64-darwin" "x86_64-darwin" "x86_64-linux"];

      perSystem = _: {
        beamWorkspace = {
          enable = true;
          devShell.languageServers.elixir = true;
          versions = {
            elixir = "1.16.2";
            erlang = "26.2.3";
          };
        };
      };
    };
}

You can add any additional packages to perSystem.beamWorkspace.devShell.extraPackages. You can provide additional arguments to mkShell, such as arbitrary environment variables, via perSystem.beamWorkspace.devShell.extraArgs. You can opt out of the automatic default devShell and manage yourself by setting perSystem.beamWorkspace.devShell.enable = false;

Setting Versions

Explicitly

    flake-parts.lib.mkFlake {inherit self;} {
      # ...
      perSystem = _: {
        beamWorkspace = {
          versions = {
            # You can also use an `asdf`-compatible string, such as "1.14.2-otp-25".
            #
            # Everything after the first hyphen is stripped and handled according
            # to the defined erlang version instead.
            elixir = "1.16.2";
            erlang = "26.2.3";
          };
        };
      };
    };

.tool-versions Compatibility

For projects that formerly, or concurrently, use asdf, a compatibility shim will read your .tool-versions file and set the elixir and erlang versions accordingly.

    flake-parts.lib.mkFlake {inherit self;} {
      # ...
      perSystem = _: {
        beamWorkspace = {
          enable = true;
          versions = {
            fromToolVersioons = ./.tool-versions;
          };
        };
      };
    };

Future Plans

Immediate concerns:

  • Significant documentation efforts inspired by the flake-parts website
  • CI that the modules continue to evaluate successfully with common scenarios
  • A binary cache for the latest pairing of Erlang/Elixir for MacOS/Linux
  • More robust specialty support for Phoenix projects

Later on:

  • Expose/enforce the compatibility-check logic that honors Elixir's compatibility policy so flake users get immediate feedback when they've chosen an unsupported combination
  • Phoenix speciality support
    • esbuild binaries
    • tailwind binaries
    • Possibly some lightweight Node.js support

Future:

  • pre-commit-hooks.nix integration with canned Elixir-specific hooks - it already pairs nicely using the flake-parts module
  • Automatic Docker-compatible OCI image creation from your Mix release via pkgs.ociTools
  • NixOS module generation to run your Mix release via systemd

Contributing

Generally not solicited at this time, but if you're particularly adventurous, read on.

Newly-published language versions

If you are a Nix user, this is already automated:

nix develop ./dev
just add-elixir 1.16.2
just add-erlang 26.2.3

Just PR the changes to data that it committed for you. I'll probably be on top of it already, for the most part.

Other Beam Languages

At this time I am not a personal or professional user of any other languages that inhabit the BEAM VM, and I do not feel I can offer a satisfactory level of support or nuance for tooling I do not use. As such, I will consider collaborating with those who do to offer support here on a best-effort basis, but I do not consider it a priority at this time.

Other Details

Please open an issue/discussion before setting out on any other contributions so that we can discuss whether your ideas align with my plans for this project. I'd hate to see anyone feel like their effort/goodwill were wasted.

Credits

I would not have pushed this very far were it not for flakes and flake-parts. I've gotten several rounds of useful feedback directly from discussions on the flake-parts repository as well as learned a lot from studying its code.

I also take some inspiration from oxalica/rust-overlay.

nix-beam-flakes's People

Contributors

dependabot[bot] avatar mhanberg avatar shanesveller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nix-beam-flakes's Issues

offer support for `next-ls` and `lexical`

Please provide support for the 2 alternative language servers.

This could be done by providing explicit options and packages for them, or by just accepting a languageServerPackage or similar.

How to use "ref:main" for Elixir version?

Thanks for this flake setup!

I am needing to only test a project against the Elixir main branch (and update it frequently), and I'm not entirely sure how to do that with this nix package.

Is it possible?

Thanks!

This repo is in low-maintenance mode

For self-care reasons I am limiting my involvement in and exposure to the Nix community and ecosystems as of 2024-03-11. If this repo issue is still marked open, then it is still the case. Please respect my privacy by not asking for any particulars in a public venue, or speculating about such.

Concretely this means I will likely not pursue any feature requests, nor create notable new functionality, and will be addressing filed bugs on a case by case basis. Showstoppers may see resolution if I can budget time for them, but papercuts or things that can be reasonably worked around at downstream Nix code likely will not.

Updating checksums for new OTP and Elixir releases has been sufficiently automated that I will probably continue publishing those for now.

I have updated the README to make this maintenance status clearer to casual visitors, and may archive this repo altogether at a later date and am still weighing that decision.

Lastly, if you wish to fork you have that right and I attached a LICENSE to make that less implicit, but I will not be transferring this repo or updating it to link out to any forks or rewrites.

How do I add extra packages through `extraPackages`?

What am I doing wrong here?

devShell.extraPackages = [
  git
];

I get the following error:

error: undefined variable 'git'

       at /nix/store/lhr1v8nir1a7ab1xvbrhng2i0r6mvxph-source/flake.nix:28:13:

           27| 	  devShell.extraPackages = [
           28|             git
             |             ^
           29| 	  ];

I'm not sure where I should get the package definition from.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.