From 5637b6188f2700cb94433080f14d2b8447aeaab1 Mon Sep 17 00:00:00 2001 From: Artem Sheremet Date: Sat, 28 Mar 2026 23:18:52 +0100 Subject: [PATCH] Upgrade flake with pre-commit hooks and devShell --- .envrc | 1 + .gitignore | 10 +++++-- flake.lock | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++- flake.nix | 47 +++++++++++++++++++++++++++----- 4 files changed, 126 insertions(+), 10 deletions(-) create mode 100644 .envrc diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 550c6a7..7e3a1d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ -# "nix build" default output symlink -/result +# direnv cache +/.direnv + +# "nix build" default output link +result + +# nix pre-commit autogenerated by devShell +/.pre-commit-config.yaml diff --git a/flake.lock b/flake.lock index 962dc49..a7b5166 100644 --- a/flake.lock +++ b/flake.lock @@ -53,9 +53,25 @@ "type": "github" } }, + "flake-compat_2": { + "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" + } + }, "flake-utils": { "inputs": { - "systems": "systems_2" + "systems": "systems_3" }, "locked": { "lastModified": 1681202837, @@ -116,6 +132,28 @@ "type": "github" } }, + "git-hooks_2": { + "inputs": { + "flake-compat": "flake-compat_2", + "gitignore": "gitignore_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1774104215, + "narHash": "sha256-EAtviqz0sEAxdHS4crqu7JGR5oI3BwaqG0mw7CmXkO8=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "f799ae951fde0627157f40aec28dec27b22076d0", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ @@ -138,6 +176,27 @@ "type": "github" } }, + "gitignore_2": { + "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" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -212,10 +271,12 @@ "inputs": { "darwin": "darwin", "fw_nix": "fw_nix", + "git-hooks": "git-hooks_2", "home-manager": "home-manager", "nix-homebrew": "nix-homebrew", "nixpkgs": "nixpkgs", "nixpkgs-screen": "nixpkgs-screen", + "systems": "systems_2", "vscode-server": "vscode-server" } }, @@ -249,6 +310,21 @@ "type": "github" } }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "vscode-server": { "inputs": { "flake-utils": "flake-utils", diff --git a/flake.nix b/flake.nix index 731f076..60c70fd 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,7 @@ # - background colors in programs (eg less) not showing # - caption and hardstatus color lacks intensity nixpkgs-screen.url = "github:NixOS/nixpkgs/e518d4ad2bcad74f98fec028cf21ce5b1e5020dd"; + systems.url = "github:nix-systems/default"; home-manager = { url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; @@ -25,12 +26,17 @@ inputs.nixpkgs.follows = "nixpkgs"; }; nix-homebrew.url = "github:zhaofengli/nix-homebrew"; + git-hooks = { + url = "github:cachix/git-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { self, nixpkgs, + systems, home-manager, vscode-server, darwin, @@ -42,8 +48,18 @@ "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJhQjxeLZUWdEPMqPNS8wTTrg4lbzBAOLKvdsJd0fSBcW5ILuEbKQjgEIwmYuR/iGhnqIp7rQK48xL/4CauQUyg= office-dock-usb-a" "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJg7zQ4H0LQeQcILZBwCzQ+MYKtCgKm7HPe9oFeoyprKZXAvpm+HDHtaYdU39JF9f+nvRztzXuMhgETAQMAQCkc= fingerprint@macbook" ]; + eachSystem = nixpkgs.lib.genAttrs (import systems); in { + checks = eachSystem (system: { + pre-commit-check = inputs.git-hooks.lib.${system}.run ( + { + src = ./.; + } + // inputs.fw_nix.lib.pre-commit + ); + }); + homeModules.main = { imports = [ ./modules/home.nix ]; }; @@ -73,13 +89,16 @@ inputs.fw_nix.nixosModules.nix-settings inputs.fw_nix.nixosModules.futureware inputs.nix-homebrew.darwinModules.nix-homebrew - ({ lib, ... }: { - # TODO: find solution to these ugly workarounds - options.programs.htop = lib.mkOption { - type = lib.types.deferredModule; - default = { }; - }; - }) + ( + { lib, ... }: + { + # TODO: find solution to these ugly workarounds + options.programs.htop = lib.mkOption { + type = lib.types.deferredModule; + default = { }; + }; + } + ) ./hosts/mars/darwin.nix ]; }; @@ -105,5 +124,19 @@ ./hosts/deimos/nixos.nix ]; }; + + devShells = eachSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + inherit (self.checks.${system}.pre-commit-check) shellHook enabledPackages; + in + { + default = pkgs.mkShell { + packages = enabledPackages; + inherit shellHook; + }; + } + ); }; }