Commit 0a526397 authored by Alex Gleason's avatar Alex Gleason

Merge branch 'nix-support' into 'master'

Add support for developing Soapbox with Nix

See merge request !136
parents acdcc2ad a4ce319e
Pipeline #104183974 passed with stage
in 6 minutes and 56 seconds
......@@ -59,6 +59,10 @@ yarn-debug.log
# Ignore Docker option files
docker-compose.override.yml
# Ignore automatically generated Nix files
gemset.nix
yarn.nix
*-autosave.kra
dump.rdb
/*.secret
......
......@@ -51,7 +51,7 @@ gem 'redis-namespace', '~> 1.5'
gem 'htmlentities', '~> 4.3'
gem 'http', '~> 3.3'
gem 'http_accept_language', '~> 2.1'
gem 'http_parser.rb', '~> 0.6', git: 'https://github.com/tmm1/http_parser.rb', ref: '54b17ba8c7d8d20a16dfc65d1775241833219cf2'
gem 'http_parser.rb', '~> 0.6', git: 'https://github.com/tmm1/http_parser.rb', ref: '54b17ba8c7d8d20a16dfc65d1775241833219cf2', submodules: true
gem 'httplog', '~> 1.3'
gem 'idn-ruby', require: 'idn'
gem 'kaminari', '~> 1.1'
......
......@@ -9,6 +9,7 @@ GIT
remote: https://github.com/tmm1/http_parser.rb
revision: 54b17ba8c7d8d20a16dfc65d1775241833219cf2
ref: 54b17ba8c7d8d20a16dfc65d1775241833219cf2
submodules: true
specs:
http_parser.rb (0.6.1)
......
web: env PORT=3000 puma -C config/puma.rb
sidekiq: env PORT=3000 sidekiq
stream: env PORT=4000 DB_HOST=/run/postgresql DB_PORT=5432 yarn run start
webpack: ./bin/webpack-dev-server --listen-host 0.0.0.0
# Use this expression with nix-shell to create a Soapbox development
# environment with the pinned version of Nixpkgs.
let
nixpkgs = import ./dist/nixpkgs/pinned-nixpkgs.nix;
pkgs = import nixpkgs {
config = { };
overlays = [
(self: super: {
soapbox = self.callPackage ./dist/nixpkgs/soapbox { };
})
];
};
in pkgs.soapbox.overrideAttrs (oldAttrs: rec {
buildPhase = ""; dontBuild = true;
installPhase = ""; dontInstall = true;
propagatedBuildInputs = oldAttrs.propagatedBuildInputs ++ [
pkgs.goreman pkgs.yarn pkgs.nodejs oldAttrs.passthru.gems
];
# Soapbox's developer tools expect to find a writable node_modules
# directory.
shellHook = ''
if [[ -e node_modules && -d node_modules ]]; then
echo "Refreshing node_modules directory"
else
echo "Creating node_modules directory"
fi
rm -rf node_modules
cp -r "${oldAttrs.passthru.js-modules}/libexec/soapbox/node_modules" node_modules
chmod -R u+w node_modules
'';
})
# Use this expression to build the Soapbox production package with
# pinned Nixpkgs.
let
nixpkgs = import ./pinned-nixpkgs.nix;
pkgs = import nixpkgs {
config = { };
overlays = [
(self: super: {
soapbox = self.callPackage ./soapbox { };
})
];
};
in pkgs.soapbox
# This expression selects a specific revision of Nixpkgs to use,
# for reproducible development environments.
let
fetcher = { owner, repo, rev, sha256 }: builtins.fetchTarball {
inherit sha256;
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
};
in fetcher {
owner = "NixOS";
repo = "nixpkgs";
rev = "18f47ecbac1"; # Nixpkgs unstable 11/21/2019
sha256 = "16jmqa22av87rh6ivqazf9qfmvi85gj69x72vbglz9pgsxgni72v";
}
# This derivation is compatible with Nixpkgs and can be used to build
# a production Soapbox package. Only the source location would
# have to be changed to include this in Nixpkgs.
{ nodejs-slim, yarn2nix-moretea, fetchFromGitHub, bundlerEnv,
stdenv, yarn, lib, callPackage, imagemagick, ffmpeg, file,
nix-gitignore, goreman, ... }:
let
version = "1.0.0rc1";
unfilteredSrc = ../../../.;
# Avoid the "dumping very large path" complaint from nix-shell.
src = nix-gitignore.gitignoreSource [] unfilteredSrc;
soapbox-gems = bundlerEnv {
name = "soapbox-gems-${version}";
inherit version;
gemfile = unfilteredSrc + "/Gemfile";
lockfile = unfilteredSrc + "/Gemfile.lock";
gemset = unfilteredSrc + "/gemset.nix";
};
soapbox-js-modules = yarn2nix-moretea.mkYarnPackage {
pname = "soapbox-modules";
yarnNix = unfilteredSrc + "/yarn.nix";
packageJSON = unfilteredSrc + "/package.json";
# Filter source to avoid unnecessary rebuilds.
src =
let
mkFilter = { filesToInclude, root }: path: type:
let
inherit (lib) elem elemAt splitString;
subpath = elemAt (splitString "${toString root}/" path) 1;
in (type == "regular" && elem subpath filesToInclude);
in builtins.filterSource
(mkFilter {
filesToInclude = ["package.json" "yarn.lock"];
root = unfilteredSrc;
})
unfilteredSrc;
inherit version;
};
soapbox-assets = stdenv.mkDerivation {
pname = "soapbox-assets";
inherit src version;
buildInputs = [
soapbox-gems nodejs-slim yarn
];
buildPhase = ''
cp -r ${soapbox-js-modules}/libexec/soapbox/node_modules "node_modules"
chmod -R u+w node_modules
rake assets:precompile
'';
installPhase = ''
mkdir -p $out/public
cp -r public/assets $out/public
cp -r public/packs $out/public
'';
};
in stdenv.mkDerivation {
pname = "soapbox";
inherit src version;
# This is used to update gemfile.nix and yarn.nix.
passthru.updateScript = callPackage ./update.nix {};
# These are used to create a development shell.
passthru.js-modules = soapbox-js-modules;
passthru.gems = soapbox-gems;
buildPhase = ''
ln -s ${soapbox-js-modules}/libexec/soapbox/node_modules node_modules
ln -s ${soapbox-assets}/public/assets public/assets
ln -s ${soapbox-assets}/public/packs public/packs
patchShebangs bin/
for b in $(ls ${soapbox-gems}/bin/)
do
if [ ! -f bin/$b ]; then
ln -s ${soapbox-gems}/bin/$b bin/$b
fi
done
rm -rf log
ln -s /var/log/soapbox log
ln -s /tmp tmp
'';
propagatedBuildInputs = [ imagemagick ffmpeg file soapbox-gems.wrappedRuby ];
installPhase = ''
mkdir -p $out
cp -r * $out/
'';
meta = {
description = "Mastodon-compatible social media software with a focus on custom branding and accessibility";
homepage = https://soapbox.pub;
license = lib.licenses.agpl3;
maintainers = [ ];
};
}
{ pkgs, stdenv, lib, writeScript, makeWrapper, yarn2nix-moretea, bundix,
coreutils, gnused }:
stdenv.mkDerivation rec {
builder = writeScript "builder" ''
source $stdenv/setup
mkdir -p $out/bin
cp $src/update.sh $out/bin
patchShebangs $out/bin/update.sh
wrapProgram $out/bin/update.sh --prefix PATH : ${lib.makeBinPath buildInputs}
'';
src = ./.;
name = "update.sh";
system = builtins.currentSystem;
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ yarn2nix-moretea.yarn2nix bundix coreutils gnused ];
}
#!/bin/bash
set -e
rm -f gemset.nix yarn.nix
# create gemset.nix and update Gemfile.lock
bundix -l
# create yarn.nix and update yarn.lock
yarn2nix > "yarn.nix"
sed "s/https___.*_//g" -i "yarn.nix"
This diff is collapsed.
{
"name": "gab-social",
"name": "soapbox",
"version": "1.0.0rc1",
"license": "AGPL-3.0-or-later",
"engines": {
"node": ">=10 <11"
......
......@@ -91,16 +91,16 @@ const startWorker = (workerId) => {
development: {
user: process.env.DB_USER || pg.defaults.user,
password: process.env.DB_PASS || pg.defaults.password,
database: process.env.DB_NAME || 'gabsocial_development',
database: process.env.DB_NAME || 'soapbox_development',
host: process.env.DB_HOST || pg.defaults.host,
port: process.env.DB_PORT || pg.defaults.port,
max: 10,
},
production: {
user: process.env.DB_USER || 'gabsocial',
user: process.env.DB_USER || 'soapbox',
password: process.env.DB_PASS || '',
database: process.env.DB_NAME || 'gabsocial_production',
database: process.env.DB_NAME || 'soapbox_production',
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT || 5432,
max: 10,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment