Skip to content

Commit

Permalink
feat(tooling): Enable use as a Nix flake
Browse files Browse the repository at this point in the history
- Use flake-compat for shell.nix and default.nix compatibility.
- Use builtins.fetchGit to fetch libtexpdf instead of relying on the
  submodule.
  • Loading branch information
doronbehar authored and alerque committed Sep 18, 2021
1 parent 0cb304f commit 8b503bb
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -83,3 +83,6 @@ sile.1
/.version-prev
/.tarball-version
/.built-subdirs

# Nix symlink to builds
/result
10 changes: 10 additions & 0 deletions default.nix
@@ -0,0 +1,10 @@
# https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash; }
) {
src = ./.;
}).defaultNix
60 changes: 60 additions & 0 deletions flake.lock

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

76 changes: 76 additions & 0 deletions flake.nix
@@ -0,0 +1,76 @@
{
description = "Simon’s Improved Layout Engine";

# To make user overrides of the nixpkgs flake not take effect
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";

# https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix
inputs.flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};

outputs = { self
, nixpkgs
, flake-utils
, flake-compat
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
# TODO: Should this be replaced with libtexpdf package from nixpkgs? or
# should we keep it that way, so that it'd be easy to test new versions
# of libtexpdf when developing?
libtexpdf-src = builtins.fetchGit {
url = "https://github.com/sile-typesetter/libtexpdf";
rev = "${(pkgs.lib.fileContents "${self}/libtexpdf.git-rev")}";
};
# https://discourse.nixos.org/t/passing-git-commit-hash-and-tag-to-build-with-flakes/11355/2
version_rev = if (self ? rev) then (builtins.substring 0 8 self.rev) else "dirty";
# Use the expression from Nixpkgs instead of rewriting it here.
sile = pkgs.sile.overrideAttrs(oldAttr: rec {
version = "${(pkgs.lib.importJSON ./package.json).version}-${version_rev}-flake";
src = builtins.filterSource
(path: type: type != "directory" || baseNameOf path != ".git")
./.;
# Add the libtexpdf src instead of the git submodule.
preAutoreconf = ''
rm -rf ./libtexpdf
# From some reason without this flag, libtexpdf/ is unwriteable
cp --no-preserve=mode -r ${libtexpdf-src} ./libtexpdf/
'';
# Pretend to be a tarball release so sile --version will not say `vUNKNOWN`.
postAutoreconf = ''
echo ${version} > .tarball-version
'';
# Don't build the manual as it's time consuming, and it requires fonts
# that are not available in the sandbox due to internet connection
# missing.
configureFlags = pkgs.lib.lists.remove "--with-manual" oldAttr.configureFlags;
nativeBuildInputs = oldAttr.nativeBuildInputs ++ [
pkgs.autoreconfHook
];
# TODO: This switch between the hooks can be moved to Nixpkgs'
postPatch = oldAttr.preConfigure;
preConfigure = "";
meta = oldAttr.meta // {
changelog = "https://github.com/sile-typesetter/sile/raw/master/CHANGELOG.md";
};
});
in rec {
devShell = pkgs.mkShell {
inherit (sile) checkInputs nativeBuildInputs buildInputs;
};
packages.sile = sile;
defaultPackage = sile;
apps.sile = {
type = "app";
program = "${sile}/bin/sile";
};
defaultApp = apps.sile;
}
);
}
1 change: 1 addition & 0 deletions libtexpdf.git-rev
@@ -0,0 +1 @@
c4ff429664607e1f055d29aeb5dc5d4b6ddb2499
10 changes: 10 additions & 0 deletions shell.nix
@@ -0,0 +1,10 @@
# https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash; }
) {
src = ./.;
}).shellNix

0 comments on commit 8b503bb

Please sign in to comment.