Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flake.nix and other files #1231

Merged
merged 5 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ sile.1
/.version-prev
/.tarball-version
/.built-subdirs

# Nix symlink to builds
/result
12 changes: 10 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,26 @@ EXTRA_DIST = spec tests examples documentation sile-dev-1.rockspec fontconfig.co
EXTRA_DIST += Makefile-distfiles
EXTRA_DIST += build-aux/action-updater.js build-aux/decore-automake.sh build-aux/git-version-gen build-aux/list-dist-files.sh
EXTRA_DIST += Dockerfile build-aux/docker-bootstrap.sh build-aux/docker-fontconfig.conf build-aux/docker-glibc-workaround.sh hooks/build
EXTRA_DIST += default.nix flake.nix flake.lock libtexpdf.git-rev shell.nix
EXTRA_DIST += package.json # imported by both Nix and Docker
EXTRA_DIST += $(MANUAL) $(EXAMPLES)

Makefile-distfiles: $(wildcard .version .tarball-version) | $(LUAMODLOCK)
build-aux/list-dist-files.sh > $@

BUILT_SOURCES = .version Makefile-distfiles

.version: $(shell $(AWK) '{print ".git/" $$2}' .git/HEAD 2>/dev/null ||:)
_BRANCH_REF := $(shell $(AWK) '{print ".git/" $$2}' .git/HEAD 2>/dev/null ||:)

.version: $(_BRANCH_REF)
[ -e "$@" ] && mv "$@" "$@-prev" || $(if $<,touch,cp "$(srcdir)/.tarball-version") "$@-prev"
$(if $<,./build-aux/git-version-gen "$(srcdir)/.tarball-version",printf "$(VERSION)") > "$@"
$(CMP) -s "$@" "$@-prev" || \
( autoreconf configure.ac --force && build-aux/decore-automake.sh )

libtexpdf.git-rev: $(_BRANCH_REF)
$(GIT) submodule status -- libtexpdf | $(AWK) '{ print $$1 }' > $@

dist-hook: $(MANUAL) $(EXAMPLES)
cd $(distdir)
printf "$(VERSION)" > .tarball-version
Expand Down Expand Up @@ -109,7 +116,8 @@ sile-%.md: CHANGELOG.md
update_libtexpdf:
$(GIT) diff-index --quiet --cached HEAD || exit 1 # die if anything already staged
$(GIT) submodule update --init --remote -- libtexpdf
$(GIT) add -- libtexpdf
$(GIT) submodule status -- libtexpdf | $(AWK) '{ print $$1 }' > libtexpdf.git-rev
$(GIT) add -- libtexpdf libtexpdf.git-rev
$(GIT) diff-index --quiet --cached HEAD || $(GIT) commit -m "chore(build): Pin latest libtexpdf library submodule"

gh-pages:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ $ docker run -it --volume "/usr/share/fonts:/fonts" --volume "$(pwd):/data" --us

[Nix packages][nix] are available and can be installed on several platforms, including NixOS, other Linux distros, and even macOS.

If you have [flakes support][nix-flakes] enabled, you can run sile with:

```console
$ nix run github:sile-typesetter/sile <sile arguments>
```

### From Source

SILE source code can be downloaded from [its website][sile] or directly from [the GitHub releases page][releases].
Expand Down Expand Up @@ -271,6 +277,7 @@ SILE is distributed under the [MIT licence][license].
[list-en]: https://groups.google.com/d/forum/sile-users
[list-ja]: https://groups.google.com/d/forum/sile-users-ja
[nix]: https://nixos.org/nix
[nix-flakes]: https://nixos.wiki/wiki/Flakes#Installing_flakes
[ports]: http://ports.su/print/sile
[ppa]: https://launchpad.net/~sile-typesetter/+archive/ubuntu/sile
[alerque-arch]: https://wiki.archlinux.org/index.php/Unofficial_user_repositories#alerque
10 changes: 10 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions documentation/c02-gettingstarted.sil
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ Packages are available for NixOS:

The Nix package manager is also available on many other Linux distributions, as well as for macOS.

If you have flakes support\footnote{\url{https://nixos.wiki/wiki/Flakes#Installing_flakes}} enabled, you can run sile with:

\begin{terminal}
nix run github:sile-typesetter/sile <sile arguments>
\end{terminal}

\subsection{Void Linux}

Void Linux packages are available in the default package manager.
Expand Down
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
Original file line number Diff line number Diff line change
@@ -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")
./.;
Comment on lines +36 to +38
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git clean -dxff -e node_modules -e .fonts -e .sources -e .husky

Perhaps we should filter these files as well right here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that will help, if $CWD is still set to the project directory when it is actually run it won't matter what was or wasn't copied into the Nix build, SILE will still prefer local resources to it's distribution ones. This is intentional so that users can override virtually anything in the system, but it does make the assumption that any resources in $CWD should be usable.

In any case this is a developer only problem and I'm not too worried about it. I've scheduled this for merge so I can test it out on the SILE website before tagging a release. We can issue any adjustments for more developer convenience in a follow-up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @ctrlcctrlv noted, this is really the same as #1212. I'm not sure what the solution should even be (maybe nothing), but lets move discussion there.

# 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;
doronbehar marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c4ff429664607e1f055d29aeb5dc5d4b6ddb2499
10 changes: 10 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -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