add treefmt-nix

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

@ -22,15 +22,16 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1673944933, "lastModified": 1673606088,
"narHash": "sha256-yrWHhOj7BwY/dbQ+Ifhanm/IZ6qWerZiGmFbmt0/wMU=", "narHash": "sha256-wdYD41UwNwPhTdMaG0AIe7fE1bAdyHe6bB4HLUqUvck=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "81aef2338a3834f4d0071978dbc114497ec56a7e", "rev": "37b97ae3dd714de9a17923d004a2c5b5543dfa6d",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
@ -38,7 +39,23 @@
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts", "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 = { inputs = {
flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; 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, ...}: outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} { flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux"]; systems = ["x86_64-linux" "aarch64-linux"];
imports = [
./nix/checks/flake-module.nix
];
perSystem = { perSystem = {
config, config,
self', self',
@ -19,15 +24,21 @@
... ...
}: { }: {
packages.default = pkgs.callPackage ./default.nix {}; packages.default = pkgs.callPackage ./default.nix {};
devShells.default = pkgs.callPackage ./shell.nix {}; devShells.default = pkgs.mkShellNoCC {
checks = let buildInputs = with pkgs; [
nixosTests = pkgs.callPackages ./nix/checks/nixos-test.nix { python3.pkgs.pytest
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix"); python3.pkgs.mypy
};
in { golangci-lint
treefmt = pkgs.callPackage ./nix/checks/treefmt.nix {}; vault
inherit (nixosTests) unittests vault-agent systemd-vaultd; systemd
hivemind
go
just
config.packages.treefmt
];
}; };
}; };
flake.nixosModules = { flake.nixosModules = {
vaultAgent = ./nix/modules/vault-agent.nix; 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 { mkShellNoCC {
buildInputs = [ buildInputs = [
python3.pkgs.pytest python3.pkgs.pytest
python3.pkgs.flake8
python3.pkgs.black
python3.pkgs.mypy python3.pkgs.mypy
gofumpt
golangci-lint golangci-lint
alejandra
vault vault
systemd systemd
hivemind hivemind
go go
treefmt
just 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