50 lines
1.7 KiB
Nix
50 lines
1.7 KiB
Nix
{
|
|
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 }:
|
|
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 ];
|
|
};
|
|
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";
|
|
};
|
|
};
|
|
}
|