Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
watch_dir nix

use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.flatpak-builder/
.ignore/
.direnv/
/.pre-commit-config.yaml

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
76 changes: 75 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 89 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
git-hooks.url = "github:cachix/git-hooks.nix";
};

outputs =
Expand All @@ -12,6 +13,7 @@
...
}:
let
inherit (self) inputs;
systems = [
"x86_64-linux"
"aarch64-linux"
Expand All @@ -28,7 +30,7 @@
in
{
default = pkgs.callPackage ./nix/package.nix { };
anifetch = self.packages.default;
anifetch = self.packages.${system}.default;
}
);

Expand All @@ -39,17 +41,97 @@
anifetch = self.overlays.default;
};

formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-tree);
formatter = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
config = self.checks.${system}.pre-commit-check.config;
inherit (config) package configFile;
script = ''
${pkgs.lib.getExe package} run --all-files --config ${configFile}
'';
in
pkgs.writeShellScriptBin "pre-commit-run" script
);

checks = forAllSystems (
system:
let
pkgs = import nixpkgs { inherit system; };
in
{
pre-commit-check = inputs.git-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixfmt.enable = true;

ruff-check = {
enable = true;
entry = "${pkgs.lib.getExe pkgs.ruff}";
args = [
"check"
"--fix"
];
types = [
"file"
"python"
];
};
ruff-format = {
enable = true;
entry = "${pkgs.lib.getExe pkgs.ruff}";
args = [
"format"
];
types = [
"file"
"python"
];
};
};

package = pkgs.prek;
};
}
);

devShell = forAllSystems (
devShells = forAllSystems (
system:
let
pkgs = import nixpkgs { inherit system; };
myPython = pkgs.python3;
pythonWithPkgs = myPython.withPackages (ps: [
ps.pip
ps.setuptools
]);

venv = "venv";
inherit (self.checks.${system}.pre-commit-check) shellHook enabledPackages;
in
pkgs.mkShell {
packages = [
self.packages.${pkgs.stdenv.hostPlatform.system}.default
];
{
default = pkgs.mkShell {
nativeBuildInputs = [
pythonWithPkgs
pkgs.bc
pkgs.chafa
pkgs.ffmpeg
]
++ enabledPackages;
shellHook = shellHook + ''
export "CPATH=${pkgs.linuxHeaders}/include:$CPATH"
if [ ! -d "${venv}" ]; then
echo "Creating Python venv..."
python3 -m venv ${venv}
fi
echo "Activating venv..."
source ${venv}/bin/activate
if ! pip show anifetch &>/dev/null; then
echo "Aniftech not installed: Install anifetch..."
pip install -e .
fi
echo "Venv activated."
'';
};
}
);
};
Expand Down
5 changes: 3 additions & 2 deletions nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
let
fs = lib.fileset;
sourceFiles = ../.;
anifetchPyprojectToml = fromTOML (builtins.readFile ../pyproject.toml);
in
fs.trace sourceFiles python3Packages.buildPythonApplication {
name = "anifetch-wrapped";
version = "git";
pname = "anifetch";
version = "${anifetchPyprojectToml.project.version}-git";
pyproject = true;
src = fs.toSource {
root = ../.;
Expand Down
4 changes: 2 additions & 2 deletions ruff.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

ruff check . --fix
ruff format .
ruff format .
Loading