feat(nix): add treefmt-nix
This commit is contained in:
parent
305daf76c9
commit
9f49f95002
|
@ -24,6 +24,7 @@ link:https://nixos.org[nix] is used to run tasks and manage other tools.
|
|||
* List available tasks: `+nix flake show+`
|
||||
* Invoke a task: `+nix run .#<task>+`
|
||||
* Enter a development shell: `+nix develop+`
|
||||
* Run linters: `+nix flake check+`
|
||||
|
||||
== License
|
||||
|
||||
|
|
23
flake.lock
23
flake.lock
|
@ -37,7 +37,8 @@
|
|||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
"nixpkgs": "nixpkgs",
|
||||
"treefmt-nix": "treefmt-nix"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
|
@ -54,6 +55,26 @@
|
|||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"treefmt-nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1699786194,
|
||||
"narHash": "sha256-3h3EH1FXQkIeAuzaWB+nK0XK54uSD46pp+dMD3gAcB4=",
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"rev": "e82f32aa7f06bbbd56d7b12186d555223dc399d1",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
|
48
flake.nix
48
flake.nix
|
@ -18,13 +18,21 @@
|
|||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
|
||||
treefmt-nix = {
|
||||
url = "github:numtide/treefmt-nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = inputs @ { self, nixpkgs, flake-utils, ... }:
|
||||
outputs = { self, nixpkgs, flake-utils, treefmt-nix, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
pkgs = nixpkgs.legacyPackages."${system}";
|
||||
|
||||
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
|
||||
|
||||
shellHook = ''
|
||||
export NIX_CONFIG="experimental-features = nix-command flakes"
|
||||
export GOTOOLCHAIN=local
|
||||
|
@ -44,12 +52,12 @@
|
|||
(builtins.map
|
||||
(x: {
|
||||
name = x;
|
||||
value = nixpkgs.lib.genAttrs
|
||||
value = lib.genAttrs
|
||||
(
|
||||
builtins.map
|
||||
(y: x + ":" + y)
|
||||
(builtins.attrNames
|
||||
(nixpkgs.lib.attrsets.filterAttrs (k: v: v == "directory")
|
||||
(lib.attrsets.filterAttrs (k: v: v == "directory")
|
||||
(builtins.readDir ./stacks)
|
||||
)
|
||||
)
|
||||
|
@ -57,8 +65,6 @@
|
|||
}) [ "plan" "up" ]);
|
||||
in
|
||||
{
|
||||
formatter = pkgs.nixpkgs-fmt;
|
||||
|
||||
# `pulumi up` -> nix run .#up:<stack>
|
||||
apps = forPulumi.up
|
||||
(target:
|
||||
|
@ -86,25 +92,39 @@
|
|||
'';
|
||||
};
|
||||
}
|
||||
)
|
||||
# Other tasks
|
||||
// {
|
||||
lint = with pkgs; flake-utils.lib.mkApp {
|
||||
drv = writeShellScriptBin "lint" ''
|
||||
${golangci-lint}/bin/golangci-lint run
|
||||
);
|
||||
|
||||
checks = {
|
||||
golangci = with pkgs; runCommandLocal "golangci-check"
|
||||
{
|
||||
buildInputs = [ golangci-lint go ];
|
||||
meta.description = "Run golangci-lint against the code base";
|
||||
}
|
||||
''
|
||||
export HOME=$TMPDIR
|
||||
export LANG=C.UTF-8
|
||||
export LC_ALL=C.UTF-8
|
||||
|
||||
cd "${self}"
|
||||
golangci-lint run
|
||||
|
||||
# Require to pass mkDerivation
|
||||
touch $out
|
||||
'';
|
||||
};
|
||||
|
||||
treefmt = treefmtEval.config.build.check self;
|
||||
};
|
||||
|
||||
formatter = treefmtEval.config.build.wrapper;
|
||||
|
||||
devShells.default = with pkgs; mkShell {
|
||||
inherit shellHook;
|
||||
nativeBuildInputs = pulumiInputs ++ [
|
||||
git
|
||||
golangci-lint
|
||||
nix
|
||||
sops
|
||||
vim
|
||||
];
|
||||
shellHook = shellHook;
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
_:
|
||||
{
|
||||
projectRootFile = ".git/config";
|
||||
|
||||
# List of formatters: https://github.com/numtide/treefmt-nix/tree/main/programs
|
||||
programs = builtins.listToAttrs
|
||||
(
|
||||
builtins.map
|
||||
(x: {
|
||||
name = x;
|
||||
value.enable = true;
|
||||
})
|
||||
[
|
||||
"gofumpt"
|
||||
"nixpkgs-fmt"
|
||||
"shellcheck"
|
||||
"shfmt"
|
||||
"statix"
|
||||
"taplo"
|
||||
]
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue