From 441fda7483f7137a7cdd9d195d95f421196c17de Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 29 Jun 2024 00:33:31 +0300 Subject: [PATCH 1/3] refactor(nix): Update Flake a bit to closer match nixpkgs --- build-aux/pkg.nix | 53 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/build-aux/pkg.nix b/build-aux/pkg.nix index 1d1e1292d..529d2aeb9 100644 --- a/build-aux/pkg.nix +++ b/build-aux/pkg.nix @@ -4,25 +4,25 @@ # `fetchFromGitHub` with fetchSubmodules = true;`. { lib , stdenv +, darwin , version, src, libtexpdf-src +, makeWrapper , autoreconfHook +, rustPlatform , gitMinimal +, runCommand , pkg-config -, jq , cargo -, rustc -, rustPlatform -, makeWrapper -, poppler_utils +, fontconfig +, gentium , harfbuzz , icu -, fontconfig -, lua +, jq , libiconv -, darwin +, lua , makeFontsConf -, gentium -, runCommand +, poppler_utils +, rustc , stylua }: @@ -50,13 +50,13 @@ let luacheck # packages needed for building api docs ldoc - # NOTE: Add lua packages here, to change the luaEnv also read by `flake.nix` ] ++ lib.optionals (lib.versionOlder lua.luaversion "5.2") [ bit32 ] ++ lib.optionals (lib.versionOlder lua.luaversion "5.3") [ compat53 ]); -in stdenv.mkDerivation (finalAttrs: { + + in stdenv.mkDerivation (finalAttrs: { pname = "sile"; inherit version src; @@ -73,16 +73,16 @@ in stdenv.mkDerivation (finalAttrs: { ''; nativeBuildInputs = [ + makeWrapper autoreconfHook - gitMinimal pkg-config + rustPlatform.cargoSetupHook + gitMinimal jq cargo rustc - rustPlatform.cargoSetupHook - poppler_utils - makeWrapper ]; + # In Nixpkgs, we don't copy the Cargo.lock file from the repo to Nixpkgs' # repo, but we inherit src, and specify a hash (it is a fixed output # derivation). `nix-update` and `nixpkgs-update` should be able to catch that @@ -103,21 +103,21 @@ in stdenv.mkDerivation (finalAttrs: { ]; configureFlags = [ + # Build SILE's internal VM against headers from the Nix supplied Lua + "--with-system-lua-sources" # Nix will supply all the Lua dependencies, so stop the build system from # bundling vendored copies of them. - "--with-system-lua-sources" "--with-system-luarocks" # The automake check target uses pdfinfo to confirm the output of a test - # run, and uses autotools to discover it. This flake build eschews that - # test because it is run from the source directory but the binary is - # already built with system paths, so it can't be checked under Nix until - # after install. After install the Makefile isn't available of course, so - # we have our own copy of it with a hard coded path to `pdfinfo`. By - # specifying some binary here we skip the configure time test for - # `pdfinfo`, by using `false` we make sure that if it is expected during - # build time we would fail to build since we only provide it at test time. + # run, and uses autotools to discover it. Nix builds have to that test + # because it is run from the source directory with a binary already built + # with system paths, so it can't be checked under Nix until after install. + # After install the Makefile isn't available of course, so we have our own + # copy of it with a hard coded path to `pdfinfo`. By specifying some binary + # here we skip the configure time test for `pdfinfo`, by using `false` we + # make sure that if it is expected during build time we would fail to build + # since we only provide it at test time. "PDFINFO=false" - #"--with-manual" In Nixpkgs we add this flag, here its not important enough ] ++ lib.optionals (!lua.pkgs.isLuaJIT) [ "--without-luajit" ]; @@ -172,7 +172,6 @@ in stdenv.mkDerivation (finalAttrs: { such as InDesign. ''; homepage = "https://sile-typesetter.org"; - # In nixpkgs we use a version specific URL for CHANGELOG.md changelog = "https://github.com/sile-typesetter/sile/raw/master/CHANGELOG.md"; platforms = lib.platforms.unix; maintainers = with lib.maintainers; [ doronbehar alerque ]; From ad26151d11a43e12787439c15ca27ddc7ebc8852 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sun, 3 Nov 2024 14:41:50 +0300 Subject: [PATCH 2/3] style(nix): Reformat Nix-lang sources with nixfmt-rfc-style --- build-aux/pkg.nix | 206 ++++++++++++++++++++++++++-------------------- default.nix | 23 ++++-- flake.nix | 196 ++++++++++++++++++++++--------------------- libtexpdf | 2 +- shell.nix | 23 ++++-- 5 files changed, 248 insertions(+), 202 deletions(-) diff --git a/build-aux/pkg.nix b/build-aux/pkg.nix index 529d2aeb9..f695a0ae1 100644 --- a/build-aux/pkg.nix +++ b/build-aux/pkg.nix @@ -2,61 +2,71 @@ # the `version`, `src` and `libtexpdf-src` attributes that are given by the # `flake.nix`. In Nixpkgs, we don't need `libtexpdf-src` because we use # `fetchFromGitHub` with fetchSubmodules = true;`. -{ lib -, stdenv -, darwin -, version, src, libtexpdf-src -, makeWrapper -, autoreconfHook -, rustPlatform -, gitMinimal -, runCommand -, pkg-config -, cargo -, fontconfig -, gentium -, harfbuzz -, icu -, jq -, libiconv -, lua -, makeFontsConf -, poppler_utils -, rustc -, stylua +{ + lib, + stdenv, + darwin, + version, + src, + libtexpdf-src, + makeWrapper, + autoreconfHook, + rustPlatform, + gitMinimal, + runCommand, + pkg-config, + cargo, + fontconfig, + gentium, + harfbuzz, + icu, + jq, + libiconv, + lua, + makeFontsConf, + poppler_utils, + rustc, + stylua, }: let - luaEnv = lua.withPackages(ps: with ps; [ - cassowary - cldr - fluent - linenoise - loadkit - lpeg - lua-zlib - lua_cliargs - luaepnf - luaexpat - luafilesystem - luarepl - luasec - luasocket - luautf8 - penlight - vstruct - # lua packages needed for testing - busted - luacheck - # packages needed for building api docs - ldoc - ] ++ lib.optionals (lib.versionOlder lua.luaversion "5.2") [ - bit32 - ] ++ lib.optionals (lib.versionOlder lua.luaversion "5.3") [ - compat53 - ]); + luaEnv = lua.withPackages ( + ps: + with ps; + [ + cassowary + cldr + fluent + linenoise + loadkit + lpeg + lua-zlib + lua_cliargs + luaepnf + luaexpat + luafilesystem + luarepl + luasec + luasocket + luautf8 + penlight + vstruct + # lua packages needed for testing + busted + luacheck + # packages needed for building api docs + ldoc + ] + ++ lib.optionals (lib.versionOlder lua.luaversion "5.2") [ + bit32 + ] + ++ lib.optionals (lib.versionOlder lua.luaversion "5.3") [ + compat53 + ] + ); - in stdenv.mkDerivation (finalAttrs: { +in +stdenv.mkDerivation (finalAttrs: { pname = "sile"; inherit version src; @@ -91,36 +101,40 @@ let lockFile = ../Cargo.lock; }; - buildInputs = [ - luaEnv - harfbuzz - icu - fontconfig - libiconv - stylua - ] ++ lib.optionals stdenv.isDarwin [ - darwin.apple_sdk.frameworks.AppKit - ]; + buildInputs = + [ + luaEnv + harfbuzz + icu + fontconfig + libiconv + stylua + ] + ++ lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.AppKit + ]; - configureFlags = [ - # Build SILE's internal VM against headers from the Nix supplied Lua - "--with-system-lua-sources" - # Nix will supply all the Lua dependencies, so stop the build system from - # bundling vendored copies of them. - "--with-system-luarocks" - # The automake check target uses pdfinfo to confirm the output of a test - # run, and uses autotools to discover it. Nix builds have to that test - # because it is run from the source directory with a binary already built - # with system paths, so it can't be checked under Nix until after install. - # After install the Makefile isn't available of course, so we have our own - # copy of it with a hard coded path to `pdfinfo`. By specifying some binary - # here we skip the configure time test for `pdfinfo`, by using `false` we - # make sure that if it is expected during build time we would fail to build - # since we only provide it at test time. - "PDFINFO=false" - ] ++ lib.optionals (!lua.pkgs.isLuaJIT) [ - "--without-luajit" - ]; + configureFlags = + [ + # Build SILE's internal VM against headers from the Nix supplied Lua + "--with-system-lua-sources" + # Nix will supply all the Lua dependencies, so stop the build system from + # bundling vendored copies of them. + "--with-system-luarocks" + # The automake check target uses pdfinfo to confirm the output of a test + # run, and uses autotools to discover it. Nix builds have to that test + # because it is run from the source directory with a binary already built + # with system paths, so it can't be checked under Nix until after install. + # After install the Makefile isn't available of course, so we have our own + # copy of it with a hard coded path to `pdfinfo`. By specifying some binary + # here we skip the configure time test for `pdfinfo`, by using `false` we + # make sure that if it is expected during build time we would fail to build + # since we only provide it at test time. + "PDFINFO=false" + ] + ++ lib.optionals (!lua.pkgs.isLuaJIT) [ + "--without-luajit" + ]; postPatch = '' patchShebangs build-aux/*.sh build-aux/git-version-gen @@ -147,17 +161,28 @@ let inherit luaEnv; # Copied from Makefile.am tests.test = lib.optionalAttrs (!(stdenv.isDarwin && stdenv.isAarch64)) ( - runCommand "${finalAttrs.pname}-test" { - nativeBuildInputs = [ poppler_utils finalAttrs.finalPackage ]; + runCommand "${finalAttrs.pname}-test" + { + nativeBuildInputs = [ + poppler_utils + finalAttrs.finalPackage + ]; inherit (finalAttrs) FONTCONFIG_FILE; - } '' - output=$(mktemp -t selfcheck-XXXXXX.pdf) - echo "foo" | sile -o $output - - pdfinfo $output | grep "SILE v${finalAttrs.version}" > $out - ''); + } + '' + output=$(mktemp -t selfcheck-XXXXXX.pdf) + echo "foo" | sile -o $output - + pdfinfo $output | grep "SILE v${finalAttrs.version}" > $out + '' + ); }; - outputs = [ "out" "doc" "man" "dev" ]; + outputs = [ + "out" + "doc" + "man" + "dev" + ]; meta = { description = "A typesetting system"; @@ -174,7 +199,10 @@ let homepage = "https://sile-typesetter.org"; changelog = "https://github.com/sile-typesetter/sile/raw/master/CHANGELOG.md"; platforms = lib.platforms.unix; - maintainers = with lib.maintainers; [ doronbehar alerque ]; + maintainers = with lib.maintainers; [ + doronbehar + alerque + ]; license = lib.licenses.mit; }; }) diff --git a/default.nix b/default.nix index 154a0b685..a03231678 100644 --- a/default.nix +++ b/default.nix @@ -1,10 +1,15 @@ # https://wiki.nixos.org/wiki/Flakes#Using_flakes_with_stable_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 +(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 diff --git a/flake.nix b/flake.nix index 055067177..0a9c4ee36 100644 --- a/flake.nix +++ b/flake.nix @@ -22,103 +22,111 @@ flake = false; }; - outputs = { self - , nixpkgs - , flake-utils - , flake-compat - , gitignore - , libtexpdf-src - }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { - inherit system; - }; - inherit (gitignore.lib) gitignoreSource; - # 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 7 self.rev) else "dirty"; - sile = pkgs.callPackage ./build-aux/pkg.nix { - version = "${(pkgs.lib.importJSON ./package.json).version}-${version_rev}-flake"; - src = pkgs.lib.cleanSourceWith { - # Ignore many files that gitignoreSource doesn't ignore, see: - # https://github.com/hercules-ci/gitignore.nix/issues/9#issuecomment-635458762 - filter = path: type: - ! (builtins.any (r: (builtins.match r (builtins.baseNameOf path)) != null) [ - # Nix files - "flake.nix" - "flake.lock" - "default.nix" - "shell.nix" - # git commit and editing format files - ".commitlintrc.yml" - "package.json" - ".husky" - ".editorconfig" - # CI files - ".cirrus.yml" - ".github" - "action.yml" - "azure-pipelines.yml" - "Dockerfile" - # Git files - ".gitattributes" - ".git" - ]); - src = gitignoreSource ./.; + outputs = + { + self, + nixpkgs, + flake-utils, + flake-compat, + gitignore, + libtexpdf-src, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; }; - inherit libtexpdf-src; - }; - inherit (sile.passthru) luaEnv; - in rec { - devShells = { - default = pkgs.mkShell { - inherit (sile) - buildInputs - nativeCheckInputs - FONTCONFIG_FILE - ; - configureFlags = sile.configureFlags ++ [ "--enable-developer-mode" "--with-manual" ]; - nativeBuildInputs = sile.nativeBuildInputs ++ [ - pkgs.luarocks - # For regression test diff highlighting - pkgs.delta - # For commitlint git hook - pkgs.yarn - # For npx - pkgs.nodejs - # For gs, dot, and bsdtar used in building the manual - pkgs.ghostscript - pkgs.graphviz - pkgs.libarchive - ]; + inherit (gitignore.lib) gitignoreSource; + # 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 7 self.rev) else "dirty"; + sile = pkgs.callPackage ./build-aux/pkg.nix { + version = "${(pkgs.lib.importJSON ./package.json).version}-${version_rev}-flake"; + src = pkgs.lib.cleanSourceWith { + # Ignore many files that gitignoreSource doesn't ignore, see: + # https://github.com/hercules-ci/gitignore.nix/issues/9#issuecomment-635458762 + filter = + path: type: + !(builtins.any (r: (builtins.match r (builtins.baseNameOf path)) != null) [ + # Nix files + "flake.nix" + "flake.lock" + "default.nix" + "shell.nix" + # git commit and editing format files + ".commitlintrc.yml" + "package.json" + ".husky" + ".editorconfig" + # CI files + ".cirrus.yml" + ".github" + "action.yml" + "azure-pipelines.yml" + "Dockerfile" + # Git files + ".gitattributes" + ".git" + ]); + src = gitignoreSource ./.; + }; + inherit libtexpdf-src; }; - }; - packages = { - sile-lua5_2 = sile; - sile-lua5_3 = sile.override { - lua = pkgs.lua5_3; + inherit (sile.passthru) luaEnv; + in + rec { + devShells = { + default = pkgs.mkShell { + inherit (sile) + buildInputs + nativeCheckInputs + FONTCONFIG_FILE + ; + configureFlags = sile.configureFlags ++ [ + "--enable-developer-mode" + "--with-manual" + ]; + nativeBuildInputs = sile.nativeBuildInputs ++ [ + pkgs.luarocks + # For regression test diff highlighting + pkgs.delta + # For commitlint git hook + pkgs.yarn + # For npx + pkgs.nodejs + # For gs, dot, and bsdtar used in building the manual + pkgs.ghostscript + pkgs.graphviz + pkgs.libarchive + ]; + }; }; - sile-lua5_4 = sile.override { - lua = pkgs.lua5_4; + packages = { + sile-lua5_2 = sile; + sile-lua5_3 = sile.override { + lua = pkgs.lua5_3; + }; + sile-lua5_4 = sile.override { + lua = pkgs.lua5_4; + }; + sile-luajit = sile.override { + lua = pkgs.luajit; + }; + sile-clang = sile.override { + lua = pkgs.luajit; + # Use the same clang version as Nixpkgs' rust clang stdenv + stdenv = pkgs.rustc.llvmPackages.stdenv; + }; }; - sile-luajit = sile.override { - lua = pkgs.luajit; + defaultPackage = packages.sile-luajit; + apps = rec { + default = sile; + sile = { + type = "app"; + program = "${self.defaultPackage.${system}}/bin/sile"; + }; }; - sile-clang = sile.override { - lua = pkgs.luajit; - # Use the same clang version as Nixpkgs' rust clang stdenv - stdenv = pkgs.rustc.llvmPackages.stdenv; - }; - }; - defaultPackage = packages.sile-luajit; - apps = rec { - default = sile; - sile = { - type = "app"; - program = "${self.defaultPackage.${system}}/bin/sile"; - }; - }; - defaultApp = apps.sile; - } - ); + defaultApp = apps.sile; + } + ); } diff --git a/libtexpdf b/libtexpdf index 736a5e753..1891bee5e 160000 --- a/libtexpdf +++ b/libtexpdf @@ -1 +1 @@ -Subproject commit 736a5e7530c13582ea704a061a358d0caa774916 +Subproject commit 1891bee5e0b73165e4a259f910d3ea3fe1df0b42 diff --git a/shell.nix b/shell.nix index be1a8d97b..b6720f7f1 100644 --- a/shell.nix +++ b/shell.nix @@ -1,10 +1,15 @@ # https://wiki.nixos.org/wiki/Flakes#Using_flakes_with_stable_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 +(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 From 24e5649f5533d30b55fc57f6ce4ec479da25080d Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sun, 3 Nov 2024 16:38:29 +0300 Subject: [PATCH 3/3] chore(nix): Update Flake with upstream Nix package changes --- build-aux/pkg.nix | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/build-aux/pkg.nix b/build-aux/pkg.nix index f695a0ae1..6b074110b 100644 --- a/build-aux/pkg.nix +++ b/build-aux/pkg.nix @@ -3,30 +3,39 @@ # `flake.nix`. In Nixpkgs, we don't need `libtexpdf-src` because we use # `fetchFromGitHub` with fetchSubmodules = true;`. { - lib, - stdenv, - darwin, - version, - src, - libtexpdf-src, - makeWrapper, + # Nix specific packaging and flake tooling autoreconfHook, - rustPlatform, + darwin, gitMinimal, + lib, + makeFontsConf, + makeWrapper, runCommand, - pkg-config, + rustPlatform, + src, + stdenv, + version, + + # Upstream build time dependencies cargo, + jq, + pkg-config, + poppler_utils, + rustc, + + # Upstream run time dependencies fontconfig, gentium, harfbuzz, icu, - jq, libiconv, lua, - makeFontsConf, - poppler_utils, - rustc, + + # Developer environment dependencies stylua, + + # This package + libtexpdf-src, }: let @@ -51,9 +60,11 @@ let luautf8 penlight vstruct + # lua packages needed for testing busted luacheck + # packages needed for building api docs ldoc ] @@ -83,13 +94,13 @@ stdenv.mkDerivation (finalAttrs: { ''; nativeBuildInputs = [ - makeWrapper autoreconfHook - pkg-config - rustPlatform.cargoSetupHook + cargo gitMinimal jq - cargo + makeWrapper + pkg-config + rustPlatform.cargoSetupHook rustc ]; @@ -103,24 +114,25 @@ stdenv.mkDerivation (finalAttrs: { buildInputs = [ - luaEnv + fontconfig harfbuzz icu - fontconfig libiconv + luaEnv + + # Developer tooling stylua - ] - ++ lib.optionals stdenv.isDarwin [ - darwin.apple_sdk.frameworks.AppKit - ]; + ] ++ lib.optional stdenv.hostPlatform.isDarwin darwin.apple_sdk.frameworks.AppKit; configureFlags = [ # Build SILE's internal VM against headers from the Nix supplied Lua "--with-system-lua-sources" + # Nix will supply all the Lua dependencies, so stop the build system from # bundling vendored copies of them. "--with-system-luarocks" + # The automake check target uses pdfinfo to confirm the output of a test # run, and uses autotools to discover it. Nix builds have to that test # because it is run from the source directory with a binary already built @@ -140,7 +152,7 @@ stdenv.mkDerivation (finalAttrs: { patchShebangs build-aux/*.sh build-aux/git-version-gen ''; - NIX_LDFLAGS = lib.optionalString stdenv.isDarwin "-framework AppKit"; + NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isDarwin "-framework AppKit"; FONTCONFIG_FILE = makeFontsConf { fontDirectories = [ @@ -160,7 +172,7 @@ stdenv.mkDerivation (finalAttrs: { # So it will be easier to inspect this environment, in comparison to others inherit luaEnv; # Copied from Makefile.am - tests.test = lib.optionalAttrs (!(stdenv.isDarwin && stdenv.isAarch64)) ( + tests.test = lib.optionalAttrs (!(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)) ( runCommand "${finalAttrs.pname}-test" { nativeBuildInputs = [ @@ -185,7 +197,7 @@ stdenv.mkDerivation (finalAttrs: { ]; meta = { - description = "A typesetting system"; + description = "Typesetting system"; longDescription = '' SILE is a typesetting system; its job is to produce beautiful printed documents. Conceptually, SILE is similar to TeX—from