Convert to manual pre-commit

This commit is contained in:
Greg Hellings
2025-12-08 05:53:17 -06:00
parent 8964529f1a
commit a9806e4eb5
9 changed files with 71 additions and 140 deletions
-1
View File
@@ -1,6 +1,5 @@
host host
result result
.pre-commit-config.yaml
.direnv .direnv
# On home-manager only installs, this is built into the same dir # On home-manager only installs, this is built into the same dir
# where I am storing my repo # where I am storing my repo
+40
View File
@@ -0,0 +1,40 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-illegal-windows-names
- id: check-json
- id: check-merge-conflict
args:
- "--assume-in-merge"
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-yaml
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.37.1
hooks:
- id: yamllint
args:
- "-d"
- |-
extends: default
ignore:
- manifests/cnpg-system/barman-cloud.yaml
rules:
comments: false
comments-indentation: false
document-start: false
- repo: https://github.com/NixOS/nixfmt
rev: v1.1.0
hooks:
- id: nixfmt-nix
- repo: https://github.com/astro/deadnix
rev: v1.3.1
hooks:
- id: deadnix
+3 -34
View File
@@ -1,5 +1,4 @@
{ {
hooks,
lib, lib,
system, system,
top, top,
@@ -9,39 +8,9 @@
let let
meta = import ./hosts/metadata.nix; meta = import ./hosts/metadata.nix;
in in
{ # Pulls all hosts down to be a check
pre-commit-check = hooks.lib.${system}.run { (builtins.mapAttrs (_n: v: v.config.system.build.toplevel) (
src = ./.;
hooks = {
deadnix.enable = true;
# Needs https://github.com/DeterminateSystems/flake-checker/pull/130
#flake-checker.enable = true;
nixfmt-rfc-style.enable = true;
check-merge-conflicts.enable = true;
check-yaml.enable = true;
yamllint = {
enable = true;
args = [
"--config-data"
(lib.generators.toYAML { } {
extends = "default";
ignore = [
"manifests/cnpg-system/barman-cloud.yaml"
".pre-commit-config.yaml"
];
rules = {
comments = false;
comments-indentation = false;
document-start = false;
};
})
];
verbose = true;
};
};
};
}
// (builtins.mapAttrs (_n: v: v.config.system.build.toplevel) (
lib.filterAttrs (n: _v: builtins.any (a: a == system) meta.${n}.arch) top.self.nixosConfigurations lib.filterAttrs (n: _v: builtins.any (a: a == system) meta.${n}.arch) top.self.nixosConfigurations
)) ))
# Adds all packages as a check
// (top.self.packages.${system}) // (top.self.packages.${system})
Generated
+6 -80
View File
@@ -160,22 +160,6 @@
} }
}, },
"flake-compat": { "flake-compat": {
"flake": false,
"locked": {
"lastModified": 1761588595,
"narHash": "sha256-XKUZz9zewJNUj46b4AJdiRZJAvSZ0Dqj2BNfXvFlJC4=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "f387cd2afec9419c8ee37694406ca490c3f34ee5",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-compat_2": {
"locked": { "locked": {
"lastModified": 1747046372, "lastModified": 1747046372,
"narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=", "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
@@ -190,7 +174,7 @@
"type": "github" "type": "github"
} }
}, },
"flake-compat_3": { "flake-compat_2": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1761588595, "lastModified": 1761588595,
@@ -358,27 +342,6 @@
"type": "github" "type": "github"
} }
}, },
"gitignore": {
"inputs": {
"nixpkgs": [
"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"
}
},
"haumea": { "haumea": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
@@ -468,26 +431,6 @@
"type": "github" "type": "github"
} }
}, },
"hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1763988335,
"narHash": "sha256-QlcnByMc8KBjpU37rbq5iP7Cp97HvjRP0ucfdh+M4Qc=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "50b9238891e388c9fdc6a5c49e49c42533a1b5ce",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"ixx": { "ixx": {
"inputs": { "inputs": {
"flake-utils": [ "flake-utils": [
@@ -713,22 +656,6 @@
} }
}, },
"nixpkgs_3": { "nixpkgs_3": {
"locked": {
"lastModified": 1759417375,
"narHash": "sha256-O7eHcgkQXJNygY6AypkF9tFhsoDQjpNEojw3eFs73Ow=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "dc704e6102e76aad573f63b74c742cd96f8f1e6c",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_4": {
"locked": { "locked": {
"lastModified": 1764517877, "lastModified": 1764517877,
"narHash": "sha256-pp3uT4hHijIC8JUK5MEqeAWmParJrgBVzHLNfJDZxg4=", "narHash": "sha256-pp3uT4hHijIC8JUK5MEqeAWmParJrgBVzHLNfJDZxg4=",
@@ -744,7 +671,7 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_5": { "nixpkgs_4": {
"locked": { "locked": {
"lastModified": 1759770925, "lastModified": 1759770925,
"narHash": "sha256-CZwkCtzTNclqlhuwDsVtGoRumTpqCUK0xSnFIMgd8ls=", "narHash": "sha256-CZwkCtzTNclqlhuwDsVtGoRumTpqCUK0xSnFIMgd8ls=",
@@ -803,7 +730,7 @@
"nurpkgs": { "nurpkgs": {
"inputs": { "inputs": {
"flake-parts": "flake-parts_4", "flake-parts": "flake-parts_4",
"nixpkgs": "nixpkgs_4" "nixpkgs": "nixpkgs_3"
}, },
"locked": { "locked": {
"lastModified": 1764709261, "lastModified": 1764709261,
@@ -869,7 +796,7 @@
}, },
"proxmox": { "proxmox": {
"inputs": { "inputs": {
"flake-compat": "flake-compat_2", "flake-compat": "flake-compat",
"nixpkgs-libvncserver": "nixpkgs-libvncserver", "nixpkgs-libvncserver": "nixpkgs-libvncserver",
"nixpkgs-stable": "nixpkgs-stable", "nixpkgs-stable": "nixpkgs-stable",
"nixpkgs-unstable": "nixpkgs-unstable_2", "nixpkgs-unstable": "nixpkgs-unstable_2",
@@ -898,7 +825,6 @@
"darwin": "darwin_2", "darwin": "darwin_2",
"flake-parts": "flake-parts_2", "flake-parts": "flake-parts_2",
"hmunstable": "hmunstable", "hmunstable": "hmunstable",
"hooks": "hooks",
"nix-hardware": "nix-hardware", "nix-hardware": "nix-hardware",
"nixos-generators": "nixos-generators", "nixos-generators": "nixos-generators",
"nixunstable": "nixunstable", "nixunstable": "nixunstable",
@@ -1092,7 +1018,7 @@
}, },
"vsext": { "vsext": {
"inputs": { "inputs": {
"nixpkgs": "nixpkgs_5" "nixpkgs": "nixpkgs_4"
}, },
"locked": { "locked": {
"lastModified": 1764640937, "lastModified": 1764640937,
@@ -1110,7 +1036,7 @@
}, },
"wsl": { "wsl": {
"inputs": { "inputs": {
"flake-compat": "flake-compat_3", "flake-compat": "flake-compat_2",
"nixpkgs": [ "nixpkgs": [
"nixunstable" "nixunstable"
] ]
-1
View File
@@ -24,7 +24,6 @@
inputs.nixpkgs.follows = "nixunstable"; inputs.nixpkgs.follows = "nixunstable";
}; };
flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.url = "github:hercules-ci/flake-parts";
hooks.url = "github:cachix/git-hooks.nix";
hmunstable = { hmunstable = {
url = "github:nix-community/home-manager/master"; url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixunstable"; inputs.nixpkgs.follows = "nixunstable";
-1
View File
@@ -217,4 +217,3 @@ let g:ctrlp_user_command = {
\} \}
" let g:ctrpl_match_func = { 'match': 'pymatcher#PyMatch' } " let g:ctrpl_match_func = { 'match': 'pymatcher#PyMatch' }
" map <F6> <Esc>:CtrlP<Cr> " map <F6> <Esc>:CtrlP<Cr>
+18 -18
View File
@@ -3,9 +3,9 @@ index a16b52a..37faf08 100644
--- c/attic/src/nix_store/bindings/mod.rs --- c/attic/src/nix_store/bindings/mod.rs
+++ i/attic/src/nix_store/bindings/mod.rs +++ i/attic/src/nix_store/bindings/mod.rs
@@ -10,6 +10,8 @@ use tokio::io::{AsyncWrite, AsyncWriteExt}; @@ -10,6 +10,8 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
use crate::{AtticError, AtticResult}; use crate::{AtticError, AtticResult};
+use super::stream_config::NarStreamConfig; +use super::stream_config::NarStreamConfig;
+ +
// The C++ implementation takes care of concurrency // The C++ implementation takes care of concurrency
@@ -19,7 +19,7 @@ index a16b52a..37faf08 100644
+ error::SendError, channel, Receiver, Sender, + error::SendError, channel, Receiver, Sender,
}; };
} }
+ +
+ +
/// Async write request. /// Async write request.
@@ -32,7 +32,7 @@ index a16b52a..37faf08 100644
- sender: mpsc::UnboundedSender<AsyncWriteMessage>, - sender: mpsc::UnboundedSender<AsyncWriteMessage>,
+ sender: mpsc::Sender<AsyncWriteMessage>, + sender: mpsc::Sender<AsyncWriteMessage>,
} }
impl AsyncWriteSender { impl AsyncWriteSender {
fn send(&mut self, data: &[u8]) -> Result<(), mpsc::SendError<AsyncWriteMessage>> { fn send(&mut self, data: &[u8]) -> Result<(), mpsc::SendError<AsyncWriteMessage>> {
let message = AsyncWriteMessage::Data(Vec::from(data)); let message = AsyncWriteMessage::Data(Vec::from(data));
@@ -41,13 +41,13 @@ index a16b52a..37faf08 100644
+ // This provides backpressure when the channel is full + // This provides backpressure when the channel is full
+ self.sender.blocking_send(message).map_err(|e| mpsc::SendError(e.0)) + self.sender.blocking_send(message).map_err(|e| mpsc::SendError(e.0))
} }
fn eof(&mut self) -> Result<(), mpsc::SendError<AsyncWriteMessage>> { fn eof(&mut self) -> Result<(), mpsc::SendError<AsyncWriteMessage>> {
let message = AsyncWriteMessage::Eof; let message = AsyncWriteMessage::Eof;
- self.sender.send(message) - self.sender.send(message)
+ self.sender.blocking_send(message).map_err(|e| mpsc::SendError(e.0)) + self.sender.blocking_send(message).map_err(|e| mpsc::SendError(e.0))
} }
pub(crate) fn rust_error( pub(crate) fn rust_error(
@@ -76,19 +82,25 @@ impl AsyncWriteSender { @@ -76,19 +82,25 @@ impl AsyncWriteSender {
error: impl std::error::Error, error: impl std::error::Error,
@@ -58,14 +58,14 @@ index a16b52a..37faf08 100644
+ self.sender.try_send(message) + self.sender.try_send(message)
} }
} }
/// A wrapper of the `AsyncWrite` trait for the synchronous Nix C++ land. /// A wrapper of the `AsyncWrite` trait for the synchronous Nix C++ land.
pub struct AsyncWriteAdapter { pub struct AsyncWriteAdapter {
- receiver: mpsc::UnboundedReceiver<AsyncWriteMessage>, - receiver: mpsc::UnboundedReceiver<AsyncWriteMessage>,
+ receiver: mpsc::Receiver<AsyncWriteMessage>, + receiver: mpsc::Receiver<AsyncWriteMessage>,
eof: bool, eof: bool,
} }
impl AsyncWriteAdapter { impl AsyncWriteAdapter {
pub fn new() -> (Self, Box<AsyncWriteSender>) { pub fn new() -> (Self, Box<AsyncWriteSender>) {
- let (sender, receiver) = mpsc::unbounded_channel(); - let (sender, receiver) = mpsc::unbounded_channel();
@@ -75,7 +75,7 @@ index a16b52a..37faf08 100644
+ pub fn new_with_config(config: NarStreamConfig) -> (Self, Box<AsyncWriteSender>) { + pub fn new_with_config(config: NarStreamConfig) -> (Self, Box<AsyncWriteSender>) {
+ // Use bounded channel to provide backpressure and prevent OOM + // Use bounded channel to provide backpressure and prevent OOM
+ let (sender, receiver) = mpsc::channel(config.channel_capacity); + let (sender, receiver) = mpsc::channel(config.channel_capacity);
let r = Self { let r = Self {
receiver, receiver,
diff --git c/attic/src/nix_store/mod.rs i/attic/src/nix_store/mod.rs diff --git c/attic/src/nix_store/mod.rs i/attic/src/nix_store/mod.rs
@@ -85,7 +85,7 @@ index 4e08a67..04ef0f6 100644
@@ -46,6 +46,9 @@ mod bindings; @@ -46,6 +46,9 @@ mod bindings;
#[cfg(feature = "nix_store")] #[cfg(feature = "nix_store")]
mod nix_store; mod nix_store;
+#[cfg(feature = "nix_store")] +#[cfg(feature = "nix_store")]
+mod stream_config; +mod stream_config;
+ +
@@ -95,34 +95,34 @@ index 4e08a67..04ef0f6 100644
@@ -61,6 +64,9 @@ use crate::hash::Hash; @@ -61,6 +64,9 @@ use crate::hash::Hash;
#[cfg(feature = "nix_store")] #[cfg(feature = "nix_store")]
pub use nix_store::NixStore; pub use nix_store::NixStore;
+#[cfg(feature = "nix_store")] +#[cfg(feature = "nix_store")]
+pub use stream_config::NarStreamConfig; +pub use stream_config::NarStreamConfig;
+ +
#[cfg(test)] #[cfg(test)]
pub mod tests; pub mod tests;
diff --git c/attic/src/nix_store/nix_store.rs i/attic/src/nix_store/nix_store.rs diff --git c/attic/src/nix_store/nix_store.rs i/attic/src/nix_store/nix_store.rs
index 3b754f9..91eb489 100644 index 3b754f9..91eb489 100644
--- c/attic/src/nix_store/nix_store.rs --- c/attic/src/nix_store/nix_store.rs
+++ i/attic/src/nix_store/nix_store.rs +++ i/attic/src/nix_store/nix_store.rs
@@ -8,6 +8,7 @@ use std::sync::Arc; @@ -8,6 +8,7 @@ use std::sync::Arc;
use tokio::task::spawn_blocking; use tokio::task::spawn_blocking;
use super::bindings::{open_nix_store, AsyncWriteAdapter, FfiNixStore}; use super::bindings::{open_nix_store, AsyncWriteAdapter, FfiNixStore};
+use super::stream_config::NarStreamConfig; +use super::stream_config::NarStreamConfig;
use super::{to_base_name, StorePath, ValidPathInfo}; use super::{to_base_name, StorePath, ValidPathInfo};
use crate::error::AtticResult; use crate::error::AtticResult;
use crate::hash::Hash; use crate::hash::Hash;
@@ -19,11 +20,18 @@ pub struct NixStore { @@ -19,11 +20,18 @@ pub struct NixStore {
/// Path to the Nix store itself. /// Path to the Nix store itself.
store_dir: PathBuf, store_dir: PathBuf,
+ +
+ /// Configuration for NAR streaming. + /// Configuration for NAR streaming.
+ stream_config: NarStreamConfig, + stream_config: NarStreamConfig,
} }
#[cfg(feature = "nix_store")] #[cfg(feature = "nix_store")]
impl NixStore { impl NixStore {
pub fn connect() -> AtticResult<Self> { pub fn connect() -> AtticResult<Self> {
@@ -140,11 +140,11 @@ index 3b754f9..91eb489 100644
+ stream_config, + stream_config,
}) })
} }
@@ -84,12 +93,26 @@ impl NixStore { @@ -84,12 +93,26 @@ impl NixStore {
self.store_dir.join(&store_path.base_name) self.store_dir.join(&store_path.base_name)
} }
- /// Creates a NAR archive from a path. - /// Creates a NAR archive from a path.
+ /// Creates a NAR archive from a path with default configuration. + /// Creates a NAR archive from a path with default configuration.
/// ///
@@ -168,7 +168,7 @@ index 3b754f9..91eb489 100644
- let (adapter, mut sender) = AsyncWriteAdapter::new(); - let (adapter, mut sender) = AsyncWriteAdapter::new();
+ let (adapter, mut sender) = AsyncWriteAdapter::new_with_config(stream_config); + let (adapter, mut sender) = AsyncWriteAdapter::new_with_config(stream_config);
let base_name = Vec::from(store_path.as_base_name_bytes()); let base_name = Vec::from(store_path.as_base_name_bytes());
spawn_blocking(move || { spawn_blocking(move || {
diff --git c/attic/src/nix_store/stream_config.rs i/attic/src/nix_store/stream_config.rs diff --git c/attic/src/nix_store/stream_config.rs i/attic/src/nix_store/stream_config.rs
new file mode 100644 new file mode 100644
+1 -1
View File
@@ -69,4 +69,4 @@
"hash": "sha256-spT7EFXLnI0FWT9Vlvp7QEP0urntmQ2C+fQB5bVLoLE=" "hash": "sha256-spT7EFXLnI0FWT9Vlvp7QEP0urntmQ2C+fQB5bVLoLE="
} }
} }
} }
+3 -4
View File
@@ -1,5 +1,4 @@
{ {
self',
pkgs, pkgs,
nixvimunstable, nixvimunstable,
... ...
@@ -18,19 +17,19 @@ let
in in
{ {
default = pkgs.mkShell { default = pkgs.mkShell {
inherit (self'.checks.pre-commit-check) shellHook;
buildInputs = with pkgs; [ buildInputs = with pkgs; [
bashInteractive bashInteractive
stdenv.cc
curl curl
git git
gnutar gnutar
gzip gzip
inject inject
inject-darwin inject-darwin
nushell
vim vim
self'.checks.pre-commit-check.enabledPackages
tmux
xonsh xonsh
zellij
]; ];
}; };
} }