add nix dev instructions

This commit is contained in:
happysalada 2021-04-23 12:53:10 +09:00
parent 80c3e0433e
commit aab187c14c
4 changed files with 84 additions and 0 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use_nix

4
.gitignore vendored
View file

@ -55,3 +55,7 @@ deps.path*
# Dev artifacts
.elixir_ls
db/
.nix-hex/
.nix-mix/
.direnv/

View file

@ -19,6 +19,21 @@ This app is part of the [Bonfire](https://bonfirenetworks.org/) ecosystem and bu
* Migrate DB when the app is running: `Bonfire.Repo.ReleaseTasks.migrate`
* More handy commands: `make help` and `mix help`
## Dev environment with Nix
If you use direnv, just cd in the directory and you will have all the dependencies. If you just have nix, running `nix-shell` will set you up with a shell.
You will need to create and init the db directory (keeping all your Postgres data inside this directory).
create the db directory `initdb ./db`
create the postgres user `createuser postgres -ds`
create the db `createdb bonfire_dev`
start the postgres instance `pg_ctl -l "$PGDATA/server.log" start`
`mix deps.get` to get elixir dependencies
`cd assets && npm install` to get the frontend dependencies
`mix ecto.migrate` to get an up to date database
`iex -S phx.server` to start the server
check out the app on `localhost:4000` in your browser
## Copyright and License

64
shell.nix Normal file
View file

@ -0,0 +1,64 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
messctl = rustPlatform.buildRustPackage rec {
pname = "messctl";
version = "0.0.1";
src = fetchFromGitHub {
owner = "bonfire-networks";
repo = pname;
rev = "8421d5ee91b120f1fe78fe8b123fc0fdf59609ff";
sha256 = "sha256-MniXkng8v30xzSC+cIZ+K6DWeJLCFDieXZioAQFU4/s=";
};
cargoSha256 = "sha256-z8SdQKME9/6O6ZRkNRI+vYZSf6fxAG4lz0Muv7876fY=";
};
# define packages to install with special handling for OSX
shellBasePackages = [
git
beam.packages.erlang.elixir_1_11
nodejs-15_x
postgresql_13
messctl
# for NIFs
rustfmt
clippy
];
shellBuildInputs = shellBasePackages ++ lib.optional stdenv.isLinux inotify-tools
++ lib.optionals stdenv.isDarwin
(with darwin.apple_sdk.frameworks; [ CoreFoundation CoreServices ]);
# define shell startup command
shellHooks = ''
# this allows mix to work on the local directory
mkdir -p $PWD/.nix-mix
mkdir -p $PWD/.nix-hex
export MIX_HOME=$PWD/.nix-mix
export HEX_HOME=$PWD/.nix-mix
export PATH=$MIX_HOME/bin:$PATH
export PATH=$HEX_HOME/bin:$PATH
mix local.hex --force
export LANG=en_US.UTF-8
export ERL_AFLAGS="-kernel shell_history enabled"
# postges related
export PGDATA="$PWD/db"
# elixir
export MIX_ENV=dev
'';
in
mkShell
{
nativeBuildInputs = [ rustc cargo gcc ]; # for NIFs
buildInputs = shellBuildInputs;
shellHook = shellHooks;
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}