mirror of
https://github.com/numtide/treefmt.git
synced 2024-10-05 13:07:17 +03:00
feat: use numtide/blueprint instead of flake.parts
Signed-off-by: Brian McGee <brian@bmcgee.ie>
This commit is contained in:
parent
30d30b54f0
commit
986f020c3d
4
.envrc
4
.envrc
@ -1,6 +1,10 @@
|
|||||||
dotenv
|
dotenv
|
||||||
|
|
||||||
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
|
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
|
||||||
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
|
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
watch_file flake.nix
|
||||||
watch_file nix/devshell.nix
|
watch_file nix/devshell.nix
|
||||||
|
|
||||||
use flake
|
use flake
|
||||||
|
2
.github/workflows/gh-pages.yml
vendored
2
.github/workflows/gh-pages.yml
vendored
@ -27,7 +27,7 @@ jobs:
|
|||||||
- name: Build the docs
|
- name: Build the docs
|
||||||
id: build
|
id: build
|
||||||
run: |
|
run: |
|
||||||
nix build .#docs
|
nix build .#treefmt-docs
|
||||||
echo "result=$(readlink ./result)" >> $GITHUB_OUTPUT
|
echo "result=$(readlink ./result)" >> $GITHUB_OUTPUT
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-pages-artifact@v3
|
uses: actions/upload-pages-artifact@v3
|
||||||
|
@ -2,7 +2,13 @@
|
|||||||
{system ? builtins.currentSystem}: let
|
{system ? builtins.currentSystem}: let
|
||||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||||
|
|
||||||
inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;
|
inherit
|
||||||
|
(lock.nodes.flake-compat.locked)
|
||||||
|
owner
|
||||||
|
repo
|
||||||
|
rev
|
||||||
|
narHash
|
||||||
|
;
|
||||||
|
|
||||||
flake-compat = fetchTarball {
|
flake-compat = fetchTarball {
|
||||||
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
|
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
|
||||||
|
60
flake.lock
60
flake.lock
@ -1,5 +1,26 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
|
"blueprint": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
],
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1719507605,
|
||||||
|
"narHash": "sha256-Jh/loHiHEkAPBTJv00s1YcQBO2JStioSe3C5BnCB+QA=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "blueprint",
|
||||||
|
"rev": "16b382c2b52c9c0b15ac4909b8a8ac712f0fc868",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "blueprint",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"devshell": {
|
"devshell": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils",
|
||||||
@ -36,29 +57,9 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"flake-parts": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs-lib": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1712014858,
|
|
||||||
"narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=",
|
|
||||||
"owner": "hercules-ci",
|
|
||||||
"repo": "flake-parts",
|
|
||||||
"rev": "9126214d0a59633752a136528f5f3b9aa8565b7d",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "hercules-ci",
|
|
||||||
"repo": "flake-parts",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-utils": {
|
"flake-utils": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"systems": "systems"
|
"systems": "systems_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1701680307,
|
"lastModified": 1701680307,
|
||||||
@ -151,9 +152,9 @@
|
|||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"blueprint": "blueprint",
|
||||||
"devshell": "devshell",
|
"devshell": "devshell",
|
||||||
"flake-compat": "flake-compat",
|
"flake-compat": "flake-compat",
|
||||||
"flake-parts": "flake-parts",
|
|
||||||
"gomod2nix": "gomod2nix",
|
"gomod2nix": "gomod2nix",
|
||||||
"nix-filter": "nix-filter",
|
"nix-filter": "nix-filter",
|
||||||
"nix-github-actions": "nix-github-actions",
|
"nix-github-actions": "nix-github-actions",
|
||||||
@ -176,6 +177,21 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"systems_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"treefmt-nix": {
|
"treefmt-nix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
|
54
flake.nix
54
flake.nix
@ -2,22 +2,13 @@
|
|||||||
description = "Treefmt: once CLI to format your repo";
|
description = "Treefmt: once CLI to format your repo";
|
||||||
|
|
||||||
nixConfig = {
|
nixConfig = {
|
||||||
extra-substituters = [
|
extra-substituters = ["https://numtide.cachix.org"];
|
||||||
"https://numtide.cachix.org"
|
extra-trusted-public-keys = ["numtide.cachix.org-1:2ps1kLBUWjxIneOy1Ik6cQjb41X0iXVXeHigGmycPPE="];
|
||||||
];
|
|
||||||
extra-trusted-public-keys = [
|
|
||||||
"numtide.cachix.org-1:2ps1kLBUWjxIneOy1Ik6cQjb41X0iXVXeHigGmycPPE="
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
blueprint = {
|
||||||
flake-parts = {
|
url = "github:numtide/blueprint";
|
||||||
url = "github:hercules-ci/flake-parts";
|
|
||||||
inputs.nixpkgs-lib.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
treefmt-nix = {
|
|
||||||
url = "github:numtide/treefmt-nix";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
devshell = {
|
devshell = {
|
||||||
@ -29,28 +20,37 @@
|
|||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
inputs.flake-utils.follows = "devshell/flake-utils";
|
inputs.flake-utils.follows = "devshell/flake-utils";
|
||||||
};
|
};
|
||||||
nix-filter.url = "github:numtide/nix-filter";
|
|
||||||
flake-compat.url = "github:nix-community/flake-compat";
|
flake-compat.url = "github:nix-community/flake-compat";
|
||||||
|
nix-filter.url = "github:numtide/nix-filter";
|
||||||
nix-github-actions = {
|
nix-github-actions = {
|
||||||
url = "github:nix-community/nix-github-actions";
|
url = "github:nix-community/nix-github-actions";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
treefmt-nix = {
|
||||||
|
url = "github:numtide/treefmt-nix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs @ {flake-parts, ...}:
|
outputs = inputs: let
|
||||||
flake-parts.lib.mkFlake
|
inherit (inputs.nixpkgs) lib;
|
||||||
{
|
in
|
||||||
|
inputs.blueprint {
|
||||||
inherit inputs;
|
inherit inputs;
|
||||||
|
prefix = "nix/";
|
||||||
|
nixpkgs.config = {
|
||||||
|
allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) ["terraform"];
|
||||||
|
};
|
||||||
}
|
}
|
||||||
{
|
// {
|
||||||
imports = [
|
githubActions = inputs.nix-github-actions.lib.mkGithubMatrix {
|
||||||
./nix
|
checks =
|
||||||
];
|
lib.getAttrs [
|
||||||
systems = [
|
"x86_64-linux"
|
||||||
"x86_64-linux"
|
"x86_64-darwin"
|
||||||
"aarch64-linux"
|
]
|
||||||
"x86_64-darwin"
|
inputs.self.checks;
|
||||||
"aarch64-darwin"
|
};
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
lib,
|
|
||||||
inputs,
|
|
||||||
self,
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
# generate github actions matrix using the flake's checks
|
|
||||||
flake.githubActions = inputs.nix-github-actions.lib.mkGithubMatrix {
|
|
||||||
checks = lib.getAttrs ["x86_64-linux" "x86_64-darwin"] self.checks;
|
|
||||||
};
|
|
||||||
|
|
||||||
perSystem = {self', ...}: {
|
|
||||||
# mixin every package
|
|
||||||
checks = with lib; mapAttrs' (n: nameValuePair "package-${n}") self'.packages;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
{...}: {
|
|
||||||
imports = [
|
|
||||||
./checks.nix
|
|
||||||
./devshell.nix
|
|
||||||
./docs.nix
|
|
||||||
./nixpkgs.nix
|
|
||||||
./packages.nix
|
|
||||||
./treefmt.nix
|
|
||||||
];
|
|
||||||
}
|
|
126
nix/devshell.nix
126
nix/devshell.nix
@ -1,59 +1,73 @@
|
|||||||
{inputs, ...}: {
|
{
|
||||||
imports = [
|
pkgs,
|
||||||
inputs.devshell.flakeModule
|
perSystem,
|
||||||
];
|
...
|
||||||
|
}: let
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
inherit (pkgs.stdenv) isLinux isDarwin;
|
||||||
|
in
|
||||||
|
perSystem.devshell.mkShell {
|
||||||
|
env = [
|
||||||
|
{
|
||||||
|
name = "GOROOT";
|
||||||
|
value = pkgs.go + "/share/go";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "LD_LIBRARY_PATH";
|
||||||
|
value = "$DEVSHELL_DIR/lib";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
config.perSystem = {
|
packages = lib.mkMerge [
|
||||||
lib,
|
(with pkgs; [
|
||||||
pkgs,
|
# golang
|
||||||
config,
|
go
|
||||||
...
|
goreleaser
|
||||||
}: let
|
golangci-lint
|
||||||
inherit (pkgs.stdenv) isLinux isDarwin;
|
delve
|
||||||
in {
|
pprof
|
||||||
config.devshells.default = {
|
graphviz
|
||||||
env = [
|
|
||||||
{
|
|
||||||
name = "GOROOT";
|
|
||||||
value = pkgs.go + "/share/go";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "LD_LIBRARY_PATH";
|
|
||||||
value = "$DEVSHELL_DIR/lib";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
packages = lib.mkMerge [
|
# docs
|
||||||
(with pkgs; [
|
nodejs
|
||||||
# golang
|
])
|
||||||
go
|
# platform dependent CGO dependencies
|
||||||
goreleaser
|
(lib.mkIf isLinux [pkgs.gcc])
|
||||||
golangci-lint
|
(lib.mkIf isDarwin [pkgs.darwin.cctools])
|
||||||
delve
|
# include formatters for development and testing
|
||||||
pprof
|
(import ./packages/treefmt/formatters.nix pkgs)
|
||||||
graphviz
|
];
|
||||||
])
|
|
||||||
# platform dependent CGO dependencies
|
|
||||||
(lib.mkIf isLinux [
|
|
||||||
pkgs.gcc
|
|
||||||
])
|
|
||||||
(lib.mkIf isDarwin [
|
|
||||||
pkgs.darwin.cctools
|
|
||||||
])
|
|
||||||
# include formatters for development and testing
|
|
||||||
(import ./formatters.nix pkgs)
|
|
||||||
];
|
|
||||||
|
|
||||||
commands = [
|
commands = [
|
||||||
{
|
{package = perSystem.gomod2nix.default;}
|
||||||
category = "development";
|
{
|
||||||
package = pkgs.gomod2nix;
|
name = "docs:dev";
|
||||||
}
|
help = "serve docs for local development";
|
||||||
{
|
command = "cd $PRJ_ROOT/docs && npm ci && npm run dev";
|
||||||
category = "development";
|
}
|
||||||
package = pkgs.enumer;
|
{
|
||||||
}
|
name = "docs:build";
|
||||||
];
|
help = "create a production build of docs";
|
||||||
};
|
command = "cd $PRJ_ROOT/docs && npm ci && npm run build";
|
||||||
};
|
}
|
||||||
}
|
{
|
||||||
|
name = "docs:preview";
|
||||||
|
help = "preview a production build of docs";
|
||||||
|
command = "cd $PRJ_ROOT/docs && npm ci && npm run preview";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
help = "generate terminal gifs";
|
||||||
|
package = pkgs.writeShellApplication {
|
||||||
|
name = "vhs";
|
||||||
|
runtimeInputs =
|
||||||
|
[
|
||||||
|
perSystem.self.treefmt
|
||||||
|
pkgs.rsync
|
||||||
|
pkgs.vhs
|
||||||
|
]
|
||||||
|
++ (import ./packages/treefmt/formatters.nix pkgs);
|
||||||
|
text = ''vhs "$@"'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
70
nix/docs.nix
70
nix/docs.nix
@ -1,70 +0,0 @@
|
|||||||
_: {
|
|
||||||
perSystem = {
|
|
||||||
pkgs,
|
|
||||||
self',
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
packages.docs = pkgs.buildNpmPackage {
|
|
||||||
pname = "treefmt-docs";
|
|
||||||
inherit (self'.packages.default) version;
|
|
||||||
|
|
||||||
src = ../docs;
|
|
||||||
npmDepsHash = "sha256-vHxJHuhvQJ0P4wS1Hd2BIfPMSptnLhuHGLXCO+P5iFs=";
|
|
||||||
|
|
||||||
# we have to use a custom build phase because vitepress is doing something funky with the ttty
|
|
||||||
buildPhase = ''
|
|
||||||
cat | npm run build 2>&1 | cat
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
runHook preInstall
|
|
||||||
cp -rv .vitepress/dist/ $out
|
|
||||||
runHook postInstall
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
devshells.default = {
|
|
||||||
packages = [
|
|
||||||
pkgs.nodejs
|
|
||||||
];
|
|
||||||
|
|
||||||
commands = let
|
|
||||||
category = "docs";
|
|
||||||
in [
|
|
||||||
{
|
|
||||||
inherit category;
|
|
||||||
name = "docs:dev";
|
|
||||||
help = "serve docs for local development";
|
|
||||||
command = "cd $PRJ_ROOT/docs && npm ci && npm run dev";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
inherit category;
|
|
||||||
name = "docs:build";
|
|
||||||
help = "create a production build of docs";
|
|
||||||
command = "cd $PRJ_ROOT/docs && npm ci && npm run build";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
inherit category;
|
|
||||||
name = "docs:preview";
|
|
||||||
help = "preview a production build of docs";
|
|
||||||
command = "cd $PRJ_ROOT/docs && npm ci && npm run preview";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
inherit category;
|
|
||||||
help = "generate terminal gifs";
|
|
||||||
package = pkgs.writeShellApplication {
|
|
||||||
name = "vhs";
|
|
||||||
runtimeInputs =
|
|
||||||
[
|
|
||||||
self'.packages.treefmt
|
|
||||||
pkgs.rsync
|
|
||||||
pkgs.vhs
|
|
||||||
]
|
|
||||||
++ (import ./formatters.nix pkgs);
|
|
||||||
text = ''vhs "$@"'';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
51
nix/formatter.nix
Normal file
51
nix/formatter.nix
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
inputs,
|
||||||
|
perSystem,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
inputs.treefmt-nix.lib.mkWrapper pkgs {
|
||||||
|
projectRootFile = "flake.nix";
|
||||||
|
|
||||||
|
package = perSystem.self.treefmt;
|
||||||
|
|
||||||
|
programs = {
|
||||||
|
alejandra.enable = true;
|
||||||
|
deadnix.enable = true;
|
||||||
|
gofumpt.enable = true;
|
||||||
|
prettier.enable = true;
|
||||||
|
statix.enable = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
global.excludes = [
|
||||||
|
"LICENSE"
|
||||||
|
# let's not mess with the test folder
|
||||||
|
"test/*"
|
||||||
|
# unsupported extensions
|
||||||
|
"*.{gif,png,svg,tape,mts,lock,mod,sum,toml,env,envrc,gitignore}"
|
||||||
|
];
|
||||||
|
|
||||||
|
formatter = {
|
||||||
|
deadnix = {
|
||||||
|
priority = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
statix = {
|
||||||
|
priority = 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
alejandra = {
|
||||||
|
priority = 3;
|
||||||
|
};
|
||||||
|
|
||||||
|
prettier = {
|
||||||
|
options = [
|
||||||
|
"--tab-width"
|
||||||
|
"4"
|
||||||
|
];
|
||||||
|
includes = ["*.{css,html,js,json,jsx,md,mdx,scss,ts,yaml}"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
{inputs, ...}: {
|
|
||||||
perSystem = {system, ...}: {
|
|
||||||
# customise nixpkgs instance
|
|
||||||
_module.args.pkgs = import inputs.nixpkgs {
|
|
||||||
inherit system;
|
|
||||||
overlays = [
|
|
||||||
inputs.gomod2nix.overlays.default
|
|
||||||
];
|
|
||||||
config = {
|
|
||||||
# for terraform
|
|
||||||
# todo make this more specific
|
|
||||||
allowUnfree = true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
{
|
|
||||||
self,
|
|
||||||
inputs,
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
imports = [
|
|
||||||
inputs.flake-parts.flakeModules.easyOverlay
|
|
||||||
];
|
|
||||||
|
|
||||||
perSystem = {
|
|
||||||
self',
|
|
||||||
inputs',
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
packages = rec {
|
|
||||||
treefmt = inputs'.gomod2nix.legacyPackages.buildGoApplication rec {
|
|
||||||
pname = "treefmt";
|
|
||||||
# there's no good way of tying in the version to a git tag or branch
|
|
||||||
# so for simplicity's sake we set the version as the commit revision hash
|
|
||||||
# we remove the `-dirty` suffix to avoid a lot of unnecessary rebuilds in local dev
|
|
||||||
version = lib.removeSuffix "-dirty" (self.shortRev or self.dirtyShortRev);
|
|
||||||
|
|
||||||
# ensure we are using the same version of go to build with
|
|
||||||
inherit (pkgs) go;
|
|
||||||
|
|
||||||
src = let
|
|
||||||
filter = inputs.nix-filter.lib;
|
|
||||||
in
|
|
||||||
filter {
|
|
||||||
root = ../.;
|
|
||||||
exclude = [
|
|
||||||
"nix/"
|
|
||||||
"docs/"
|
|
||||||
".github/"
|
|
||||||
"README.md"
|
|
||||||
"default.nix"
|
|
||||||
"shell.nix"
|
|
||||||
".envrc"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
modules = ../gomod2nix.toml;
|
|
||||||
|
|
||||||
CGO_ENABLED = 1;
|
|
||||||
|
|
||||||
ldflags = [
|
|
||||||
"-s"
|
|
||||||
"-w"
|
|
||||||
"-X git.numtide.com/numtide/treefmt/build.Name=${pname}"
|
|
||||||
"-X git.numtide.com/numtide/treefmt/build.Version=v${version}"
|
|
||||||
];
|
|
||||||
|
|
||||||
nativeBuildInputs =
|
|
||||||
# we need some formatters available for the tests
|
|
||||||
import ./formatters.nix pkgs;
|
|
||||||
|
|
||||||
preCheck = ''
|
|
||||||
XDG_CACHE_HOME=$(mktemp -d)
|
|
||||||
export XDG_CACHE_HOME
|
|
||||||
'';
|
|
||||||
|
|
||||||
meta = with lib; {
|
|
||||||
description = "treefmt: one CLI to format your repo";
|
|
||||||
homepage = "https://git.numtide.com/numtide/treefmt";
|
|
||||||
license = licenses.mit;
|
|
||||||
mainProgram = "treefmt";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
default = treefmt;
|
|
||||||
};
|
|
||||||
|
|
||||||
overlayAttrs = self'.packages;
|
|
||||||
};
|
|
||||||
}
|
|
1
nix/packages/default.nix
Normal file
1
nix/packages/default.nix
Normal file
@ -0,0 +1 @@
|
|||||||
|
{perSystem, ...}: perSystem.self.treefmt
|
25
nix/packages/treefmt-docs.nix
Normal file
25
nix/packages/treefmt-docs.nix
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
pname,
|
||||||
|
pkgs,
|
||||||
|
flake,
|
||||||
|
perSystem,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
pkgs.buildNpmPackage {
|
||||||
|
inherit pname;
|
||||||
|
inherit (perSystem.self.treefmt) version;
|
||||||
|
|
||||||
|
src = "${flake}/docs";
|
||||||
|
npmDepsHash = "sha256-vHxJHuhvQJ0P4wS1Hd2BIfPMSptnLhuHGLXCO+P5iFs=";
|
||||||
|
|
||||||
|
# we have to use a custom build phase because vitepress is doing something funky with the ttty
|
||||||
|
buildPhase = ''
|
||||||
|
cat | npm run build 2>&1 | cat
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
runHook preInstall
|
||||||
|
cp -rv .vitepress/dist/ $out
|
||||||
|
runHook postInstall
|
||||||
|
'';
|
||||||
|
}
|
64
nix/packages/treefmt/default.nix
Normal file
64
nix/packages/treefmt/default.nix
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
{
|
||||||
|
pname,
|
||||||
|
pkgs,
|
||||||
|
flake,
|
||||||
|
inputs,
|
||||||
|
perSystem,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
in
|
||||||
|
perSystem.gomod2nix.buildGoApplication rec {
|
||||||
|
inherit pname;
|
||||||
|
# there's no good way of tying in the version to a git tag or branch
|
||||||
|
# so for simplicity's sake we set the version as the commit revision hash
|
||||||
|
# we remove the `-dirty` suffix to avoid a lot of unnecessary rebuilds in local dev
|
||||||
|
version = lib.removeSuffix "-dirty" (flake.shortRev or flake.dirtyShortRev);
|
||||||
|
|
||||||
|
# ensure we are using the same version of go to build with
|
||||||
|
inherit (pkgs) go;
|
||||||
|
|
||||||
|
src = let
|
||||||
|
filter = inputs.nix-filter.lib;
|
||||||
|
in
|
||||||
|
filter {
|
||||||
|
root = ../../../.;
|
||||||
|
exclude = [
|
||||||
|
"nix/"
|
||||||
|
"docs/"
|
||||||
|
".github/"
|
||||||
|
"README.md"
|
||||||
|
"default.nix"
|
||||||
|
"shell.nix"
|
||||||
|
".env"
|
||||||
|
".envrc"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
modules = ./gomod2nix.toml;
|
||||||
|
|
||||||
|
CGO_ENABLED = 1;
|
||||||
|
|
||||||
|
ldflags = [
|
||||||
|
"-s"
|
||||||
|
"-w"
|
||||||
|
"-X git.numtide.com/numtide/treefmt/build.Name=${pname}"
|
||||||
|
"-X git.numtide.com/numtide/treefmt/build.Version=v${version}"
|
||||||
|
];
|
||||||
|
|
||||||
|
nativeBuildInputs =
|
||||||
|
# we need some formatters available for the tests
|
||||||
|
import ./formatters.nix pkgs;
|
||||||
|
|
||||||
|
preCheck = ''
|
||||||
|
XDG_CACHE_HOME=$(mktemp -d)
|
||||||
|
export XDG_CACHE_HOME
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "treefmt: one CLI to format your repo";
|
||||||
|
homepage = "https://git.numtide.com/numtide/treefmt";
|
||||||
|
license = licenses.mit;
|
||||||
|
mainProgram = "treefmt";
|
||||||
|
};
|
||||||
|
}
|
@ -1,66 +0,0 @@
|
|||||||
{inputs, ...}: {
|
|
||||||
imports = [
|
|
||||||
inputs.treefmt-nix.flakeModule
|
|
||||||
];
|
|
||||||
perSystem = {
|
|
||||||
config,
|
|
||||||
self',
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
treefmt.config = {
|
|
||||||
flakeCheck = true;
|
|
||||||
flakeFormatter = true;
|
|
||||||
projectRootFile = "flake.nix";
|
|
||||||
|
|
||||||
package = self'.packages.default;
|
|
||||||
|
|
||||||
programs = {
|
|
||||||
alejandra.enable = true;
|
|
||||||
deadnix.enable = true;
|
|
||||||
gofumpt.enable = true;
|
|
||||||
prettier.enable = true;
|
|
||||||
statix.enable = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
settings = {
|
|
||||||
global.excludes = [
|
|
||||||
"LICENSE"
|
|
||||||
# let's not mess with the test folder
|
|
||||||
"test/*"
|
|
||||||
# unsupported extensions
|
|
||||||
"*.{gif,png,svg,tape,mts,lock,mod,sum,toml,env,envrc,gitignore}"
|
|
||||||
];
|
|
||||||
|
|
||||||
formatter = {
|
|
||||||
deadnix = {
|
|
||||||
priority = 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
statix = {
|
|
||||||
priority = 2;
|
|
||||||
};
|
|
||||||
|
|
||||||
alejandra = {
|
|
||||||
priority = 3;
|
|
||||||
};
|
|
||||||
|
|
||||||
prettier = {
|
|
||||||
options = ["--tab-width" "4"];
|
|
||||||
includes = ["*.{css,html,js,json,jsx,md,mdx,scss,ts,yaml}"];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
devshells.default = {
|
|
||||||
commands = [
|
|
||||||
{
|
|
||||||
category = "formatting";
|
|
||||||
name = "fmt";
|
|
||||||
help = "format the repo";
|
|
||||||
command = "nix fmt";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
@ -2,7 +2,13 @@
|
|||||||
{system ? builtins.currentSystem}: let
|
{system ? builtins.currentSystem}: let
|
||||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||||
|
|
||||||
inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;
|
inherit
|
||||||
|
(lock.nodes.flake-compat.locked)
|
||||||
|
owner
|
||||||
|
repo
|
||||||
|
rev
|
||||||
|
narHash
|
||||||
|
;
|
||||||
|
|
||||||
flake-compat = fetchTarball {
|
flake-compat = fetchTarball {
|
||||||
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
|
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
|
||||||
|
Loading…
Reference in New Issue
Block a user