103 lines
3.1 KiB
Nix
103 lines
3.1 KiB
Nix
{
|
|
description = "A flake for building development environment of Phoenix project.";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/master";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
};
|
|
|
|
outputs = {
|
|
nixpkgs,
|
|
flake-utils,
|
|
...
|
|
}:
|
|
flake-utils.lib.eachDefaultSystem (
|
|
system: let
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
erl = pkgs.beam.interpreters.erlang_27;
|
|
erlangPackages = pkgs.beam.packagesWith erl;
|
|
elixir = erlangPackages.elixir;
|
|
in {
|
|
packages = let
|
|
version = "0.1.0";
|
|
src = ./.;
|
|
mixFodDeps = erlangPackages.fetchMixDeps {
|
|
inherit version src;
|
|
pname = "example";
|
|
sha256 = "";
|
|
};
|
|
translatedPlatform =
|
|
pkgs.lib.getAttr
|
|
system
|
|
{
|
|
aarch64-darwin = "macos-arm64";
|
|
aarch64-linux = "linux-arm64";
|
|
armv7l-linux = "linux-armv7";
|
|
x86_64-darwin = "macos-x64";
|
|
x86_64-linux = "linux-x64";
|
|
};
|
|
in rec {
|
|
default = erlangPackages.mixRelease {
|
|
inherit version src mixFodDeps;
|
|
pname = "example";
|
|
|
|
preInstall = ''
|
|
ln -s ${pkgs.tailwindcss}/bin/tailwindcss _build/tailwind-${translatedPlatform}
|
|
ln -s ${pkgs.esbuild}/bin/esbuild _build/esbuild-${translatedPlatform}
|
|
|
|
${elixir}/bin/mix assets.deploy
|
|
${elixir}/bin/mix phx.gen.release
|
|
'';
|
|
};
|
|
dockerImage = pkgs.dockerTools.buildImage {
|
|
name = "example";
|
|
config = {
|
|
Entrypoint = "${default}/bin/example";
|
|
Cmd = "start";
|
|
};
|
|
};
|
|
};
|
|
devShells.default = pkgs.mkShell {
|
|
buildInputs = with pkgs;
|
|
[
|
|
erl
|
|
elixir
|
|
lexical
|
|
erlangPackages.elixir-ls
|
|
next-ls
|
|
]
|
|
++ lib.optionals stdenv.isLinux [
|
|
# For ExUnit Notifier on Linux.
|
|
libnotify
|
|
|
|
# For file_system on Linux.
|
|
inotify-tools
|
|
]
|
|
++ lib.optionals stdenv.isDarwin [
|
|
# For ExUnit Notifier on macOS.
|
|
terminal-notifier
|
|
|
|
# For file_system on macOS.
|
|
darwin.apple_sdk.frameworks.CoreFoundation
|
|
darwin.apple_sdk.frameworks.CoreServices
|
|
];
|
|
|
|
shellHook = ''
|
|
# allows mix to work on the local directory
|
|
mkdir -p .nix/{mix,hex}
|
|
export MIX_HOME=$PWD/.nix/mix
|
|
export HEX_HOME=$PWD/.nix/hex
|
|
export ERL_LIBS=$HEX_HOME/lib/erlang/lib
|
|
|
|
# concats PATH
|
|
export PATH=$MIX_HOME/bin:$PATH
|
|
export PATH=$MIX_HOME/escripts:$PATH
|
|
export PATH=$HEX_HOME/bin:$PATH
|
|
|
|
# enables history for IEx
|
|
export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_path '\"$PWD/.nix/erlang-history\"'"
|
|
'';
|
|
};
|
|
}
|
|
);
|
|
}
|