Add Nix flake (#158)

This commit is contained in:
figsoda 2023-03-27 10:26:08 -04:00 committed by GitHub
parent 52905cf77f
commit b843ca17d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 108 additions and 0 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake

4
.gitignore vendored
View File

@ -18,3 +18,7 @@ bench/target
# Node # Node
node_modules node_modules
package-lock.json package-lock.json
# Nix
/result
.direnv/

27
flake.lock generated Normal file
View File

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1679262748,
"narHash": "sha256-DQCrrAFrkxijC6haUzOC5ZoFqpcv/tg2WxnyW3np1Cc=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "60c1d71f2ba4c80178ec84523c2ca0801522e0a6",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

76
flake.nix Normal file
View File

@ -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)";
};
});
};
}