Merge branch 'checks' into 'main'

chore: set up pre-commit checks

See merge request kernald/reddit-magnet!29
This commit is contained in:
Marc Plano-Lesay 2025-05-04 12:29:06 +00:00
commit ed13d54ba1
5 changed files with 176 additions and 43 deletions

5
.gitignore vendored
View file

@ -2,7 +2,4 @@
.idea/ .idea/
/target /target
.rust-toolchain .rust-toolchain
*.act .pre-commit-config.yaml
*.bmp
*.jpg
*.png

View file

@ -18,6 +18,28 @@ tests:
- cargo fmt --check - cargo fmt --check
- cargo test - cargo test
flake-check:
stage: test
image: nixpkgs/nix-flakes:nixos-24.11-x86_64-linux
before_script:
- mkdir -p ~/.ssh
- eval $(ssh-agent -s)
- chmod 400 "$NIX_SSH_PRIVATE_KEY"
- ssh-add "$NIX_SSH_PRIVATE_KEY"
- cp "$SSH_KNOWN_HOSTS" ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- echo "substituters = ssh://nix-ssh@build.enoent.fr?priority=10 https://cache.nixos.org?priority=40 https://cuda-maintainers.cachix.org https://nix-community.cachix.org https://statix.cachix.org https://pre-commit-hooks.cachix.org" >> /etc/nix/nix.conf
- echo "trusted-substituters = ssh://nix-ssh@build.enoent.fr" >> /etc/nix/nix.conf
- echo "trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs= statix.cachix.org-1:Z9E/g1YjCjU117QOOt07OjhljCoRZddiAm4VVESvais= pre-commit-hooks.cachix.org-1:Pkk3Panw5AW24TOv6kz3PvLhlH8puAsJTBbOPmBo7Rc=" >> /etc/nix/nix.conf
- echo "extra-trusted-public-keys = galatea-0:E7F1FzfoY+X9l9Xn9AvNWDkW1U7H644FHDzX3lpxHkI=" >> /etc/nix/nix.conf
- echo "builders-use-substitutes = true" >> /etc/nix/nix.conf
- echo "max-jobs = 0" >> /etc/nix/nix.conf
- echo "ssh://nix-ssh@build.enoent.fr x86_64-linux" >> /etc/nix/machines
- echo "ssh://nix-ssh@build.enoent.fr aarch64-linux" >> /etc/nix/machines
- nix store info --store ssh://nix-ssh@build.enoent.fr
script:
- nix flake check
build:amd64: build:amd64:
stage: build stage: build
image: rust image: rust

62
flake.lock generated
View file

@ -1,5 +1,21 @@
{ {
"nodes": { "nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems"
@ -18,6 +34,27 @@
"type": "github" "type": "github"
} }
}, },
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1744932701, "lastModified": 1744932701,
@ -34,10 +71,33 @@
"type": "github" "type": "github"
} }
}, },
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1742649964,
"narHash": "sha256-DwOTp7nvfi8mRfuL1escHDXabVXFGT1VlPD1JHrtrco=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "dcf5072734cb576d2b0c59b2ac44f5050b5eac82",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
} }
}, },
"systems": { "systems": {

View file

@ -2,13 +2,18 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = outputs =
{ nixpkgs { self
, nixpkgs
, flake-utils , flake-utils
, ... , ...
}: }@inputs:
flake-utils.lib.eachDefaultSystem (system: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = import nixpkgs { pkgs = import nixpkgs {
@ -28,7 +33,50 @@
}; };
in in
{ {
devShells.default = pkgs.mkShell { checks = {
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
# TOML
check-toml.enable = true;
# Nix
deadnix.enable = true;
flake-checker.enable = true;
nixpkgs-fmt.enable = true;
statix.enable = true;
# Rust
clippy = {
enable = true;
settings = {
denyWarnings = true;
};
extraPackages = with pkgs; [
openssl
pkg-config
];
};
# Git
no-commit-to-branch = {
enable = true;
settings = {
branch = [ "main" ];
};
};
};
settings = {
rust.check.cargoDeps = pkgs.rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
};
};
};
devShells = {
default = pkgs.mkShell {
name = "reddit-magnet"; name = "reddit-magnet";
buildInputs = with pkgs; [ buildInputs = with pkgs; [
cargo cargo
@ -42,11 +90,12 @@
pkg-config pkg-config
rustc rustc
rust-toolchain rust-toolchain
sqlfluff
sqlite sqlite
] ++ lib.optionals stdenv.isDarwin [ ] ++ lib.optionals stdenv.isDarwin [
libiconv libiconv
darwin.apple_sdk.frameworks.SystemConfiguration darwin.apple_sdk.frameworks.SystemConfiguration
]; ] ++ self.checks.${system}.pre-commit-check.enabledPackages;
RUST_BACKTRACE = 1; RUST_BACKTRACE = 1;
# Copy rust-toolchain to project directory for easy use in IntelliJ # Copy rust-toolchain to project directory for easy use in IntelliJ
@ -58,7 +107,12 @@
ln -s ${rust-toolchain} ./.rust-toolchain ln -s ${rust-toolchain} ./.rust-toolchain
echo "Rust toolchain symlink updated." echo "Rust toolchain symlink updated."
fi fi
${self.checks.${system}.pre-commit-check.shellHook}
''; '';
}; };
};
formatter = pkgs.nixpkgs-fmt;
}); });
} }