From 4e4a36ca7f602d25361a4a0ca583386bbbd262f4 Mon Sep 17 00:00:00 2001 From: Immelancholy Date: Sat, 6 Jun 2026 18:47:10 +0100 Subject: [PATCH 1/8] Add pre-commit hook for nix users, auto formats with ruff.sh and nix fmt --- .gitignore | 1 + flake.lock | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 36 ++++++++++++++++++++++++-- ruff.sh | 5 ++-- 4 files changed, 113 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index b609f70..9631fad 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .flatpak-builder/ .ignore/ .direnv/ +/.pre-commit-config.yaml # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/flake.lock b/flake.lock index bffd844..35b8c66 100644 --- a/flake.lock +++ b/flake.lock @@ -1,6 +1,79 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1778507602, + "narHash": "sha256-kTwur1wV+01SdqskVMSo6JMEpg71ps3HpbFY2GsflKs=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "61ab0e80d9c7ab14c256b5b453d8b3fb0189ba0a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { + "locked": { + "lastModified": 1770073757, + "narHash": "sha256-Vy+G+F+3E/Tl+GMNgiHl9Pah2DgShmIUBJXmbiQPHbI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "47472570b1e607482890801aeaf29bfb749884f6", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1780243769, "narHash": "sha256-x5UQuRsH3MqI0U9afaXSNqzTPSeZlRLvFAav2Ux1pNw=", @@ -18,7 +91,8 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs_2" } } }, diff --git a/flake.nix b/flake.nix index 50c7279..0185c6d 100644 --- a/flake.nix +++ b/flake.nix @@ -3,6 +3,7 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + git-hooks.url = "github:cachix/git-hooks.nix"; }; outputs = @@ -12,6 +13,7 @@ ... }: let + inherit (self) inputs; systems = [ "x86_64-linux" "aarch64-linux" @@ -39,15 +41,45 @@ 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: { + pre-commit-check = inputs.git-hooks.lib.${system}.run { + src = ./.; + hooks = { + nixfmt.enable = true; + + ruff-sh = { + enable = true; + entry = "./ruff.sh"; + }; + }; + }; + }); devShell = forAllSystems ( system: let pkgs = import nixpkgs { inherit system; }; + inherit (self.checks.${system}.pre-commit-check) shellHook enabledPackages; in pkgs.mkShell { - packages = [ + inherit shellHook; + buildInputs = enabledPackages; + packages = with pkgs; [ + bash + ruff self.packages.${pkgs.stdenv.hostPlatform.system}.default ]; } diff --git a/ruff.sh b/ruff.sh index 2612939..ace605c 100755 --- a/ruff.sh +++ b/ruff.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/env bash ruff check . --fix -ruff format . \ No newline at end of file +ruff format . + From fa45bd055ec1b7decaf66646cda0dc7d997311e8 Mon Sep 17 00:00:00 2001 From: Immelancholy Date: Sat, 6 Jun 2026 21:00:27 +0100 Subject: [PATCH 2/8] use prek, teehee rust --- flake.nix | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 0185c6d..03a88be 100644 --- a/flake.nix +++ b/flake.nix @@ -54,19 +54,27 @@ pkgs.writeShellScriptBin "pre-commit-run" script ); - checks = forAllSystems (system: { - pre-commit-check = inputs.git-hooks.lib.${system}.run { - src = ./.; - hooks = { - nixfmt.enable = true; + 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-sh = { - enable = true; - entry = "./ruff.sh"; + ruff-sh = { + enable = true; + entry = "./ruff.sh"; + }; }; + + package = pkgs.prek; }; - }; - }); + } + ); devShell = forAllSystems ( system: From e4f4697f57a7504762bc15023857598b486b17cc Mon Sep 17 00:00:00 2001 From: Immelancholy Date: Sun, 7 Jun 2026 00:28:31 +0100 Subject: [PATCH 3/8] direnv: add watch_dir src to .envrc so it actually reloads on --- .envrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.envrc b/.envrc index 3550a30..c70f005 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,3 @@ +watch_dir src + use flake From ef52874080a0f335640d0afca50255afbe7a1f65 Mon Sep 17 00:00:00 2001 From: Immelancholy Date: Sun, 7 Jun 2026 00:33:33 +0100 Subject: [PATCH 4/8] direnv: watch nix dir --- .envrc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.envrc b/.envrc index c70f005..e676596 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1,5 @@ watch_dir src +watch_dir nix + use flake From 9ebe8ec3e7196cf699be56ad33109066d2f6f244 Mon Sep 17 00:00:00 2001 From: Immelancholy Date: Sun, 7 Jun 2026 16:37:23 +0100 Subject: [PATCH 5/8] nix: read package version from pyproject.toml --- nix/package.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nix/package.nix b/nix/package.nix index 7fab868..8a74592 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -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 = ../.; From 48cc02001bceecf3c1f78c87e52f2586b0b9eb45 Mon Sep 17 00:00:00 2001 From: Immelancholy Date: Sun, 7 Jun 2026 18:05:12 +0100 Subject: [PATCH 6/8] check: fix checks --- flake.nix | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index 03a88be..a5eea2e 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,7 @@ in { default = pkgs.callPackage ./nix/package.nix { }; - anifetch = self.packages.default; + anifetch = self.packages.${system}.default; } ); @@ -65,9 +65,28 @@ hooks = { nixfmt.enable = true; - ruff-sh = { + ruff-check = { enable = true; - entry = "./ruff.sh"; + 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" + ]; }; }; @@ -76,20 +95,20 @@ } ); - devShell = forAllSystems ( + devShells = forAllSystems ( system: let pkgs = import nixpkgs { inherit system; }; inherit (self.checks.${system}.pre-commit-check) shellHook enabledPackages; in - pkgs.mkShell { - inherit shellHook; - buildInputs = enabledPackages; - packages = with pkgs; [ - bash - ruff - self.packages.${pkgs.stdenv.hostPlatform.system}.default - ]; + { + default = pkgs.mkShell { + inherit shellHook; + nativeBuildInputs = [ + self.packages.${system}.default + ] + ++ enabledPackages; + }; } ); }; From 52d4bda985ae305893736914d7afb08172b54fda Mon Sep 17 00:00:00 2001 From: Immelancholy Date: Sun, 7 Jun 2026 21:36:26 +0100 Subject: [PATCH 7/8] Devshell: Fix pip install devshell cos it's superior --- .envrc | 2 -- flake.nix | 27 +++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.envrc b/.envrc index e676596..fd3f77f 100644 --- a/.envrc +++ b/.envrc @@ -1,5 +1,3 @@ -watch_dir src - watch_dir nix use flake diff --git a/flake.nix b/flake.nix index a5eea2e..8384b6a 100644 --- a/flake.nix +++ b/flake.nix @@ -99,15 +99,38 @@ 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 { default = pkgs.mkShell { - inherit shellHook; nativeBuildInputs = [ - self.packages.${system}.default + 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." + ''; }; } ); From 51a1ea8f072032ad7e034ecf04e857b5f91e19c9 Mon Sep 17 00:00:00 2001 From: Mela Date: Sun, 7 Jun 2026 21:40:06 +0100 Subject: [PATCH 8/8] remove whitespaces from ruff.sh --- ruff.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ruff.sh b/ruff.sh index ace605c..fac5e86 100755 --- a/ruff.sh +++ b/ruff.sh @@ -2,4 +2,3 @@ ruff check . --fix ruff format . -