diff options
| author | Pol Dellaiera <pol.dellaiera@protonmail.com> | 2023-10-29 10:12:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-29 10:12:22 +0100 |
| commit | 102a57056b41e3965a1acf528f17dd0c5e5ea673 (patch) | |
| tree | 0ac39a33fa273577d7df4a9f814c5940904038c3 /flake.nix | |
| parent | 29130a26f83f28ae37be1ff4f57877e765d27285 (diff) | |
Prevent Nix warning when using `lib.getExe` (#2507)
1. Remove unecessary inputs
2. Use `flake-parts` module `easyOverlay`
3. Add default Nix formatter
4. Make `systems` attr overridable
Diffstat (limited to 'flake.nix')
| -rw-r--r-- | flake.nix | 164 |
1 files changed, 78 insertions, 86 deletions
@@ -2,64 +2,65 @@ inputs = { 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"; }; - }; - - outputs = inputs@{ flake-parts, flake-utils, crane, nixpkgs, ... }: - let - # Generate the typst package for the given nixpkgs instance. - packageFor = pkgs: - let - inherit (nixpkgs.lib) - importTOML - optionals - sourceByRegex - ; - Cargo-toml = importTOML ./Cargo.toml; - - pname = "typst"; - 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'' - ]; - # Typst derivation's args, used within crane's derivation generation - # functions. - commonCraneArgs = { - inherit src pname version; + systems.url = "github:nix-systems/default"; + }; - buildInputs = optionals pkgs.stdenv.isDarwin [ - pkgs.darwin.apple_sdk.frameworks.CoreServices + outputs = inputs@{ flake-parts, crane, nixpkgs, ... }: flake-parts.lib.mkFlake { inherit inputs; } { + systems = import inputs.systems; + + imports = [ + inputs.flake-parts.flakeModules.easyOverlay + ]; + + perSystem = { self', pkgs, lib, ... }: + let + # Generate the typst package for the given nixpkgs instance. + packageFor = pkgs: + let + inherit (lib) + importTOML + optionals + sourceByRegex + ; + Cargo-toml = importTOML ./Cargo.toml; + + pname = "typst"; + 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'' ]; - nativeBuildInputs = [ pkgs.installShellFiles ]; - }; + # 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 + ]; - # Derivation with just the dependencies, so we don't have to keep - # re-building them. - cargoArtifacts = craneLib.buildDepsOnly commonCraneArgs; + nativeBuildInputs = [ pkgs.installShellFiles ]; + }; - typst = craneLib.buildPackage (commonCraneArgs // { + # Derivation with just the dependencies, so we don't have to keep + # re-building them. + cargoArtifacts = craneLib.buildDepsOnly commonCraneArgs; + in + craneLib.buildPackage (commonCraneArgs // { inherit cargoArtifacts; postInstall = '' @@ -70,47 +71,38 @@ ''; GEN_ARTIFACTS = "artifacts"; + + meta.mainProgram = "typst"; }); - in - typst; - in - flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ - "aarch64-darwin" - "aarch64-linux" - "x86_64-darwin" - "x86_64-linux" - ]; - - flake = { - overlays.default = _: prev: { - typst-dev = packageFor prev; + + typst = packageFor pkgs; + in + { + formatter = pkgs.nixpkgs-fmt; + + packages = { + default = typst; + typst-dev = self'.packages.default; }; - }; - perSystem = { pkgs, ... }: - let - inherit (pkgs) lib; - typst = packageFor pkgs; - in - { - packages.default = typst; - - apps.default = flake-utils.lib.mkApp { - drv = typst; - }; - - devShells.default = pkgs.mkShell { - packages = with pkgs; [ - rustc - cargo - ]; + overlayAttrs = builtins.removeAttrs self'.packages [ "default" ]; - buildInputs = lib.optionals pkgs.stdenv.isDarwin [ - pkgs.darwin.apple_sdk.frameworks.CoreServices - pkgs.libiconv - ]; - }; + apps.default = { + type = "app"; + program = lib.getExe typst; }; - }; + + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + rustc + cargo + ]; + + buildInputs = lib.optionals pkgs.stdenv.isDarwin [ + pkgs.darwin.apple_sdk.frameworks.CoreServices + pkgs.libiconv + ]; + }; + }; + }; } |
