summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/dependabot.yml8
-rw-r--r--.github/workflows/ci.yaml32
-rw-r--r--.github/workflows/publish.yaml26
-rw-r--r--.gitignore20
-rw-r--r--Cargo.toml5
-rw-r--r--LICENSE19
-rw-r--r--README.md20
-rw-r--r--checks/actionlint/package.nix10
-rw-r--r--checks/alejandra/package.nix10
-rw-r--r--checks/biome-fmt/package.nix10
-rw-r--r--checks/biome-lint/package.nix10
-rw-r--r--checks/deadnix/package.nix10
-rw-r--r--checks/editorconfig/package.nix11
-rw-r--r--checks/rustfmt/package.nix11
-rw-r--r--checks/selene/package.nix11
-rw-r--r--checks/statix/package.nix10
-rw-r--r--checks/stylua/package.nix10
-rw-r--r--default.nix10
-rw-r--r--flake.nix11
-rw-r--r--template/flake.nix27
-rw-r--r--test/Cargo.toml9
-rw-r--r--test/biome.js2
-rw-r--r--test/flake.lock60
-rw-r--r--test/flake.nix21
-rw-r--r--test/src/main.rs4
25 files changed, 377 insertions, 0 deletions
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..4c39a33
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,8 @@
+version: 2
+updates:
+ - package-ecosystem: "github-actions"
+ directory: "/"
+ schedule:
+ interval: "weekly"
+ commit-message:
+ prefix: "ci"
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
new file mode 100644
index 0000000..163c10a
--- /dev/null
+++ b/.github/workflows/ci.yaml
@@ -0,0 +1,32 @@
+name: CI
+
+on:
+ push:
+ paths:
+ - '.github/workflows/**'
+ - '**.nix'
+ branches: [main]
+ pull_request:
+ paths:
+ - '.github/workflows/**'
+ - '**.nix'
+ workflow_dispatch:
+
+jobs:
+ test:
+ name: Run tests
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v4
+
+ - name: Install Nix
+ uses: cachix/install-nix-action@v26
+
+ - name: Build release.nix
+ run: |
+ nix flake check ./test \
+ --print-build-logs \
+ --show-trace
diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml
new file mode 100644
index 0000000..9c546d3
--- /dev/null
+++ b/.github/workflows/publish.yaml
@@ -0,0 +1,26 @@
+name: Publish flake
+
+on:
+ push:
+ tags:
+ - v?[0-9]+.[0-9]+.[0-9]+
+ workflow_dispatch:
+ inputs:
+ tag:
+ description: "The existing tag to publish"
+ type: "string"
+ required: true
+
+jobs:
+ flakestry:
+ name: Publish to flakestry.dev
+
+ runs-on: ubuntu-latest
+
+ permissions:
+ id-token: write
+
+ steps:
+ - uses: flakestry/flakestry-publish@main
+ with:
+ version: "${{ inputs.tag || github.ref_name }}"
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f7abe76
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,20 @@
+### Created by https://www.gitignore.io
+### Rust ###
+# Generated by Cargo
+# will have compiled files and executables
+debug/
+target/
+
+# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
+# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
+Cargo.lock
+
+# These are backup files generated by rustfmt
+**/*.rs.bk
+
+# MSVC Windows builds of rustc generate these, which store debugging information
+*.pdb
+
+### Nix ###
+result*
+repl-result-out*
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..2325437
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,5 @@
+# this is for testing the `rustfmt` check
+[workspace]
+members = [
+ "test"
+]
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..cbbadba
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2024 seth
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..79b8259
--- /dev/null
+++ b/README.md
@@ -0,0 +1,20 @@
+# flake-checks
+
+Simple, lightweight, and reusable Nix `flake check`s
+
+## Getting started
+
+```sh
+nix flake init --template github:getchoo/flake-checks # create a new flake with our template
+nix flake check --print-build-logs # and off to the races!
+```
+
+## Usage
+
+### `mkChecks :: { pkgs, root }`
+
+Returns an attribute set of our [supported checks](./checks)
+
+## Related projects
+
+- [git-hooks.nix](https://github.com/cachix/git-hooks.nix) (previously `pre-commit-hooks.nix`)
diff --git a/checks/actionlint/package.nix b/checks/actionlint/package.nix
new file mode 100644
index 0000000..561f826
--- /dev/null
+++ b/checks/actionlint/package.nix
@@ -0,0 +1,10 @@
+{
+ lib,
+ runCommand,
+ root,
+ actionlint,
+}:
+runCommand "check-actionlint" {} ''
+ ${lib.getExe actionlint} ${root}/.github/workflows/*
+ touch $out
+''
diff --git a/checks/alejandra/package.nix b/checks/alejandra/package.nix
new file mode 100644
index 0000000..1f2c995
--- /dev/null
+++ b/checks/alejandra/package.nix
@@ -0,0 +1,10 @@
+{
+ lib,
+ runCommand,
+ root,
+ alejandra,
+}:
+runCommand "check-alejandra" {} ''
+ ${lib.getExe alejandra} --check ${root}
+ touch $out
+''
diff --git a/checks/biome-fmt/package.nix b/checks/biome-fmt/package.nix
new file mode 100644
index 0000000..11d967c
--- /dev/null
+++ b/checks/biome-fmt/package.nix
@@ -0,0 +1,10 @@
+{
+ lib,
+ runCommand,
+ root,
+ biome,
+}:
+runCommand "check-biome-fmt" {} ''
+ ${lib.getExe biome} format ${root}/**/*
+ touch $out
+''
diff --git a/checks/biome-lint/package.nix b/checks/biome-lint/package.nix
new file mode 100644
index 0000000..b575d34
--- /dev/null
+++ b/checks/biome-lint/package.nix
@@ -0,0 +1,10 @@
+{
+ lib,
+ runCommand,
+ root,
+ biome,
+}:
+runCommand "check-biome-lint" {} ''
+ ${lib.getExe biome} lint ${root}/**/*
+ touch $out
+''
diff --git a/checks/deadnix/package.nix b/checks/deadnix/package.nix
new file mode 100644
index 0000000..9faaea5
--- /dev/null
+++ b/checks/deadnix/package.nix
@@ -0,0 +1,10 @@
+{
+ lib,
+ runCommand,
+ root,
+ deadnix,
+}:
+runCommand "check-deadnix" {} ''
+ ${lib.getExe deadnix} --fail ${root}
+ touch $out
+''
diff --git a/checks/editorconfig/package.nix b/checks/editorconfig/package.nix
new file mode 100644
index 0000000..97b2a31
--- /dev/null
+++ b/checks/editorconfig/package.nix
@@ -0,0 +1,11 @@
+{
+ lib,
+ runCommand,
+ root,
+ editorconfig-checker,
+}:
+runCommand "check-editorconfig" {} ''
+ cd ${root}
+ ${lib.getExe editorconfig-checker} -exclude '.git' .
+ touch $out
+''
diff --git a/checks/rustfmt/package.nix b/checks/rustfmt/package.nix
new file mode 100644
index 0000000..ef12b49
--- /dev/null
+++ b/checks/rustfmt/package.nix
@@ -0,0 +1,11 @@
+{
+ runCommand,
+ root,
+ cargo,
+ rustfmt,
+}:
+runCommand "check-rustfmt" {nativeBuildInputs = [cargo rustfmt];} ''
+ cd ${root}
+ cargo fmt -- --check
+ touch $out
+''
diff --git a/checks/selene/package.nix b/checks/selene/package.nix
new file mode 100644
index 0000000..cc9f15f
--- /dev/null
+++ b/checks/selene/package.nix
@@ -0,0 +1,11 @@
+{
+ lib,
+ runCommand,
+ root,
+ selene,
+}:
+runCommand "check-selene" {} ''
+ cd ${root}
+ ${lib.getExe selene} .
+ touch $out
+''
diff --git a/checks/statix/package.nix b/checks/statix/package.nix
new file mode 100644
index 0000000..aa0a478
--- /dev/null
+++ b/checks/statix/package.nix
@@ -0,0 +1,10 @@
+{
+ lib,
+ runCommand,
+ root,
+ statix,
+}:
+runCommand "check-statix" {} ''
+ ${lib.getExe statix} check ${root}
+ touch $out
+''
diff --git a/checks/stylua/package.nix b/checks/stylua/package.nix
new file mode 100644
index 0000000..57b439b
--- /dev/null
+++ b/checks/stylua/package.nix
@@ -0,0 +1,10 @@
+{
+ lib,
+ runCommand,
+ root,
+ stylua,
+}:
+runCommand "check-stylua" {} ''
+ ${lib.getExe stylua} --check ${root}
+ touch $out
+''
diff --git a/default.nix b/default.nix
new file mode 100644
index 0000000..d66666e
--- /dev/null
+++ b/default.nix
@@ -0,0 +1,10 @@
+{
+ mkChecks = {
+ pkgs,
+ root,
+ }:
+ pkgs.lib.packagesFromDirectoryRecursive {
+ callPackage = path: attrs: pkgs.callPackage path ({inherit root;} // attrs);
+ directory = ./checks;
+ };
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..e8ec591
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,11 @@
+{
+ description = "Simple, lightweight, and reusable Nix `flake check`s";
+
+ outputs = _: {
+ lib = import ./.;
+ templates.default = {
+ path = toString ./template;
+ description = "a starting place for flake-checks";
+ };
+ };
+}
diff --git a/template/flake.nix b/template/flake.nix
new file mode 100644
index 0000000..4a06e40
--- /dev/null
+++ b/template/flake.nix
@@ -0,0 +1,27 @@
+{
+ inputs = {
+ nixpkgs.url = "nixpkgs/nixpkgs-unstable";
+ flake-utils.url = "github:numtide/flake-utils";
+ flake-checks.url = "github:getchoo/flake-checks";
+ };
+
+ outputs = {
+ nixpkgs,
+ flake-utils,
+ flake-checks,
+ ...
+ }:
+ flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = nixpkgs.legacyPackages.${system};
+ flake-checks' = flake-checks.lib.mkChecks {
+ inherit pkgs;
+ root = ./.;
+ };
+ in {
+ checks = {
+ check-actionlint = flake-checks'.actionlint;
+ check-alejandra = flake-checks'.alejandra;
+ check-deadnix = flake-checks'.deadnix;
+ };
+ });
+}
diff --git a/test/Cargo.toml b/test/Cargo.toml
new file mode 100644
index 0000000..eef754c
--- /dev/null
+++ b/test/Cargo.toml
@@ -0,0 +1,9 @@
+# this is for testing the `rustfmt` check
+[package]
+name = "flake-checks"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/test/biome.js b/test/biome.js
new file mode 100644
index 0000000..07ef948
--- /dev/null
+++ b/test/biome.js
@@ -0,0 +1,2 @@
+// this is a file for biome to format
+console.log("hello world!");
diff --git a/test/flake.lock b/test/flake.lock
new file mode 100644
index 0000000..4361b8a
--- /dev/null
+++ b/test/flake.lock
@@ -0,0 +1,60 @@
+{
+ "nodes": {
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1710146030,
+ "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1714314149,
+ "narHash": "sha256-yNAevSKF4krRWacmLUsLK7D7PlfuY3zF0lYnGYNi9vQ=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "cf8cc1201be8bc71b7cbbbdaf349b22f4f99c7ae",
+ "type": "github"
+ },
+ "original": {
+ "id": "nixpkgs",
+ "ref": "nixpkgs-unstable",
+ "type": "indirect"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/test/flake.nix b/test/flake.nix
new file mode 100644
index 0000000..fb4547c
--- /dev/null
+++ b/test/flake.nix
@@ -0,0 +1,21 @@
+{
+ inputs = {
+ nixpkgs.url = "nixpkgs/nixpkgs-unstable";
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = {
+ nixpkgs,
+ flake-utils,
+ ...
+ }:
+ flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = nixpkgs.legacyPackages.${system};
+ flake-checks' = (import ../.).mkChecks {
+ inherit pkgs;
+ root = ../.;
+ };
+ in {
+ checks = flake-checks';
+ });
+}
diff --git a/test/src/main.rs b/test/src/main.rs
new file mode 100644
index 0000000..1264903
--- /dev/null
+++ b/test/src/main.rs
@@ -0,0 +1,4 @@
+// this is for testing the `rustfmt` check
+fn main() {
+ println!("hello world");
+}