typst/flake.nix

88 lines
2.0 KiB
Nix
Raw Normal View History

2023-03-27 17:26:08 +03:00
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
inherit (nixpkgs.lib)
genAttrs
importTOML
2023-03-27 17:26:08 +03:00
optionals
cleanSource
2023-03-27 17:26:08 +03:00
;
eachSystem = f: genAttrs
[
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
]
(system: f nixpkgs.legacyPackages.${system});
rev = fallback:
self.shortRev or fallback;
2023-03-27 23:42:05 +03:00
packageFor = pkgs: pkgs.rustPlatform.buildRustPackage rec {
2023-03-27 23:42:05 +03:00
pname = "typst";
inherit ((importTOML ./Cargo.toml).workspace.package) version;
2023-03-27 23:42:05 +03:00
src = cleanSource ./.;
2023-03-27 23:42:05 +03:00
cargoLock = {
lockFile = ./Cargo.lock;
allowBuiltinFetchGit = true;
};
nativeBuildInputs = [
pkgs.installShellFiles
];
2023-03-27 23:42:05 +03:00
buildInputs = optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.CoreServices
];
postInstall = ''
installManPage cli/artifacts/*.1
installShellCompletion \
cli/artifacts/typst.{bash,fish} \
--zsh cli/artifacts/_typst
'';
GEN_ARTIFACTS = "artifacts";
TYPST_VERSION = "${version} (${rev "unknown hash"})";
2023-03-27 23:42:05 +03:00
};
2023-03-27 17:26:08 +03:00
in
{
devShells = eachSystem (pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
cargo
clippy
rust-analyzer
rustc
rustfmt
];
buildInputs = optionals pkgs.stdenv.isDarwin [
pkgs.darwin.apple_sdk.frameworks.CoreServices
pkgs.libiconv
];
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
};
});
formatter = eachSystem (pkgs: pkgs.nixpkgs-fmt);
2023-03-27 23:42:05 +03:00
overlays.default = _: prev: {
typst-dev = packageFor prev;
};
2023-03-27 17:26:08 +03:00
2023-03-27 23:42:05 +03:00
packages = eachSystem (pkgs: {
default = packageFor pkgs;
2023-03-27 17:26:08 +03:00
});
};
}