2023-03-27 17:26:08 +03:00
{
inputs = {
2023-09-11 10:57:46 +03:00
nixpkgs . url = " g i t h u b : n i x o s / n i x p k g s / n i x o s - u n s t a b l e " ;
crane = {
url = " g i t h u b : i p e t k o v / c r a n e " ;
2023-06-12 14:49:39 +03:00
inputs . nixpkgs . follows = " n i x p k g s " ;
} ;
2023-03-27 23:42:05 +03:00
2023-10-29 12:12:22 +03:00
systems . url = " g i t h u b : n i x - s y s t e m s / d e f a u l t " ;
} ;
2023-09-11 10:57:46 +03:00
2023-10-29 12:12:22 +03:00
outputs = inputs @ { flake-parts , crane , nixpkgs , . . . }: flake-parts . lib . mkFlake { inherit inputs ; } {
systems = import inputs . systems ;
imports = [
inputs . flake-parts . flakeModules . easyOverlay
] ;
perSystem = { self' , pkgs , lib , . . . }:
let
# Generate the typst package for the given nixpkgs instance.
packageFor = pkgs :
let
inherit ( lib )
importTOML
optionals
sourceByRegex
;
Cargo-toml = importTOML ./Cargo.toml ;
pname = " t y p s t " ;
version = Cargo-toml . workspace . package . version ;
# Crane-based Nix flake configuration.
# Based on https://github.com/ipetkov/crane/blob/master/examples/trunk-workspace/flake.nix
craneLib = crane . mkLib pkgs ;
# Typst files to include in the derivation.
# Here we include Rust files, assets and tests.
src = sourceByRegex ./. [
" ( a s s e t s | c r a t e s | t e s t s ) ( / . * ) ? "
'' C a r g o \ . ( t o m l | l o c k ) ''
'' b u i l d \ . r s ''
2023-09-11 10:57:46 +03:00
] ;
2023-10-29 12:12:22 +03:00
# Typst derivation's args, used within crane's derivation generation
# functions.
commonCraneArgs = {
inherit src pname version ;
buildInputs = optionals pkgs . stdenv . isDarwin [
pkgs . darwin . apple_sdk . frameworks . CoreServices
2023-10-31 01:06:46 +03:00
pkgs . libiconv
2023-10-29 12:12:22 +03:00
] ;
2023-03-27 23:42:05 +03:00
2023-10-29 12:12:22 +03:00
nativeBuildInputs = [ pkgs . installShellFiles ] ;
} ;
2023-04-06 21:14:01 +03:00
2023-10-29 12:12:22 +03:00
# Derivation with just the dependencies, so we don't have to keep
# re-building them.
cargoArtifacts = craneLib . buildDepsOnly commonCraneArgs ;
in
craneLib . buildPackage ( commonCraneArgs // {
2023-09-11 10:57:46 +03:00
inherit cargoArtifacts ;
2023-03-27 23:42:05 +03:00
2023-09-11 10:57:46 +03:00
postInstall = ''
installManPage crates/typst-cli/artifacts /* . 1
installShellCompletion \
crates/typst-cli/artifacts/typst. { bash , fish } \
- - zsh crates/typst-cli/artifacts/_typst
'' ;
2023-04-06 21:14:01 +03:00
2023-09-11 10:57:46 +03:00
GEN_ARTIFACTS = " a r t i f a c t s " ;
2023-10-29 12:12:22 +03:00
meta . mainProgram = " t y p s t " ;
2023-09-11 10:57:46 +03:00
} ) ;
2023-10-29 12:12:22 +03:00
typst = packageFor pkgs ;
in
{
formatter = pkgs . nixpkgs-fmt ;
packages = {
default = typst ;
typst-dev = self' . packages . default ;
2023-03-27 17:26:08 +03:00
} ;
2023-10-29 12:12:22 +03:00
overlayAttrs = builtins . removeAttrs self' . packages [ " d e f a u l t " ] ;
2023-03-27 17:26:08 +03:00
2023-10-29 12:12:22 +03:00
apps . default = {
type = " a p p " ;
program = lib . getExe typst ;
2023-09-11 10:57:46 +03:00
} ;
2023-10-29 12:12:22 +03:00
devShells . default = pkgs . mkShell {
packages = with pkgs ; [
rustc
cargo
] ;
buildInputs = lib . optionals pkgs . stdenv . isDarwin [
pkgs . darwin . apple_sdk . frameworks . CoreServices
pkgs . libiconv
] ;
} ;
} ;
} ;
2023-03-27 17:26:08 +03:00
}