Skip to content

Commit

Permalink
nix: Simplify and comment flake.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
jtojnar committed Dec 18, 2020
1 parent 7a3a611 commit f0367a9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ before_install:
- nix path-info --all > /tmp/store-path-pre-build

# Update flake.nix to match the current CI job from matrix.
- sed -i "s/matrix.php = \"php\";/matrix.php = \"php${PHP}\";/" flake.nix
- sed -i "s/matrix.phpPackage = \"php\";/matrix.phpPackage = \"php${PHP}\";/" flake.nix

- if [ -n "$GH_TOKEN" ]; then nix-shell --run "composer config github-oauth.github.com ${GH_TOKEN}"; fi

Expand Down
68 changes: 44 additions & 24 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,80 @@
description = "selfoss feed reader and aggregator";

inputs = {
# Shim to make flake.nix work with stable Nix.
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};

# Repository with software packages.
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

utils.url = "github:numtide/flake-utils";
};

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

mkDevShell = pkgs: phpPackage:
# By default, we use the default PHP version from Nixpkgs.
matrix.phpPackage = "php";
in
# For each supported platform,
utils.lib.eachDefaultSystem (system:
let
php = pkgs.${phpPackage}.withExtensions ({ enabled, all }: with all; enabled ++ [
# Let’s merge the package set from Nixpkgs with our custom PHP versions.
pkgs = import nixpkgs.outPath {
inherit system;
overlays = [
(import ./utils/nix/phps.nix nixpkgs.outPath)
];
};

# Create a PHP package from the selected PHP package, with some extra extensions enabled.
php = pkgs.${matrix.phpPackage}.withExtensions ({ enabled, all }: with all; enabled ++ [
imagick
]);

# Create a Python package with some extra packages installed.
python = pkgs.python3.withPackages (pp: with pp; [
requests
# For integration tests.
bcrypt
requests
]);
in
pkgs.mkShell {
in {
# Expose shell environment for development.
devShell = pkgs.mkShell {
nativeBuildInputs = [
# Composer and PHP for back-end.
php
pkgs.zola
php.packages.composer

# Back-end code validation.
php.packages.psalm
php.packages.phpstan

# npm for front-end.
pkgs.nodejs_latest
python

# For building zip archive.
pkgs.jq
] ++ (with php.packages; [
composer
psalm
phpstan
]);

LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
};
in
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs.outPath {
inherit system;
overlays = [
(import ./utils/nix/phps.nix nixpkgs.outPath)
# For building zip archive and integration tests.
python

# Website generator.
pkgs.zola
];

# node-gyp wants some locales, let’s make them available through an environment variable.
LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
};
in {

# Expose our custom PHP packages for testing.
packages = {
inherit (pkgs) php56 php70 php71 php72;
};
devShell = mkDevShell pkgs matrix.php;
}
);
}

0 comments on commit f0367a9

Please sign in to comment.