From 1da7187b780670868274864a94391b168221d3dd Mon Sep 17 00:00:00 2001 From: sgiath Date: Sat, 16 Mar 2024 08:54:11 +0000 Subject: [PATCH] feat: update Elixir template Signed-off-by: sgiath --- elixir/flake.lock | 34 ++++++++++++++++++ elixir/flake.nix | 88 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 105 insertions(+), 17 deletions(-) diff --git a/elixir/flake.lock b/elixir/flake.lock index d4ecad3..7a0cc8f 100644 --- a/elixir/flake.lock +++ b/elixir/flake.lock @@ -1,5 +1,23 @@ { "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1703013332, @@ -16,8 +34,24 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/elixir/flake.nix b/elixir/flake.nix index f83f706..912e459 100644 --- a/elixir/flake.nix +++ b/elixir/flake.nix @@ -1,25 +1,79 @@ { description = "A Nix-flake-based Elixir development environment"; - inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz"; + inputs = { + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz"; - outputs = { self, nixpkgs }: + flake-utils = { + url = "github:numtide/flake-utils"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: let - supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; - forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { - pkgs = import nixpkgs { inherit system; }; - }); + pkgs = nixpkgs.legacyPackages.${system}; + + # documentation + # https://nixos.org/manual/nixpkgs/stable/#sec-beam + + # ==== ERLANG ==== + + # use whatever version is currently defined in nixpkgs + erlang = pkgs.beam.interpreters.erlang; + + # use latest version of Erlang 26 + # erlang = pkgs.beam.interpreters.erlang_26; + + # specify exact version of Erlang OTP + # erlang = pkgs.beam.interpreters.erlang.override { + # version = "26.2.2"; + # sha256 = "sha256-7S+mC4pDcbXyhW2r5y8+VcX9JQXq5iEUJZiFmgVMPZ0="; + # } + + # ==== BEAM packages ==== + + # all BEAM packages will be compile with your preffered erlang version + pkgs-beam = pkgs.beam.packagesWith erlang; + + # ==== Elixir ==== + + # use whatever version is currently defined in nixpkgs + elixir = pkgs-beam.elixir; + + # use latest version of Elixir 1.16 + # elixir = pkgs-beam.elixir_1_16; + + # specify exact version of Elixir + # elixir = pkgs-beam.elixir.override { + # version = "1.16.1"; + # sha256 = "sha256-rjUt3gCUszCbzGE7BriwH3ptrV81dqNB/d0nVOXrcGI="; + # }; in { - devShells = forEachSupportedSystem ({ pkgs }: { - default = pkgs.mkShell { - packages = (with pkgs; [ elixir ]) ++ - # Linux only - pkgs.lib.optionals (pkgs.stdenv.isLinux) (with pkgs; [ gigalixir inotify-tools libnotify ]) ++ - # macOS only - pkgs.lib.optionals (pkgs.stdenv.isDarwin) (with pkgs; [ terminal-notifier ]) ++ - (with pkgs.darwin.apple_sdk.frameworks; [ CoreFoundation CoreServices ]); - }; - }); - }; + devShells.default = pkgs.mkShell { + packages = [ + # use the Elixr/OTP versions defined above; will also install OTP, mix, hex, rebar3 + elixir + + # mix needs it for downloading dependencies + pkgs.git + + # probably needed for your Phoenix assets + pkgs.nodejs_20 + ] ++ + # Linux only + pkgs.lib.optionals pkgs.stdenv.isLinux (with pkgs; [ gigalixir inotify-tools libnotify ]) ++ + # macOS only + pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ pkgs.terminal-notifier CoreFoundation CoreServices ]); + + # some sane defaults for iex session + shellHooks = '' + export ERL_AFLAGS="+pc unicode -kernel shell_history enabled" + export ELIXIR_ERL_OPTIONS="+sssdio 128" + ''; + }; + } + ); }