Skip to content

Commit

Permalink
remove nix dependency: flake-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
toastal committed Dec 11, 2024
1 parent 5dddb5e commit f5cae43
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 70 deletions.
5 changes: 1 addition & 4 deletions flake.lock

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

152 changes: 86 additions & 66 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,101 +25,121 @@
flake = false;
};

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

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

outputs = { self, nixpkgs, ... }@inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
wasm-bindgen-cli-overlay = final: prev:
let
cargoLock = builtins.fromTOML (builtins.readFile ./Cargo.lock);
wasmBindgenCargoVersions = builtins.map ({ version, ... }: version) (builtins.filter ({ name, ... }: name == "wasm-bindgen") cargoLock.package);
wasmBindgenVersion = assert builtins.length wasmBindgenCargoVersions == 1; builtins.elemAt wasmBindgenCargoVersions 0;
in
{
wasm-bindgen-cli = prev.wasm-bindgen-cli.override {
version = wasmBindgenVersion;
hash = "sha256-f/RK6s12ItqKJWJlA2WtOXtwX4Y0qa8bq/JHlLTAS3c=";
cargoHash = "sha256-3vxVI0BhNz/9m59b+P2YEIrwGwlp7K3pyPKt4VqQuHE=";
};
};
let
supportedSystems = nixpkgs.lib.systems.flakeExposed;

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

craneLib = inputs.crane.mkLib pkgs;

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

topiaryPkgs = pkgs.callPackage ./default.nix {
inherit (inputs) advisory-db crane rust-overlay;
inherit craneLib tree-sitter-nickel;
};
binPkgs = pkgs.callPackage ./bin/default.nix { };
in
{
packages = {
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;
inherit (pkgs.tree-sitter-grammars) tree-sitter-nickel;
craneLib = inputs.crane.mkLib pkgs;
};

checks = {
inherit (topiaryPkgs) clippy clippy-wasm fmt topiary-core topiary-playground audit benchmark;
topiary-cli = self.packages.${system}.topiary-cli;
binPkgs = pkgs.callPackage ./bin/default.nix { };
});

## 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;
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;
};
};

devShells =
wasm-bindgen-cli = final: prev:
let
checksLight = {
cargoLock = builtins.fromTOML (builtins.readFile ./Cargo.lock);
wasmBindgenCargoVersions = builtins.map ({ version, ... }: version) (builtins.filter ({ name, ... }: name == "wasm-bindgen") cargoLock.package);
wasmBindgenVersion = assert builtins.length wasmBindgenCargoVersions == 1; builtins.elemAt wasmBindgenCargoVersions 0;
in
{
wasm-bindgen-cli = prev.wasm-bindgen-cli.override {
version = wasmBindgenVersion;
hash = "sha256-f/RK6s12ItqKJWJlA2WtOXtwX4Y0qa8bq/JHlLTAS3c=";
cargoHash = "sha256-3vxVI0BhNz/9m59b+P2YEIrwGwlp7K3pyPKt4VqQuHE=";
};
};
};

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 = 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.passthru.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, ... }: {
pre-commit-hook = {
enable = true;
name = "topiary";
description = "A general code formatter based on tree-sitter.";
entry = "${pkgs.lib.getExe self.packages.${system}.topiary-cli} fmt";
types = [ "text" ];
};
}
);
});
};
}

0 comments on commit f5cae43

Please sign in to comment.