Skip to content

Commit

Permalink
nix: build PHP package using C4
Browse files Browse the repository at this point in the history
Instead of sleeping one night, I wrote https://github.com/fossar/composition-c4.

Combined with napalm, this will allow us to fully build selfoss using Nix.
  • Loading branch information
jtojnar committed May 31, 2021
1 parent f71a50f commit 41654ef
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
16 changes: 16 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
description = "selfoss feed reader and aggregator";

inputs = {
# Tool for downloading Composer dependencies using Nix.
c4.url = "github:fossar/composition-c4";

# Shim to make flake.nix work with stable Nix.
flake-compat = {
url = "github:edolstra/flake-compat";
Expand All @@ -17,7 +20,7 @@
phps.url = "github:fossar/nix-phps";
};

outputs = { self, flake-compat, nixpkgs, phps, utils }:
outputs = { self, c4, flake-compat, nixpkgs, phps, utils }:
let
# Configure the development shell here (e.g. for CI).

Expand All @@ -28,7 +31,13 @@
utils.lib.eachDefaultSystem (system:
let
# Get Nixpkgs packages for current platform.
pkgs = nixpkgs.legacyPackages.${system};
pkgs = import nixpkgs {
inherit system;
overlays = [
# Include c4 tool.
c4.overlay
];
};

# Create a PHP package from the selected PHP package, with some extra extensions enabled.
php = phps.packages.${system}.${matrix.phpPackage}.withExtensions ({ enabled, all }: with all; enabled ++ [
Expand Down Expand Up @@ -69,6 +78,12 @@
# node-gyp wants some locales, let’s make them available through an environment variable.
LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
};

packages = {
selfoss = pkgs.callPackage ./utils/selfoss.nix {
src = self.outPath;
};
};
}
);
}
32 changes: 32 additions & 0 deletions utils/selfoss.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
stdenv,
lib,
src,
php,
c4,
}:

stdenv.mkDerivation rec {
pname = "selfoss";
version = (lib.importJSON "${src}/package.json").ver;

inherit src;

composerDeps = c4.fetchComposerDeps {
inherit src;
};

nativeBuildInputs = [
php.packages.composer
c4.composerSetupHook
];

installPhase = ''
runHook preInstall
composer install
cp -r . $out
runHook postInstall
'';
}

0 comments on commit 41654ef

Please sign in to comment.