Commit a2ed5ca5 authored by happyriver's avatar happyriver

Add support for developing with Nix

parent 911da969
......@@ -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
......
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.
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