add treefmt-nix

main
Jörg Thalheim 2 years ago
parent 05bce1e1f8
commit cc78160e6e

@ -22,15 +22,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1673944933,
"narHash": "sha256-yrWHhOj7BwY/dbQ+Ifhanm/IZ6qWerZiGmFbmt0/wMU=",
"lastModified": 1673606088,
"narHash": "sha256-wdYD41UwNwPhTdMaG0AIe7fE1bAdyHe6bB4HLUqUvck=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "81aef2338a3834f4d0071978dbc114497ec56a7e",
"rev": "37b97ae3dd714de9a17923d004a2c5b5543dfa6d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
@ -38,7 +39,23 @@
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"treefmt-nix": {
"locked": {
"lastModified": 1672931382,
"narHash": "sha256-lgtc2Sct/xtvqkdzlJ4AL3Vesw0Wz/fxqNGOBFS7YXU=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "6717065d6a432bc3f5b827007ad959e6032d5856",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},

@ -4,12 +4,17 @@
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux"];
imports = [
./nix/checks/flake-module.nix
];
perSystem = {
config,
self',
@ -19,15 +24,21 @@
...
}: {
packages.default = pkgs.callPackage ./default.nix {};
devShells.default = pkgs.callPackage ./shell.nix {};
checks = let
nixosTests = pkgs.callPackages ./nix/checks/nixos-test.nix {
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
};
in {
treefmt = pkgs.callPackage ./nix/checks/treefmt.nix {};
inherit (nixosTests) unittests vault-agent systemd-vaultd;
devShells.default = pkgs.mkShellNoCC {
buildInputs = with pkgs; [
python3.pkgs.pytest
python3.pkgs.mypy
golangci-lint
vault
systemd
hivemind
go
just
config.packages.treefmt
];
};
};
flake.nixosModules = {
vaultAgent = ./nix/modules/vault-agent.nix;

@ -0,0 +1,68 @@
{inputs, ...}: {
imports = [
inputs.treefmt-nix.flakeModule
];
perSystem = {
self',
inputs',
pkgs,
system,
...
}: {
treefmt = {
# Used to find the project root
projectRootFile = "flake.lock";
programs.gofumpt.enable = true;
programs.prettier.enable = true;
settings.formatter = {
nix = {
command = "sh";
options = [
"-eucx"
''
# First deadnix
${pkgs.lib.getExe pkgs.deadnix} --edit "$@"
# Then nixpkgs-fmt
${pkgs.lib.getExe pkgs.nixpkgs-fmt} "$@"
''
"--"
];
includes = ["*.nix"];
};
python = {
command = "sh";
options = [
"-eucx"
''
${pkgs.lib.getExe pkgs.ruff} --fix "$@"
${pkgs.lib.getExe pkgs.python3.pkgs.black} "$@"
''
"--" # this argument is ignored by bash
];
includes = ["*.py"];
};
};
checks =
let
nixosTests = pkgs.callPackages ./nixos-test.nix {
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
};
in
{
inherit (nixosTests) unittests vault-agent systemd-vaultd;
};
};
checks = let
nixosTests = pkgs.callPackages ./nix/checks/nixos-test.nix {
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
};
in {
inherit (nixosTests) unittests vault-agent systemd-vaultd;
};
};
}

@ -1,22 +0,0 @@
{
runCommand,
gofumpt,
alejandra,
python3,
treefmt,
}:
runCommand "treefmt" {
nativeBuildInputs = [
gofumpt
treefmt
alejandra
python3.pkgs.flake8
python3.pkgs.black
];
} ''
# keep timestamps so that treefmt is able to detect mtime changes
cp --no-preserve=mode --preserve=timestamps -r ${../..} source
cd source
HOME=$TMPDIR treefmt --no-cache --fail-on-change
touch $out
''

@ -3,18 +3,13 @@ with pkgs;
mkShellNoCC {
buildInputs = [
python3.pkgs.pytest
python3.pkgs.flake8
python3.pkgs.black
python3.pkgs.mypy
gofumpt
golangci-lint
alejandra
vault
systemd
hivemind
go
treefmt
just
];
}

@ -1,21 +0,0 @@
[formatter.nix]
command = "alejandra"
includes = ["*.nix"]
[formatter.python]
command = "sh"
options = [
"-eucx",
"""
flake8 "$@"
black "$@"
"""
]
includes = ["*.py"]
excludes = []
[formatter.go]
command = "gofumpt"
options = ["-w"]
includes = ["*.go"]
excludes = []
Loading…
Cancel
Save