This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
bdfr-browser/flake.nix

211 lines
6.4 KiB
Nix
Raw Normal View History

2023-05-17 22:13:55 +00:00
{
description = "bdfr-browser development environment";
2023-08-13 23:18:55 +00:00
2023-05-17 22:13:55 +00:00
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
2023-08-13 23:18:55 +00:00
# Tools
2023-05-17 22:13:55 +00:00
flake-parts.url = "github:hercules-ci/flake-parts";
2023-08-13 23:18:55 +00:00
flake-root.url = "github:srid/flake-root";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pre-commit-hooks-nix = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.gitignore.follows = "gitignore";
};
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
2023-05-17 22:13:55 +00:00
};
2023-08-13 23:18:55 +00:00
outputs = inputs@{ flake-parts, gitignore, ... }:
2023-05-17 22:13:55 +00:00
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "aarch64-darwin" "x86_64-linux" "aarch64-linux" ];
2023-08-13 23:18:55 +00:00
imports = [
inputs.flake-root.flakeModule
inputs.treefmt-nix.flakeModule
inputs.pre-commit-hooks-nix.flakeModule
inputs.process-compose-flake.flakeModule
];
perSystem = { pkgs, lib, config, self', ... }:
2023-05-17 22:13:55 +00:00
let
pname = "bdfr-browser";
version = "0.0.1";
2023-08-13 23:18:55 +00:00
erlang = pkgs.beam.interpreters.erlangR26;
beamPackagesPrev = pkgs.beam.packagesWith erlang;
elixir = beamPackagesPrev.elixir_1_15;
beamPackages = beamPackagesPrev // rec {
inherit erlang elixir;
hex = beamPackagesPrev.hex.override { inherit elixir; };
buildMix = beamPackagesPrev.buildMix.override { inherit elixir erlang hex; };
mixRelease = beamPackagesPrev.mixRelease.override { inherit erlang elixir; };
};
2023-10-01 22:33:41 +00:00
mix2nix = pkgs.mix2nix.override { inherit elixir erlang; };
2023-08-13 23:18:55 +00:00
postgres = pkgs.postgresql_15;
2023-05-17 22:13:55 +00:00
inherit (pkgs.stdenv) isDarwin;
2023-08-14 17:22:48 +00:00
inherit (pkgs.stdenv) isLinux;
2023-08-13 23:18:55 +00:00
inherit (gitignore.lib) gitignoreSource;
2023-05-17 22:13:55 +00:00
in
{
2023-08-13 23:18:55 +00:00
treefmt = {
inherit (config.flake-root) projectRootFile;
flakeCheck = false;
programs = {
mix-format = {
enable = true;
package = elixir;
};
nixpkgs-fmt.enable = true;
};
};
pre-commit = {
check.enable = false;
settings = {
excludes = [ "mix.nix" ];
hooks = {
deadnix.enable = true;
statix.enable = true;
treefmt.enable = true;
};
};
};
2023-05-17 22:13:55 +00:00
devShells.default = pkgs.mkShell {
2023-08-13 23:18:55 +00:00
name = pname;
nativeBuildInputs = [
2023-05-17 22:13:55 +00:00
erlang
elixir
2023-08-13 23:18:55 +00:00
postgres
2023-08-20 22:20:42 +00:00
pkgs.ruby_3_2
pkgs.rubyPackages_3_2.nokogiri
2023-08-14 17:22:48 +00:00
] ++ lib.optionals isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
CoreFoundation
CoreServices
]) ++ lib.optionals isLinux (with pkgs; [
inotify-tools
]);
2023-05-17 22:13:55 +00:00
2023-08-13 23:18:55 +00:00
packages = [
2023-10-01 22:33:41 +00:00
mix2nix
2023-08-13 23:18:55 +00:00
self'.packages.bdfr-browser-dev
];
inputsFrom = [
config.flake-root.devShell
config.treefmt.build.devShell
config.pre-commit.devShell
];
2023-05-17 22:13:55 +00:00
ERL_INCLUDE_PATH = "${erlang}/lib/erlang/usr/include";
2023-08-13 23:18:55 +00:00
TREEFMT_CONFIG_FILE = config.treefmt.build.configFile;
2023-05-17 22:13:55 +00:00
};
packages.default = beamPackages.mixRelease {
inherit pname version;
2023-08-13 23:18:55 +00:00
src = gitignoreSource ./.;
2023-08-17 13:19:56 +00:00
mixNixDeps = import ./mix.nix { inherit lib beamPackages; };
meta = with lib; {
description = "Bulk Downloader for Reddit Web UI";
homepage = "https://git.kempkens.io/daniel/bdfr-browser";
license = [ licenses.isc ];
platforms = [ "x86_64-darwin" "aarch64-darwin" "aarch64-linux" "x86_64-linux" ];
};
2023-05-17 22:13:55 +00:00
};
2023-08-13 23:18:55 +00:00
process-compose."${pname}-dev" =
let
db-host = "127.0.0.1";
db-user = "bdfr-browser";
in
{
port = 18808;
settings = {
environment = {
BDFR_BROWSER_BASE_DIRECTORY = "/Volumes/MediaScraper/Reddit";
2023-10-01 22:33:41 +00:00
BDFR_BROWSER_CONFIG_FILE = "./priv/dev_config.yml";
2023-08-13 23:18:55 +00:00
BDFR_BROWSER_REPO_USER = db-user;
BDFR_BROWSER_REPO_HOST = db-host;
2023-08-14 11:07:38 +00:00
RELEASE_DISTRIBUTION = "none";
RELEASE_COOKIE = "no_dist_anyway";
2023-08-13 23:18:55 +00:00
};
processes = {
db-init.command = ''
if [ ! -d "$PWD/.direnv/postgres/data" ]; then
echo "Initializing database ..."
mkdir -p "$PWD/.direnv/postgres"
${postgres}/bin/initdb --username ${db-user} --pgdata "$PWD/.direnv/postgres/data" --auth trust
else
echo "Database already initialized"
fi
'';
db = {
command = "${postgres}/bin/postgres -D $PWD/.direnv/postgres/data";
depends_on.db-init.condition = "process_completed_successfully";
readiness_probe.exec.command = "PGCONNECT_TIMEOUT=1 ${postgres}/bin/psql -h ${db-host} -U ${db-user} -l";
};
app-setup.command = ''
mix local.hex --if-missing --force
mix local.rebar --force
mix deps.get
'';
app-compile = {
command = "mix release --overwrite";
depends_on.app-setup.condition = "process_completed_successfully";
};
app = {
command = "$PWD/_build/dev/rel/bdfr_browser/bin/bdfr_browser start";
depends_on = {
db.condition = "process_healthy";
app-compile.condition = "process_completed_successfully";
};
readiness_probe.http_get = {
host = "127.0.0.1";
port = 4040;
path = "/_ping";
};
};
};
};
};
2023-05-17 22:13:55 +00:00
};
};
}