summaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorfigsoda <figsoda@pm.me>2023-03-27 10:26:08 -0400
committerGitHub <noreply@github.com>2023-03-27 16:26:08 +0200
commitb843ca17d8c58689dcef1433dd1c7100394a2a83 (patch)
tree04824d970a61a50dca697ef6396cac7aac5b4925 /flake.nix
parent52905cf77f593c8bee0d96ce0a405bdf80323316 (diff)
Add Nix flake (#158)
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix76
1 files changed, 76 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 00000000..908609cd
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,76 @@
+{
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+ };
+
+ outputs = { self, nixpkgs }:
+ let
+ inherit (builtins)
+ substring
+ ;
+ inherit (nixpkgs.lib)
+ genAttrs
+ optionals
+ ;
+
+ eachSystem = f: genAttrs
+ [
+ "aarch64-darwin"
+ "aarch64-linux"
+ "x86_64-darwin"
+ "x86_64-linux"
+ ]
+ (system: f nixpkgs.legacyPackages.${system});
+
+ rev = fallback:
+ if self ? rev then
+ substring 0 8 self.rev
+ else
+ fallback;
+ 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);
+
+ packages = eachSystem (pkgs: {
+ default = pkgs.rustPlatform.buildRustPackage {
+ pname = "typst";
+ version = rev "00000000";
+
+ src = self;
+
+ cargoLock = {
+ lockFile = ./Cargo.lock;
+ allowBuiltinFetchGit = true;
+ };
+
+ buildInputs = optionals pkgs.stdenv.isDarwin [
+ pkgs.darwin.apple_sdk.frameworks.CoreServices
+ ];
+
+ cargoBuildFlags = [ "-p" "typst-cli" ];
+ cargoTestFlags = [ "-p" "typst-cli" ];
+
+ TYPST_VERSION = rev "(unknown version)";
+ };
+ });
+ };
+}