2022-12-01 09:12:19 +01:00
|
|
|
{
|
|
|
|
description = "Flake utils demo";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
|
|
|
|
};
|
|
|
|
|
|
|
|
outputs = { self, nixpkgs, flake-utils, pre-commit-hooks }:
|
2022-12-01 11:50:10 +01:00
|
|
|
flake-utils.lib.eachDefaultSystem
|
|
|
|
(system:
|
|
|
|
let
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
minVersion = 8;
|
|
|
|
maxVersion = 11;
|
|
|
|
mkPython = version: "python3${toString version}";
|
|
|
|
pythonVersions = map mkPython (pkgs.lib.lists.range minVersion maxVersion);
|
|
|
|
mkDevShell = version: pkgs.mkShell {
|
|
|
|
buildInputs = [ pkgs.${version} pkgs.poetry ];
|
2022-12-01 09:12:19 +01:00
|
|
|
};
|
2022-12-01 11:50:10 +01:00
|
|
|
addPreCommit = shell: shell.overrideAttrs (old: {
|
|
|
|
inherit (self.checks.${system}.pre-commit-check) shellHook;
|
|
|
|
});
|
|
|
|
devShells = pkgs.lib.genAttrs pythonVersions mkDevShell;
|
|
|
|
preCommitShells = pkgs.lib.mapAttrs' (name: value: pkgs.lib.nameValuePair (name + "-precommit") (addPreCommit value)) devShells;
|
|
|
|
allShells = devShells // preCommitShells;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
devShells = allShells // {
|
|
|
|
default = self.devShells.${system}."${mkPython maxVersion}-precommit";
|
|
|
|
};
|
|
|
|
checks.pre-commit-check = pre-commit-hooks.lib."${system}".run {
|
|
|
|
src = ./.;
|
|
|
|
hooks = {
|
|
|
|
nixpkgs-fmt.enable = true;
|
|
|
|
statix.enable = true;
|
|
|
|
shellcheck.enable = true;
|
|
|
|
black.enable = true;
|
|
|
|
isort.enable = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}) // {
|
|
|
|
templates.default = {
|
|
|
|
path = ./.;
|
|
|
|
description = "A adhoc python environment";
|
|
|
|
};
|
|
|
|
};
|
2022-12-01 09:12:19 +01:00
|
|
|
}
|