putzplan/flake.nix

114 lines
3.5 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 = {
self,
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 = "putzplan";
sha256 = "sha256-H8FFuNayJcFvESWlGYr6H6L5zSzAjqBixBmob5Gnoc4=";
};
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 = "putzplan";
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 = "putzplan";
config = {
Entrypoint = "${default}/bin/putzplan";
Cmd = "start";
};
};
};
devShells.default = pkgs.mkShell {
buildInputs = with pkgs;
[
erl
elixir
lexical
erlangPackages.elixir-ls
next-ls
gnumake
authelia
lazysql
nix-output-monitor
]
++ 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 = ''
export OIDC_CLIENT_ID="putzplan"
export OIDC_BASE_URL="http://127.0.0.1:9091"
export OIDC_CLIENT_SECRET_FILE="${pkgs.writeText "client_secret" "insecure_secret"}"
export OIDC_REDIRECT_URI="http://127.0.0.1:4000/auth"
# 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\"'"
'';
};
}
);
}