Skip to content

Commit

Permalink
Merge pull request #42 from dataheld/factor-out-format
Browse files Browse the repository at this point in the history
add formatting and linting
  • Loading branch information
maxheld83 authored Feb 13, 2025
2 parents 05d689d + 93d9d90 commit 20da40d
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 65 deletions.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
fi
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
---
name: CI
on:
pull_request:
workflow_dispatch:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
DeterminateCI:
uses: dataheld/ci/.github/workflows/workflow.yml@main
Expand All @@ -17,14 +14,3 @@ jobs:
contents: "read"
with:
visibility: public
format:
name: format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@v16
with:
determinate: true
- uses: DeterminateSystems/flakehub-cache-action@main
- name: Format Files
run: nix develop --command make format-ci
6 changes: 2 additions & 4 deletions .github/workflows/nix_maintenance.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---
name: Maintenance
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0' # runs weekly on Sunday at 01:00

- cron: "0 0 * * 0" # runs weekly on Sunday at 01:00
jobs:
nix-maintenance:
name: Nix Maintenance
Expand All @@ -23,4 +21,4 @@ jobs:
automated
- uses: DeterminateSystems/flake-checker-action@main
with:
fail-mode: true
fail-mode: true
8 changes: 5 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"nix.serverSettings": {
"nixd": {
"formatting": {
"command": [ "treefmt" ]
"command": ["treefmt"]
}
}
}
},
"editor.defaultFormatter": "ibecker.treefmt-vscode"
"editor.defaultFormatter": "ibecker.treefmt-vscode",
"treefmt.command": "treefmt",
"nix.formatterPath": "treefmt"
}
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ batteries-included 🔋,
extra-[DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) 🤌
[Nix](https://nixos.org) ❄️ boilerplate.

> nullkommanix [ɪn ˈnʊl ˌkɔma ˈnɪçt͡s] noun German colloquialism (translation: in next to time).
> nullkommanix \[ɪn ˈnʊl ˌkɔma ˈnɪçt͡s\] noun German colloquialism (translation: in next to time).
## Installing

> [!NOTE]
> This is the software you need to have on your *system*.
> \[!NOTE\]
> This is the software you need to have on your _system_.
> All project-specific software is handled automatically.
1. Install Nix (the package manager).
The [Determinate Nix Installer](https://github.com/DeterminateSystems/nix-installer) is recommended.
2. Install [direnv](https://direnv.net).
3. (optional) Install
[nix-direnv](https://github.com/nix-community/nix-direnv)
for better performance during development.
4. (if not already done) Clone the repo
5. (one-time only) Inside the repo, run `direnv allow`

> [!TIP]
The [Determinate Nix Installer](https://github.com/DeterminateSystems/nix-installer) is recommended.
1. Install [direnv](https://direnv.net).
1. (optional) Install
[nix-direnv](https://github.com/nix-community/nix-direnv)
for better performance during development.
1. (if not already done) Clone the repo
1. (one-time only) Inside the repo, run `direnv allow`

> \[!TIP\]
> Windows is not supported by Nix,
> but you can use the
> [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install).
Expand All @@ -47,21 +47,21 @@ make help

There are two separate aspects to updating the nix dependencies.

1. There may be newer versions available *given* the pinning in `flake.nix`.
This can be accomplished by running `make update-flake` locally and may change the `flake.lock`.
However such updates may break a project.
It is therefore recommended **to only run this in CI**,
using the periodically scheduled `nix_maintenance.yml` job.
It will automatically open pull requests if there are updates available.
Users can then inspect whether the updated project still passes all tests.
2. The versions pinned in `flake.nix` (and the resulting `flake.lock`) itself may be out of date.
The [DeterminateSystems/flake-checker](https://github.com/DeterminateSystems/flake-checker) will fail if this is the case.
It runs on every push as well as periodically.
You can also run this locally using `make check-flake-checker`.
1. There may be newer versions available _given_ the pinning in `flake.nix`.
This can be accomplished by running `make update-flake` locally and may change the `flake.lock`.
However such updates may break a project.
It is therefore recommended **to only run this in CI**,
using the periodically scheduled `nix_maintenance.yml` job.
It will automatically open pull requests if there are updates available.
Users can then inspect whether the updated project still passes all tests.
1. The versions pinned in `flake.nix` (and the resulting `flake.lock`) itself may be out of date.
The [DeterminateSystems/flake-checker](https://github.com/DeterminateSystems/flake-checker) will fail if this is the case.
It runs on every push as well as periodically.
You can also run this locally using `make check-flake-checker`.

### Development Shell

To bring the shell you are working in up to date with the *source*
To bring the shell you are working in up to date with the _source_
(`nix.flake`, etc.)
of your repository:

Expand Down
91 changes: 85 additions & 6 deletions flake.lock

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

26 changes: 19 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@

inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*";
# keep-sorted start
flake-checker.url = "https://flakehub.com/f/DeterminateSystems/flake-checker/0.2.4.tar.gz";
flake-iter.url = "https://flakehub.com/f/DeterminateSystems/flake-iter/0.1.92.tar.gz";
flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/0.1.5.tar.gz";
format.url = "path:./format";
# keep-sorted end
};

outputs = {
nixpkgs,
flake-checker,
flake-iter,
flake-schemas,
format,
...
}: let
supportedSystems = [
Expand All @@ -23,25 +27,33 @@
forEachSupportedSystem = f:
nixpkgs.lib.genAttrs supportedSystems (system:
f {
pkgs = import nixpkgs {inherit system;};
pkgs = import nixpkgs {
inherit system;
};
});
in {
schemas = flake-schemas.schemas;
checks = forEachSupportedSystem ({pkgs}: {
default = pkgs.runCommand "check" {} ''touch $out'';
});
checks = forEachSupportedSystem (
{pkgs}: {
formatting = format.checks.${pkgs.system}.formatting;
}
);
devShells = forEachSupportedSystem ({pkgs}: {
default = pkgs.mkShell {
packages = with pkgs; [
alejandra
# keep-sorted start
flake-checker.packages.${pkgs.system}.default
flake-iter.packages.${pkgs.system}.default
format.formatter.${pkgs.system}
git
gnumake
nixd
treefmt2
# keep-sorted end
];
};
});
formatter = forEachSupportedSystem ({pkgs}: pkgs.alejandra);
formatter = forEachSupportedSystem (
{pkgs}: format.formatter.${pkgs.system}
);
};
}
29 changes: 29 additions & 0 deletions format/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# copied from https://github.com/numtide/treefmt-nix
{
description = "treefmt-nix";
inputs.treefmt-nix.url = "github:numtide/treefmt-nix";

outputs = {
self,
nixpkgs,
systems,
treefmt-nix,
}: let
eachSystem = f:
nixpkgs.lib.genAttrs (import systems) (
system: let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true; # Allows unfree packages
};
in
f pkgs
);
treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix);
in {
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
checks = eachSystem (pkgs: {
formatting = treefmtEval.${pkgs.system}.config.build.check self;
});
};
}
25 changes: 25 additions & 0 deletions format/treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# treefmt.nix
{...}: {
# Used to find the project root
projectRootFile = ".git/config";
# keep-sorted start
programs.actionlint.enable = true;
programs.alejandra.enable = true;
programs.beautysh.enable = true;
programs.black.enable = true;
programs.cmake-format.enable = true;
programs.deadnix.enable = true;
programs.hclfmt.enable = true;
programs.isort.enable = true;
programs.jsonfmt.enable = true;
programs.keep-sorted.enable = true;
programs.mdformat.enable = true;
programs.prettier.enable = true;
programs.shellcheck.enable = true;
programs.shfmt.enable = true;
programs.sqlfluff.enable = true;
programs.terraform.enable = true;
programs.toml-sort.enable = true;
programs.yamlfmt.enable = true;
# keep-sorted end
}
7 changes: 0 additions & 7 deletions treefmt.toml

This file was deleted.

0 comments on commit 20da40d

Please sign in to comment.