diff options
| -rw-r--r-- | .github/workflows/build.yml | 61 | ||||
| -rw-r--r-- | .github/workflows/docs.yml | 2 | ||||
| -rw-r--r-- | config/shell.config | 31 | ||||
| -rw-r--r-- | config/sys.config | 24 | ||||
| -rw-r--r-- | config/vm.args | 7 | ||||
| -rw-r--r-- | flake.nix | 55 | ||||
| -rw-r--r-- | rebar-deps.nix | 18 | ||||
| -rw-r--r-- | rebar.config | 78 | ||||
| -rw-r--r-- | treefmt.nix | 1 |
9 files changed, 250 insertions, 27 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5754292 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,61 @@ +name: "[Domino] Build" + +on: + push: + branches: [ "master" ] + paths: + - .github/workflows/** + - config/** + - docs/** + - include/** + - test/** + - src/** + - flake.nix + - flake.lock + - rebar.config + - rebar-deps.nix + - rebar.lock + + pull_request: + branches: [ "master" ] + paths: + - .github/workflows/** + - config/** + - docs/** + - include/** + - test/** + - src/** + - flake.nix + - flake.lock + - rebar.config + - rebar-deps.nix + - rebar.lock + +permissions: + contents: read + +jobs: + build: + name: "[Domino] Nix Build" + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + lfs: true + + - name: Install Nix + uses: cachix/install-nix-action@v31 + with: + # Mostly to avoid GitHub rate limiting + extra_nix_config: | + access-tokens = github.com=${{ github.token }} + + - name: Install Nix Cache + uses: DeterminateSystems/magic-nix-cache-action@main + + # Actual Pipelines + - name: "Build" + run: | + nix build diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 84048cf..0d3aa58 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -73,6 +73,7 @@ jobs: deploy: name: Deploy to GitHub Pages + if: github.event_name != 'pull_request' environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} @@ -82,5 +83,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - if: github.event_name != 'pull_request' uses: actions/deploy-pages@v4 diff --git a/config/shell.config b/config/shell.config new file mode 100644 index 0000000..cfee2fa --- /dev/null +++ b/config/shell.config @@ -0,0 +1,31 @@ +[ + {kernel, [ + {logger_level, debug}, + {logger, [ + {handler, default, logger_std_h, #{ + level => debug, + config => #{ + type => standard_io + }, + formatter => {logger_formatter, #{ + legacy_header => false, + single_line => false, + max_size => unlimited, + depth => unlimited, + chars_limit => unlimited, + template => [time, " ", color_start, "[", level, "]", color_end, " ", + {mfa, [mfa, ":", line], ""}, " ", msg, "\n"], + time_designator => $T, + time_offset => "Z" + }} + }} + ]} + ]}, + {sasl, [ + {sasl_error_logger, {file, "log/sasl.log"}}, + {errlog_type, error}, + {error_logger_mf_dir, "log"}, + {error_logger_mf_maxbytes, 10485760}, + {error_logger_mf_maxfiles, 5} + ]} +]. diff --git a/config/sys.config b/config/sys.config new file mode 100644 index 0000000..a63cf9e --- /dev/null +++ b/config/sys.config @@ -0,0 +1,24 @@ +[ + {kernel, [ + {logger_level, info}, + {logger, [ + {handler, default, logger_std_h, #{ + level => info, + config => #{ + type => standard_io + }, + formatter => {logger_formatter, #{ + single_line => false, + template => [ + "{\"timestamp\":\"", time, "\",", + "\"level\":\"", level, "\",", + "\"pid\":\"", pid, "\",", + "\"mfa\":\"", mfa, "\",", + "\"line\":", line, ",", + "\"msg\":", msg, "}\n" + ] + }} + }} + ]} + ]} +]. diff --git a/config/vm.args b/config/vm.args new file mode 100644 index 0000000..4ff3840 --- /dev/null +++ b/config/vm.args @@ -0,0 +1,7 @@ +## Name of the node +-sname domino + +## Extra options +-heart +-env HEART_BEAT_TIMEOUT 20 ++K true @@ -17,24 +17,11 @@ perSystem = { pkgs, system, ... }: let - erlang = pkgs.erlang_28; - - buildRebar3 = pkgs.beamPackages.buildRebar3 { - pname = "domino"; - version = "0.1.0"; - src = ./.; - beam = erlang; - generate-lock = true; - name = "domino"; - buildInputs = [ pkgs.rebar3 ]; - - meta = with pkgs.lib; { - description = "Domino Erlang Server"; - license = pkgs.lib.licenses.mit; - platforms = pkgs.lib.platforms.all; - }; - }; - + erlangLatest = pkgs.erlang_28; + + rebar_config = builtins.readFile ./rebar.config; + match = builtins.match ".*release,.+domino, \"([0-9.]+)\".*" rebar_config; + pversion = builtins.head match; in { # This sets `pkgs` to a nixpkgs with allowUnfree option set. _module.args.pkgs = import nixpkgs { @@ -44,18 +31,42 @@ # nix build packages = { - domino = buildRebar3; - default = buildRebar3; + default = + let + deps = import ./rebar-deps.nix { + inherit (pkgs) fetchHex fetchFromGitHub fetchgit; + builder = pkgs.beamPackages.buildRebar3; + }; + in + pkgs.beamPackages.rebar3Relx { + pname = "domino"; + version = pversion; + src = pkgs.lib.cleanSource ./.; + releaseType = "release"; + profile = "prod"; + buildInputs = ( + with pkgs; + [ + coreutils + gawk + gnugrep + openssl + ] + ++ lib.optional stdenv.isLinux [ + liburing + ] + ); + beamDeps = builtins.attrValues deps; + }; }; # Define devShell for Erlang + Rebar3 devShells = { default = pkgs.mkShell { packages = with pkgs; [ - erlang_28 erlang-language-platform rebar3 - ]; + ] ++ [erlangLatest]; }; }; diff --git a/rebar-deps.nix b/rebar-deps.nix new file mode 100644 index 0000000..178f889 --- /dev/null +++ b/rebar-deps.nix @@ -0,0 +1,18 @@ +# Generated by rebar3_nix +let fetchOnly = { src, ... }: src; +in { builder ? fetchOnly, fetchHex, fetchgit, fetchFromGitHub, overrides ? (x: y: { }) }: +let + self = packages // (overrides self packages); + packages = with self; { + merklet = builder { + name = "merklet"; + version = "2.0.0"; + src = fetchHex { + pkg = "merklet"; + version = "2.0.0"; + sha256 = "sha256-teho2ll5+bPD5Oi4FxqlwWeGjjVJW4FzHJPYOC/dMng="; + }; + beamDeps = [ ]; + }; + }; +in self diff --git a/rebar.config b/rebar.config index 2c2d11e..8f364e6 100644 --- a/rebar.config +++ b/rebar.config @@ -1,15 +1,84 @@ -{erl_opts, [debug_info]}. -{deps, [{merklet, "2.0.0"}]}. +%% == Compiler Options == +{erl_opts, [ + debug_info, + report, + verbose, + warn_unused_import, + warn_export_vars +]}. + +%% == Dependencies and Plugins == +{deps, [ + {merklet, "2.0.0"}] +}. {plugins, [ - {rebar3_nix, ".*", {git, "https://github.com/erlang-nix/rebar3_nix.git", {tag, "v0.1.1"}}}, - {covertool, "v2.0.4"} + {covertool, "2.0.7"}, + {rebar3_nix, ".*", {git, "https://github.com/erlang-nix/rebar3_nix.git", {tag, "v0.1.1"}}} +]}. + +%% == Common Test Options == +{ct_opts, []}. + +%% == Releases == +{relx, [ + {release, {domino, "0.1.0"}, [ + merklet + ]}, + + {mode, dev}, + {extended_start_script, true}, + + %% automatically picked up if the files + %% exist but can be set manually, which + %% is required if the names aren't exactly + %% sys.config and vm.args + {sys_config, "./config/sys.config"}, + {vm_args, "./config/vm.args"}, + + {overlay, [ + {mkdir, "log/sasl"}, + {mkdir, "log/errors"} + ]} ]}. +%% == Profiles == +{profiles, [ + %% prod is the default mode when prod + %% profile is used, so does not have + %% to be explicitly included like this + {prod, [ + {relx, [ + {include_erts, true}, + {sys_config, "./config/sys.config"}, + %% https://rebar3.org/docs/deployment/releases/#modes + {mode, prod} + ]} + ]}, + + {test, [ + {deps, [ + meck, + proper + ]} + ]} +]}. + +%% == Shell == +%% apps to auto-boot with `rebar3 shell'; defaults to apps +%% specified in a `relx' tuple, if any. {shell, [ + %% We have a special config just to run the app inside + %% a shell, helps with debugging and local testing. + {config, "config/shell.config"}, {apps, [main]} + + %% If you need any environment variables to be set inside + %% the debug shell as well. + %%{env_file, "deployment/default.env"}] ]}. +%% == Dialyzer Settings == {dialyzer, [ {plt_extra_apps, [merklet]}, {warnings, [unknown]}, @@ -25,6 +94,7 @@ ]} ]}. +%% == EDOC Settings == {edoc_opts, [ {doclet, edoc_doclet}, {source_path, ["src"]}, diff --git a/treefmt.nix b/treefmt.nix index 4341016..7a4812b 100644 --- a/treefmt.nix +++ b/treefmt.nix @@ -5,5 +5,6 @@ projectRootFile = "flake.nix"; programs = { erlfmt.enable = true; + nixfmt.enable = true; }; } |
