mirror of
https://github.com/typst/typst
synced 2025-05-15 09:35:28 +08:00
Various improvements to nix flake (#5012)
This commit is contained in:
parent
d8cdc66c57
commit
5d8685e450
98
flake.lock
generated
98
flake.lock
generated
@ -1,17 +1,12 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"crane": {
|
"crane": {
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1698166613,
|
"lastModified": 1727060013,
|
||||||
"narHash": "sha256-y4rdN4flxRiROqNi1waMYIZj/Fs7L2OrszFk/1ry9vU=",
|
"narHash": "sha256-/fC5YlJy4IoAW9GhkJiwyzk0K/gQd9Qi4rRcoweyG9E=",
|
||||||
"owner": "ipetkov",
|
"owner": "ipetkov",
|
||||||
"repo": "crane",
|
"repo": "crane",
|
||||||
"rev": "b7db46f0f1751f7b1d1911f6be7daf568ad5bc65",
|
"rev": "6b40cc876c929bfe1e3a24bf538ce3b5622646ba",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -20,30 +15,52 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"fenix": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"rust-analyzer-src": "rust-analyzer-src"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1727245890,
|
||||||
|
"narHash": "sha256-B4gUhZxqdn24PqL7z7ZuvLOS84HVskhKRByWdgA4/RI=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "fenix",
|
||||||
|
"rev": "de3acda8b67b92abeeb35ac236924afd959874ad",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "fenix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"flake-parts": {
|
"flake-parts": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs-lib": "nixpkgs-lib"
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1696343447,
|
"lastModified": 1726153070,
|
||||||
"narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=",
|
"narHash": "sha256-HO4zgY0ekfwO5bX0QH/3kJ/h4KvUDFZg8YpkNwIbg1U=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "flake-parts",
|
"repo": "flake-parts",
|
||||||
"rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4",
|
"rev": "bcef6817a8b2aa20a5a6dbb19b43e63c5bf8619a",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "flake-parts",
|
"owner": "hercules-ci",
|
||||||
"type": "indirect"
|
"repo": "flake-parts",
|
||||||
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1720957393,
|
"lastModified": 1726937504,
|
||||||
"narHash": "sha256-oedh2RwpjEa+TNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA=",
|
"narHash": "sha256-bvGoiQBvponpZh8ClUcmJ6QnsNKw0EMrCQJARK3bI1c=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "693bc46d169f5af9c992095736e82c3488bf7dbb",
|
"rev": "9357f4f23713673f310988025d9dc261c20e70c6",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@ -55,30 +72,55 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs-lib": {
|
"nixpkgs-lib": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"dir": "lib",
|
"lastModified": 1725233747,
|
||||||
"lastModified": 1696019113,
|
"narHash": "sha256-Ss8QWLXdr2JCBPcYChJhz4xJm+h/xjl4G0c0XlP6a74=",
|
||||||
"narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=",
|
"type": "tarball",
|
||||||
"owner": "NixOS",
|
"url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz"
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a",
|
|
||||||
"type": "github"
|
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"dir": "lib",
|
"type": "tarball",
|
||||||
"owner": "NixOS",
|
"url": "https://github.com/NixOS/nixpkgs/archive/356624c12086a18f2ea2825fed34523d60ccc4e3.tar.gz"
|
||||||
"ref": "nixos-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"crane": "crane",
|
"crane": "crane",
|
||||||
|
"fenix": "fenix",
|
||||||
"flake-parts": "flake-parts",
|
"flake-parts": "flake-parts",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
|
"rust-manifest": "rust-manifest",
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"rust-analyzer-src": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1727104575,
|
||||||
|
"narHash": "sha256-lB/ZS0SnHyE8Z3G8DIL/QJPg6w6x5ZhgVO2pBqnz89g=",
|
||||||
|
"owner": "rust-lang",
|
||||||
|
"repo": "rust-analyzer",
|
||||||
|
"rev": "3d0343251fe084b335b55c17a52bb4a3527b1bd0",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "rust-lang",
|
||||||
|
"ref": "nightly",
|
||||||
|
"repo": "rust-analyzer",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rust-manifest": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"narHash": "sha256-3EJkGxF108nDakQ5ZlSQezA8XJMIEk/c9aLDPAUfybM=",
|
||||||
|
"type": "file",
|
||||||
|
"url": "https://static.rust-lang.org/dist/channel-rust-1.80.1.toml"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"type": "file",
|
||||||
|
"url": "https://static.rust-lang.org/dist/channel-rust-1.80.1.toml"
|
||||||
|
}
|
||||||
|
},
|
||||||
"systems": {
|
"systems": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1681028828,
|
"lastModified": 1681028828,
|
||||||
|
100
flake.nix
100
flake.nix
@ -1,16 +1,21 @@
|
|||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
|
systems.url = "github:nix-systems/default";
|
||||||
|
|
||||||
crane = {
|
crane.url = "github:ipetkov/crane";
|
||||||
url = "github:ipetkov/crane";
|
fenix = {
|
||||||
|
url = "github:nix-community/fenix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
rust-manifest = {
|
||||||
systems.url = "github:nix-systems/default";
|
url = "https://static.rust-lang.org/dist/channel-rust-1.80.1.toml";
|
||||||
|
flake = false;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs@{ flake-parts, crane, nixpkgs, self, ... }: flake-parts.lib.mkFlake { inherit inputs; } {
|
outputs = inputs@{ flake-parts, crane, nixpkgs, fenix, rust-manifest, self, ... }: flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
systems = import inputs.systems;
|
systems = import inputs.systems;
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
@ -19,45 +24,44 @@
|
|||||||
|
|
||||||
perSystem = { self', pkgs, lib, ... }:
|
perSystem = { self', pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
# Generate the typst package for the given nixpkgs instance.
|
cargoToml = lib.importTOML ./Cargo.toml;
|
||||||
packageFor = pkgs:
|
|
||||||
let
|
|
||||||
inherit (lib)
|
|
||||||
importTOML
|
|
||||||
optionals
|
|
||||||
sourceByRegex
|
|
||||||
;
|
|
||||||
Cargo-toml = importTOML ./Cargo.toml;
|
|
||||||
|
|
||||||
pname = "typst";
|
pname = "typst";
|
||||||
version = Cargo-toml.workspace.package.version;
|
version = cargoToml.workspace.package.version;
|
||||||
|
|
||||||
|
rust-toolchain = (fenix.packages.x86_64-linux.fromManifestFile rust-manifest).defaultToolchain;
|
||||||
|
|
||||||
# Crane-based Nix flake configuration.
|
# Crane-based Nix flake configuration.
|
||||||
# Based on https://github.com/ipetkov/crane/blob/master/examples/trunk-workspace/flake.nix
|
# Based on https://github.com/ipetkov/crane/blob/master/examples/trunk-workspace/flake.nix
|
||||||
craneLib = crane.mkLib pkgs;
|
craneLib = (crane.mkLib pkgs).overrideToolchain rust-toolchain;
|
||||||
|
|
||||||
# Typst files to include in the derivation.
|
# Typst files to include in the derivation.
|
||||||
# Here we include Rust files, docs and tests.
|
# Here we include Rust files, docs and tests.
|
||||||
src = sourceByRegex ./. [
|
src = lib.fileset.toSource {
|
||||||
"(docs|crates|tests)(/.*)?"
|
root = ./.;
|
||||||
''Cargo\.(toml|lock)''
|
fileset = lib.fileset.unions [
|
||||||
''build\.rs''
|
./Cargo.toml
|
||||||
|
./Cargo.lock
|
||||||
|
./rustfmt.toml
|
||||||
|
./crates
|
||||||
|
./docs
|
||||||
|
./tests
|
||||||
];
|
];
|
||||||
|
};
|
||||||
|
|
||||||
# Typst derivation's args, used within crane's derivation generation
|
# Typst derivation's args, used within crane's derivation generation
|
||||||
# functions.
|
# functions.
|
||||||
commonCraneArgs = {
|
commonCraneArgs = {
|
||||||
inherit src pname version;
|
inherit src pname version;
|
||||||
|
|
||||||
buildInputs = (optionals pkgs.stdenv.isDarwin [
|
buildInputs = [
|
||||||
|
pkgs.openssl
|
||||||
|
] ++ (lib.optionals pkgs.stdenv.isDarwin [
|
||||||
pkgs.darwin.apple_sdk.frameworks.CoreServices
|
pkgs.darwin.apple_sdk.frameworks.CoreServices
|
||||||
pkgs.libiconv
|
pkgs.libiconv
|
||||||
]) ++ [
|
]);
|
||||||
pkgs.openssl
|
|
||||||
];
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
pkgs.installShellFiles
|
|
||||||
pkgs.pkg-config
|
pkgs.pkg-config
|
||||||
pkgs.openssl.dev
|
pkgs.openssl.dev
|
||||||
];
|
];
|
||||||
@ -66,10 +70,14 @@
|
|||||||
# Derivation with just the dependencies, so we don't have to keep
|
# Derivation with just the dependencies, so we don't have to keep
|
||||||
# re-building them.
|
# re-building them.
|
||||||
cargoArtifacts = craneLib.buildDepsOnly commonCraneArgs;
|
cargoArtifacts = craneLib.buildDepsOnly commonCraneArgs;
|
||||||
in
|
|
||||||
craneLib.buildPackage (commonCraneArgs // {
|
typst = craneLib.buildPackage (commonCraneArgs // {
|
||||||
inherit cargoArtifacts;
|
inherit cargoArtifacts;
|
||||||
|
|
||||||
|
nativeBuildInputs = commonCraneArgs.nativeBuildInputs ++ [
|
||||||
|
pkgs.installShellFiles
|
||||||
|
];
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
installManPage crates/typst-cli/artifacts/*.1
|
installManPage crates/typst-cli/artifacts/*.1
|
||||||
installShellCompletion \
|
installShellCompletion \
|
||||||
@ -81,14 +89,12 @@
|
|||||||
TYPST_VERSION =
|
TYPST_VERSION =
|
||||||
let
|
let
|
||||||
rev = self.shortRev or "dirty";
|
rev = self.shortRev or "dirty";
|
||||||
version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version;
|
version = cargoToml.workspace.package.version;
|
||||||
in
|
in
|
||||||
"${version} (${rev})";
|
"${version} (${rev})";
|
||||||
|
|
||||||
meta.mainProgram = "typst";
|
meta.mainProgram = "typst";
|
||||||
});
|
});
|
||||||
|
|
||||||
typst = packageFor pkgs;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
formatter = pkgs.nixpkgs-fmt;
|
formatter = pkgs.nixpkgs-fmt;
|
||||||
@ -105,22 +111,28 @@
|
|||||||
program = lib.getExe typst;
|
program = lib.getExe typst;
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell {
|
checks = {
|
||||||
packages = with pkgs; [
|
typst-fmt = craneLib.cargoFmt commonCraneArgs;
|
||||||
rustc
|
typst-clippy = craneLib.cargoClippy (commonCraneArgs // {
|
||||||
cargo
|
inherit cargoArtifacts;
|
||||||
];
|
cargoClippyExtraArgs = "--workspace -- --deny warnings";
|
||||||
|
});
|
||||||
|
typst-test = craneLib.cargoTest (commonCraneArgs // {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
cargoTestExtraArgs = "--workspace";
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
buildInputs = (lib.optionals pkgs.stdenv.isDarwin [
|
devShells.default = craneLib.devShell {
|
||||||
pkgs.darwin.apple_sdk.frameworks.CoreServices
|
checks = self'.checks;
|
||||||
pkgs.libiconv
|
inputsFrom = [ typst ];
|
||||||
]) ++ [
|
|
||||||
pkgs.openssl
|
|
||||||
];
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
packages = [
|
||||||
pkgs.pkg-config
|
# A script for quickly running tests.
|
||||||
pkgs.openssl.dev
|
# See https://github.com/typst/typst/blob/main/tests/README.md#making-an-alias
|
||||||
|
(pkgs.writeShellScriptBin "testit" ''
|
||||||
|
cargo test --workspace --test tests -- "$@"
|
||||||
|
'')
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user