Skip to content

Commit

Permalink
Refactor devShells
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Jul 18, 2023
1 parent d260c26 commit 992b94f
Showing 1 changed file with 62 additions and 34 deletions.
96 changes: 62 additions & 34 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,81 @@
parsedDevDeps = map self.lib.pep508.parseString pyproject.tool.pdm.dev-dependencies.dev;
in
pkgs.python3.withPackages (ps: map (dep: ps.${dep.name}) parsedDevDeps);

in
{

devShells.default = pkgs.mkShell {
packages = [
pkgs.treefmt # Format all the things in one go
pkgs.deadnix # Check for dead Nix code
pkgs.statix # Static Nix analysis
pkgs.ruff # Python linter
pkgs.nixpkgs-fmt # Nix formatter
pythonEnv
pkgs.pdm # Python PEP-621 compliant package manager
];

shellHook = ''
export NIX_PATH=nixpkgs=${nixpkgs}
'';
};
devShells.default =
let
checkInputs = builtins.filter (pkg: pkg != pkgs.nix) (
lib.unique (lib.flatten (
lib.mapAttrsToList (_: drv: drv.nativeBuildInputs) self.checks.${system}
))
);
in
pkgs.mkShell {
packages = checkInputs ++ [
pkgs.pdm
];
};

checks =
let
mkCheck = name: check: pkgs.runCommand name
{
nativeBuildInputs = self.devShells.${system}.default.nativeBuildInputs ++ [
(check.attrs or { })
''
cp -rv ${self} src
chmod +w -R src
cd src
${check.check}
touch $out
'';
in
lib.mapAttrs mkCheck {
pytest = {
attrs = {
nativeBuildInputs = [
pkgs.nix
pythonEnv
];
env.NIX_PATH = "nixpkgs=${nixpkgs}";
} ''
cp -rv ${self} src
chmod +w -R src
cd src
};
check = ''
export NIX_REMOTE=local?root=$PWD
pytest --workers auto
'';
};

export NIX_REMOTE=local?root=$PWD
# Format all the things in one go
treefmt = {
attrs.nativeBuildInputs = [ pkgs.treefmt pkgs.nixpkgs-fmt pythonEnv ];
check = "treefmt --no-cache --fail-on-change";
};

${check}
# Check for dead Nix code
deadnix = {
attrs.nativeBuildInputs = [ pkgs.deadnix ];
check = "deadnix --fail";
};

touch $out
'';
in
lib.mapAttrs mkCheck {
pytest = "pytest --workers auto";
treefmt = "treefmt --no-cache --fail-on-change";
deadnix = "deadnix --fail";
statix = "statix check";
mypy = "mypy .";
ruff = "ruff check .";
# Static Nix analysis
statix = {
attrs.nativeBuildInputs = [ pkgs.statix ];
check = "statix check";
};

# Python type checking
mypy = {
attrs.nativeBuildInputs = [ pythonEnv ];
check = "mypy .";
};

# Python linter
ruff = {
attrs.nativeBuildInputs = [ pkgs.ruff ];
check = "ruff check .";
};
};

});
Expand Down

0 comments on commit 992b94f

Please sign in to comment.