diff options
| -rw-r--r-- | flake.lock | 160 | ||||
| -rw-r--r-- | flake.nix | 159 |
2 files changed, 223 insertions, 96 deletions
@@ -1,33 +1,107 @@ { "nodes": { - "fenix": { + "crane": { "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" ], - "rust-analyzer-src": "rust-analyzer-src" + "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1686291735, - "narHash": "sha256-mpq2m6TN3ImqqUqA4u93NvkZu5vH//3spqjmPRbRlvA=", - "owner": "nix-community", - "repo": "fenix", - "rev": "6e6a94c4d0cac4821b6452fbae46609b89a8ddcf", + "lastModified": 1693787605, + "narHash": "sha256-rwq5U8dy+a9JFny/73L0SJu1GfWwATMPMTp7D+mjHy8=", + "owner": "ipetkov", + "repo": "crane", + "rev": "8b4f7a4dab2120cf41e7957a28a853f45016bd9d", "type": "github" }, "original": { - "owner": "nix-community", - "repo": "fenix", + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693611461, + "narHash": "sha256-aPODl8vAgGQ0ZYFIRisxYG5MOGSkIczvu2Cd8Gb9+1Y=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "7f53fdb7bdc5bb237da7fefef12d099e4fd611ca", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1686226982, - "narHash": "sha256-nLuiPoeiVfqqzeq9rmXxpybh77VS37dsY/k8N2LoxVg=", + "lastModified": 1693985761, + "narHash": "sha256-K5b+7j7Tt3+AqbWkcw+wMeqOAWyCD1MH26FPZyWXpdo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "a64b73e07d4aa65cfcbda29ecf78eaf9e72e44bd", + "rev": "0bffda19b8af722f8069d09d8b6a24594c80b352", "type": "github" }, "original": { @@ -39,24 +113,64 @@ }, "root": { "inputs": { - "fenix": "fenix", + "crane": "crane", + "flake-parts": "flake-parts", + "flake-utils": "flake-utils_2", "nixpkgs": "nixpkgs" } }, - "rust-analyzer-src": { - "flake": false, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "crane", + "flake-utils" + ], + "nixpkgs": [ + "crane", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693707092, + "narHash": "sha256-HR1EnynBSPqbt+04/yxxqsG1E3n6uXrOl7SPco/UnYo=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "98ccb73e6eefc481da6039ee57ad8818d1ca8d56", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { "locked": { - "lastModified": 1686239338, - "narHash": "sha256-c6Mm7UnDf3j3akY3YB3rELFA76QRbB8ttSBsh00LWi0=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "9c03aa1ac2e67051db83a85baf3cfee902e4dd84", + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", + "owner": "nix-systems", + "repo": "default", "type": "github" } } @@ -1,103 +1,116 @@ { inputs = { - fenix = { - url = "github:nix-community/fenix"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + + flake-utils.url = "github:numtide/flake-utils"; + + crane = { + url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; }; - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; }; - outputs = { self, fenix, nixpkgs }: + outputs = inputs@{ flake-parts, flake-utils, crane, nixpkgs, ... }: let - inherit (nixpkgs.lib) - genAttrs - importTOML - optionals - sourceByRegex - ; - - eachSystem = f: genAttrs - [ - "aarch64-darwin" - "aarch64-linux" - "x86_64-darwin" - "x86_64-linux" - ] - (system: f nixpkgs.legacyPackages.${system}); - + # Generate the typst package for the given nixpkgs instance. packageFor = pkgs: let - rust = fenix.packages.${pkgs.stdenv.hostPlatform.system}.minimal.toolchain; - rustPlatform = pkgs.makeRustPlatform { - cargo = rust; - rustc = rust; - }; - in - rustPlatform.buildRustPackage { + inherit (nixpkgs.lib) + importTOML + optionals + sourceByRegex + ; + Cargo-toml = importTOML ./Cargo.toml; + pname = "typst"; - inherit ((importTOML ./Cargo.toml).workspace.package) version; + 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 ./. [ "(assets|crates|tests)(/.*)?" ''Cargo\.(toml|lock)'' ''build\.rs'' ]; - cargoLock = { - lockFile = ./Cargo.lock; - allowBuiltinFetchGit = true; + # 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 + ]; + + nativeBuildInputs = [ pkgs.installShellFiles ]; }; - nativeBuildInputs = [ - pkgs.installShellFiles - ]; + # Derivation with just the dependencies, so we don't have to keep + # re-building them. + cargoArtifacts = craneLib.buildDepsOnly commonCraneArgs; - buildInputs = optionals pkgs.stdenv.isDarwin [ - pkgs.darwin.apple_sdk.frameworks.CoreServices - ]; + typst = craneLib.buildPackage (commonCraneArgs // { + inherit cargoArtifacts; - postInstall = '' - installManPage crates/typst-cli/artifacts/*.1 - installShellCompletion \ - crates/typst-cli/artifacts/typst.{bash,fish} \ - --zsh crates/typst-cli/artifacts/_typst - ''; + postInstall = '' + installManPage crates/typst-cli/artifacts/*.1 + installShellCompletion \ + crates/typst-cli/artifacts/typst.{bash,fish} \ + --zsh crates/typst-cli/artifacts/_typst + ''; - GEN_ARTIFACTS = "artifacts"; - }; + GEN_ARTIFACTS = "artifacts"; + }); + in + typst; in - { - devShells = eachSystem (pkgs: { - default = pkgs.mkShell { - packages = - let - fenix' = fenix.packages.${pkgs.stdenv.hostPlatform.system}; - in - [ - (fenix'.default.withComponents [ - "cargo" - "clippy" - "rustc" - "rustfmt" - ]) - fenix'.rust-analyzer - ]; + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "aarch64-darwin" + "aarch64-linux" + "x86_64-darwin" + "x86_64-linux" + ]; - buildInputs = optionals pkgs.stdenv.isDarwin [ - pkgs.darwin.apple_sdk.frameworks.CoreServices - pkgs.libiconv - ]; + flake = { + overlays.default = _: prev: { + typst-dev = packageFor prev; }; - }); + }; - formatter = eachSystem (pkgs: pkgs.nixpkgs-fmt); + perSystem = { pkgs, ... }: + let + inherit (pkgs) lib; + typst = packageFor pkgs; + in + { + packages.default = typst; - overlays.default = _: prev: { - typst-dev = packageFor prev; - }; + apps.default = flake-utils.lib.mkApp { + drv = typst; + }; + + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + rustc + cargo + ]; - packages = eachSystem (pkgs: { - default = packageFor pkgs; - }); + buildInputs = lib.optionals pkgs.stdenv.isDarwin [ + pkgs.darwin.apple_sdk.frameworks.CoreServices + pkgs.libiconv + ]; + }; + }; }; } |
