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 10, 2024
1 parent 9971d47 commit e9cdbd9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 55 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.

128 changes: 77 additions & 51 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,58 @@
flake = false;
};

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

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
supportedSystems = nixpkgs.lib.systems.flakeExposed;

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

topiaryPkgsFor = nixpkgs.lib.genAttrs supportedSystems (system:
let pkgs = nixpkgsFor.${system}; in
pkgs.callPackage ./default.nix {
inherit (inputs) advisory-db crane rust-overlay nix-filter;
inherit (pkgs.tree-sitter-grammars) tree-sitter-nickel;
craneLib = inputs.crane.mkLib pkgs;
});

binPkgsFor = nixpkgs.lib.genAttrs supportedSystems (system:
nixpkgsFor.${system}.callPackage ./bin/default.nix { }
);

forAllSystems = fn: nixpkgs.lib.genAttrs supportedSystems (system: fn rec {
inherit system;
pkgs = nixpkgsFor.${system};
inherit (pkgs) lib;
craneLib = inputs.crane.mkLib pkgs;
topiaryPkgs = topiaryPkgsFor.${system};
binPkgs = binPkgsFor.${system};
});
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,24 +89,10 @@
cargoHash = "sha256-3vxVI0BhNz/9m59b+P2YEIrwGwlp7K3pyPKt4VqQuHE=";
};
};
};

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

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 nix-filter;
inherit craneLib tree-sitter-nickel;
};
binPkgs = pkgs.callPackage ./bin/default.nix { };
in
{
packages = rec {
packages = forAllSystems ({ system, pkgs, topiaryPkgs, binPkgs, ... }:
{
inherit (topiaryPkgs)
topiary-playground
topiary-queries
Expand All @@ -86,41 +109,44 @@
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 = {
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.passthru.craneLibWasm; inherit binPkgs; };
inherit craneLib;
inherit binPkgs;
optionals = false;
};
wasm = pkgs.callPackage ./shell.nix { checks = self.checks.${system}; craneLib = topiaryPkgsFor.${system}.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 = "${topiaryPkgs.topiary-cli {}}/bin/topiary fmt";
entry = "${self.packages.${system}.topiary-cli}/bin/topiary fmt";
types = [ "text" ];
};
}
);
});
};
}

0 comments on commit e9cdbd9

Please sign in to comment.