[question] How to add pre-commit hooks to nixos flake configuration?
cronyakatsuki opened this issue · 1 comments
cronyakatsuki commented
Hello, I have been trying out pre-commit hooks and am interested how would I be going around adding it to my nixos flake configuration?
I have tried out this with the flake only, but get the next error:
flake.nix
{
description = "Nixos config flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
flake-utils.url = "github:numtide/flake-utils";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nixvim = {
url = "github:nix-community/nixvim";
inputs.nixpkgs.follows = "nixpkgs";
};
hb-downloader = {
url = "git+file:///home/crony/Documents/develop/hb-downloader";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ self, nixpkgs, flake-utils, pre-commit-hooks, home-manager
, ... }: {
nixosConfigurations = {
default = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./nixos/configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.extraSpecialArgs = { inherit inputs; };
home-manager.users.crony = {
imports = [ ./home-manager/home.nix ];
};
}
flake-utils.lib.eachDefaultSystem
(system: {
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = { nixpkgs-fmt.enable = true; };
};
};
devShell = nixpkgs.legacyPackages.${system}.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
};
})
];
};
};
};
}
error
error:
… while checking flake output 'nixosConfigurations'
at /nix/store/8c26jqrhnk2iw0hynh3jr9gy7yixz819-source/flake.nix:29:7:
28| , ... }: {
29| nixosConfigurations = {
| ^
30| default = nixpkgs.lib.nixosSystem {
… while checking the NixOS configuration 'nixosConfigurations.default'
at /nix/store/8c26jqrhnk2iw0hynh3jr9gy7yixz819-source/flake.nix:30:9:
29| nixosConfigurations = {
30| default = nixpkgs.lib.nixosSystem {
| ^
31| system = "x86_64-linux";
(stack trace truncated; use '--show-trace' to show the full trace)
error: attempt to call something which is not a function but a set
at /nix/store/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source/lib.nix:36:17:
35| let
36| ret = f system;
| ^
37| op = attrs: key: attrs //
I'm still new to nix and flakes, so would like some help. The flake is located in my user directory.
cronyakatsuki commented
Fixed by adding a simple shell.nix and making a shell environment.