From 81f128265cbf81a64870b03883db34a33da0d797 Mon Sep 17 00:00:00 2001 From: Fishandchips321 Date: Sun, 1 Mar 2026 15:33:24 +0000 Subject: [PATCH] added checks and formatting pre-commit hooks --- .gitignore | 1 + flake.lock | 100 ++++++++++++++++++++++++-- flake.nix | 48 ++++++++++++- modules/boot.nix | 10 +-- modules/default-packages.nix | 2 +- modules/k3s.nix | 7 +- modules/networkManager.nix | 6 +- systems/vm/configuration.nix | 2 +- systems/vm/hardware-configuration.nix | 30 ++++---- treefmt.toml | 2 +- 10 files changed, 166 insertions(+), 42 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c6f3fa --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.pre-commit-config.yaml \ No newline at end of file diff --git a/flake.lock b/flake.lock index 82d8ab7..931cd7f 100644 --- a/flake.lock +++ b/flake.lock @@ -1,24 +1,114 @@ { "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": 1772024342, + "narHash": "sha256-+eXlIc4/7dE6EcPs9a2DaSY3fTA9AE526hGqkNID3Wg=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "6e34e97ed9788b17796ee43ccdbaf871a5c2b476", + "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": 1771848320, - "narHash": "sha256-0MAd+0mun3K/Ns8JATeHT1sX28faLII5hVLq0L3BdZU=", + "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": 1772047000, + "narHash": "sha256-7DaQVv4R97cii/Qdfy4tmDZMB2xxtyIvNGSwXBBhSmo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2fc6539b481e1d2569f25f8799236694180c0993", + "rev": "1267bb4920d0fc06ea916734c11b0bf004bbe17e", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-unstable", + "ref": "nixos-25.11", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs_2", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 42af1f5..137b540 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,54 @@ { inputs = { - nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-25.11"; + systems.url = "github:nix-systems/default"; + git-hooks.url = "github:cachix/git-hooks.nix"; }; outputs = - { self, nixpkgs }: { - # hydraJobs = nixpkgs.lib.mapAttrs (_: value: value.config.system.build.toplevel) self.nixosConfigurations; + self, + systems, + nixpkgs, + ... + }@inputs: + let + forEachSystem = inputs.nixpkgs.lib.genAttrs (import systems); + in + { + formatter = forEachSystem ( + system: + let + pkgs = inputs.nixpkgs.legacyPackages.${system}; + in + pkgs.treefmt + ); + + checks = forEachSystem (system: { + pre-commit-check = inputs.git-hooks.lib.${system}.run { + src = ./.; + hooks = { + treefmt.enable = true; + treefmt.settings.formatters = [ inputs.nixpkgs.legacyPackages.${system}.nixfmt ]; + statix.enable = true; + deadnix.enable = true; + nil.enable = true; + }; + }; + }); + + devShells = forEachSystem (system: { + default = + let + pkgs = nixpkgs.legacyPackages.${system}; + inherit (self.checks.${system}.pre-commit-check) shellHook enabledPackages; + in + pkgs.mkShell { + inherit shellHook; + buildInputs = enabledPackages; + }; + }); + nixosConfigurations = { vm = nixpkgs.lib.nixosSystem { modules = [ ./systems/vm/configuration.nix ]; }; }; diff --git a/modules/boot.nix b/modules/boot.nix index 7181c0f..6640b39 100644 --- a/modules/boot.nix +++ b/modules/boot.nix @@ -1,7 +1,9 @@ -{ config, pkgs, ... }: +_: { - boot.loader.grub.enable = true; - boot.loader.grub.device = "/dev/vda"; - boot.loader.grub.useOSProber = true; + boot.loader.grub = { + enable = true; + device = "/dev/vda"; + useOSProber = true; + }; } diff --git a/modules/default-packages.nix b/modules/default-packages.nix index 1eb713f..ff957ba 100644 --- a/modules/default-packages.nix +++ b/modules/default-packages.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ pkgs, ... }: { programs = { diff --git a/modules/k3s.nix b/modules/k3s.nix index 0df95ff..781da73 100644 --- a/modules/k3s.nix +++ b/modules/k3s.nix @@ -1,9 +1,4 @@ -{ - config, - pkgs, - lib, - ... -}: +{ config, lib, ... }: let cfg = config.modules.k3s; diff --git a/modules/networkManager.nix b/modules/networkManager.nix index 34b6b7c..c576060 100644 --- a/modules/networkManager.nix +++ b/modules/networkManager.nix @@ -1,5 +1 @@ -{ config, pkgs, ... }: - -{ - networking.networkmanager.enable = true; -} +_: { networking.networkmanager.enable = true; } diff --git a/systems/vm/configuration.nix b/systems/vm/configuration.nix index 61fec7c..0ed30cc 100644 --- a/systems/vm/configuration.nix +++ b/systems/vm/configuration.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +_: { imports = [ diff --git a/systems/vm/hardware-configuration.nix b/systems/vm/hardware-configuration.nix index 23f42df..000e8b6 100644 --- a/systems/vm/hardware-configuration.nix +++ b/systems/vm/hardware-configuration.nix @@ -1,22 +1,20 @@ -{ - config, - lib, - pkgs, - modulesPath, - ... -}: +{ lib, modulesPath, ... }: { imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; - boot.initrd.availableKernelModules = [ - "ahci" - "xhci_pci" - "virtio_pci" - "sr_mod" - "virtio_blk" - ]; - boot.initrd.kernelModules = [ ]; - boot.extraModulePackages = [ ]; + boot = { + initrd = { + availableKernelModules = [ + "ahci" + "xhci_pci" + "virtio_pci" + "sr_mod" + "virtio_blk" + ]; + kernelModules = [ ]; + }; + extraModulePackages = [ ]; + }; fileSystems."/" = { device = "/dev/disk/by-uuid/ed56e12e-55cc-42e0-b94f-9a6d6bb2bdad"; diff --git a/treefmt.toml b/treefmt.toml index c883b33..4d63807 100644 --- a/treefmt.toml +++ b/treefmt.toml @@ -46,7 +46,7 @@ # Env $TREEFMT_WALK # walk = "filesystem" -[formatter.mylanguage] +[formatter.nixfmt] # Command to execute command = "nixfmt" # Command-line arguments for the command