Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Nix dependency: flake-utils + fixups #802

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let
craneLibWasm = craneLib.overrideToolchain rustWithWasmTarget;
in
{
passtru = {
passthru = {
inherit craneLibWasm;
};

Expand Down
9 changes: 3 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

162 changes: 91 additions & 71 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,52 @@
flake = false;
};

flake-utils.url = "github:numtide/flake-utils";

tree-sitter-nickel-input = {
tree-sitter-nickel = {
url = "github:nickel-lang/tree-sitter-nickel";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};

outputs = inputs:
with inputs;
flake-utils.lib.eachDefaultSystem (
system:
let
wasm-bindgen-cli-overlay = final: prev:
outputs = { self, nixpkgs, ... }@inputs:
let
supportedSystems = nixpkgs.lib.systems.flakeExposed;
yannham marked this conversation as resolved.
Show resolved Hide resolved

pkgsFor = nixpkgs.lib.genAttrs supportedSystems (system: rec {
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.tree-sitter-grammars
self.overlays.wasm-bindgen-cli
inputs.rust-overlay.overlays.default
];
};

topiaryPkgs = pkgs.callPackage ./default.nix {
inherit (inputs) advisory-db crane rust-overlay;
inherit (pkgs.tree-sitter-grammars) tree-sitter-nickel;
craneLib = inputs.crane.mkLib pkgs;
};

binPkgs = pkgs.callPackage ./bin/default.nix { };
});

forAllSystems = fn: nixpkgs.lib.genAttrs supportedSystems (system: fn rec {
inherit system;
inherit (pkgsFor.${system}) pkgs topiaryPkgs binPkgs;
inherit (pkgs) lib;
craneLib = inputs.crane.mkLib pkgs;
});
in
{
overlays = {
tree-sitter-grammars = final: prev: {
# Nickel *should* have an overlay like this already
tree-sitter-grammars = prev.tree-sitter-grammars // {
tree-sitter-nickel = inputs.tree-sitter-nickel.packages.${prev.system}.default;
};
};

wasm-bindgen-cli = final: prev:
let
cargoLock = builtins.fromTOML (builtins.readFile ./Cargo.lock);
wasmBindgenCargoVersions = builtins.map ({ version, ... }: version) (builtins.filter ({ name, ... }: name == "wasm-bindgen") cargoLock.package);
Expand All @@ -52,74 +83,63 @@
cargoHash = "sha256-3vxVI0BhNz/9m59b+P2YEIrwGwlp7K3pyPKt4VqQuHE=";
};
};

pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default wasm-bindgen-cli-overlay ];
};

craneLib = crane.mkLib pkgs;

tree-sitter-nickel = tree-sitter-nickel-input.packages.${system}.default;

topiaryPkgs = pkgs.callPackage ./default.nix {
inherit advisory-db crane rust-overlay craneLib tree-sitter-nickel;
};
binPkgs = pkgs.callPackage ./bin/default.nix { };
in
{
packages = rec {
inherit (topiaryPkgs)
topiary-playground
topiary-queries
client-app;

topiary-cli = topiaryPkgs.topiary-cli { };
topiary-cli-nix = topiaryPkgs.topiary-cli { nixSupport = true; };

inherit (binPkgs)
# FIXME: Broken
# generate-coverage
playground
update-wasm-app
update-wasm-grammars
verify-documented-usage;

default = topiary-cli;
};

checks = {
inherit (topiaryPkgs) clippy clippy-wasm fmt topiary-core topiary-playground audit benchmark;
topiary-cli = topiaryPkgs.topiary-cli { };

## Check that the `lib.pre-commit-hook` output builds/evaluates
## correctly. `deepSeq e1 e2` evaluates `e1` strictly in depth before
## returning `e2`. We use this trick because checks need to be
## derivations, which `lib.pre-commit-hook` is not.
pre-commit-hook = builtins.deepSeq self.lib.${system}.pre-commit-hook pkgs.hello;
};

devShells =
let
checksLight = {
};

packages = forAllSystems ({ system, pkgs, topiaryPkgs, binPkgs, ... }: {
inherit (topiaryPkgs)
topiary-playground
topiary-queries
client-app;

topiary-cli = topiaryPkgs.topiary-cli { };
topiary-cli-nix = topiaryPkgs.topiary-cli { nixSupport = true; };

inherit (binPkgs)
# FIXME: Broken
# generate-coverage
playground
update-wasm-app
update-wasm-grammars
verify-documented-usage;

default = self.packages.${system}.topiary-cli;
});

checks = forAllSystems ({ system, pkgs, topiaryPkgs, ... }: {
inherit (topiaryPkgs) clippy clippy-wasm fmt topiary-core topiary-playground audit benchmark;
topiary-cli = self.packages.${system}.topiary-cli;

## Check that the `lib.pre-commit-hook` output builds/evaluates
## correctly. `deepSeq e1 e2` evaluates `e1` strictly in depth before
## returning `e2`. We use this trick because checks need to be
## derivations, which `lib.pre-commit-hook` is not.
pre-commit-hook = builtins.deepSeq self.lib.${system}.pre-commit-hook pkgs.hello;
});

devShells = forAllSystems ({ system, pkgs, craneLib, topiaryPkgs, binPkgs, ... }:
{
default = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; inherit craneLib; inherit binPkgs; };
light = pkgs.callPackage ./shell.nix {
checks = /* checksLight */ {
inherit (topiaryPkgs) clippy fmt topiary-core;
topiary-cli = topiaryPkgs.topiary-cli { };
topiary-cli = self.packages.${system}.topiary-cli;
};
in
{
default = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; inherit craneLib; inherit binPkgs; };
light = pkgs.callPackage ./shell.nix { checks = checksLight; inherit craneLib; inherit binPkgs; optionals = false; };
wasm = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; craneLib = topiaryPkgs.passtru.craneLibWasm; inherit binPkgs; };
inherit craneLib;
inherit binPkgs;
optionals = false;
};
wasm = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; craneLib = topiaryPkgs.passthru.craneLibWasm; inherit binPkgs; };
});

## For easy use in https://github.com/cachix/pre-commit-hooks.nix
lib.pre-commit-hook = {
## For easy use in https://github.com/cachix/pre-commit-hooks.nix
lib = forAllSystems ({ system, lib, ... }: {
pre-commit-hook = {
enable = true;
name = "topiary";
description = "A general code formatter based on tree-sitter.";
entry = "${pkgs.lib.getExe (topiaryPkgs.topiary-cli {})} fmt";
entry = "${lib.getExe self.packages.${system}.topiary-cli} fmt";
types = [ "text" ];
};
}
);
});
};
}
Loading