Skip to content

Instantly share code, notes, and snippets.

@lukateras
Last active October 26, 2019 09:39
Show Gist options
  • Save lukateras/0b6987ed3fafb93fa47a6985cda0aa8f to your computer and use it in GitHub Desktop.
Save lukateras/0b6987ed3fafb93fa47a6985cda0aa8f to your computer and use it in GitHub Desktop.
Pleroma derivation that leverages http://gitlab.com/transumption/mix-to-nix
with import <nixpkgs> {};
let
inherit (callPackage (fetchGit {
url = https://gitlab.com/transumption/mix-to-nix;
rev = "b70cb8f7fca80d0c5f7539dbfec497535e07d75c";
}) {}) mixToNix;
# Fake config, required for compilation
prodSecret = writeText "prod.secret.exs" ''
use Mix.Config
config :pleroma, Pleroma.Repo,
adapter: Ecto.Adapters.Postgres
'';
in
(mixToNix {
src = stdenv.mkDerivation {
name = "pleroma";
src = fetchGit {
url = https://git.pleroma.social/pleroma/pleroma;
rev = "3879500c87829a5cf1377ca7ccdb7bf92c75367f";
};
buildCommand = ''
cp --no-preserve=mode -r $src $out
# Suppresses runtime git invocation
substituteInPlace $out/mix.exs \
--replace 'version: version' 'version: to_string'
# Fork with v1.4 as HEAD branch, see:
# https://github.com/NixOS/nix/pull/2409
substituteInPlace $out/mix.lock \
--replace phoenixframework/phoenix yegortimoshenko/phoenix
cp ${prodSecret} $out/config/prod.secret.exs
'';
};
overlay = final: previous: {
cowlib = previous.cowlib.overrideAttrs (super: {
postPatch = ''
substituteInPlace src/cow_multipart.erl \
--replace crypto:rand_bytes crypto:strong_rand_bytes
'';
});
};
}).overrideAttrs (super: {
doCheck = false;
})
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.pleroma;
in
{
options.services.pleroma = {
enable = mkEnableOption "Pleroma";
configPath = mkOption {
default = "/root/pleroma.exs";
type = types.str;
};
package = mkOption {
default = pkgs.pleroma;
type = types.package;
};
};
config = mkIf cfg.enable {
systemd.services.pleroma = {
after = [ "network.target" ];
requires = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
environment = {
ERL_LIBS = "${pkgs.beamPackages.hex}/lib/erlang/lib";
MIX_ENV = "prod";
};
path = with pkgs; [ elixir ];
preStart = ''
cat ${cfg.configPath} > /tmp/pleroma.exs
'';
serviceConfig = {
DynamicUser = true;
ExecStart = "${pkgs.elixir}/bin/mix run -c /tmp/pleroma.exs do deps.loadpaths --no-compile --no-deps-check, phx.server";
PermissionsStartOnly = true;
StateDirectory = "pleroma";
WorkingDirectory = cfg.package;
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment