Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treewide: Add more static checks #297

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions checks/alejandra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
mkTest,
lib,
alejandra,
generatedFiles,
}: let
inherit (lib) concatStringsSep;
inherit (lib.sources) sourceFilesBySuffices;
excludes = concatStringsSep " " (map (f: "--exclude ./${f}") generatedFiles);
in
mkTest {
name = "lint-alejandra";
src = sourceFilesBySuffices self [".nix"];
checkInputs = [alejandra];
checkPhase = ''
mkdir -p $out
alejandra --check \
--exclude ./home-config/dotfiles/emacs.d/share/templates/ \
--exclude ./pkgs/_sources/ \
--exclude ./nixos-config/yui/hardware-configuration.nix \
--exclude ./nixos-config/ren/hardware-configuration.nix \
. \
| tee $out/test.log
echo alejandra --check ${excludes} . | tee $out/test.log
alejandra --check ${excludes} . | tee $out/test.log
'';
}
24 changes: 24 additions & 0 deletions checks/deadnix.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
pkgs,
self,
mkTest,
lib,
flake-inputs,
generatedFiles,
}: let
inherit (lib) concatStringsSep;
inherit (lib.sources) sourceFilesBySuffices;

deadnix = flake-inputs.deadnix.packages.${pkgs.system}.default;

excludes = "--exclude ${concatStringsSep " " (map (f: "./${f}") generatedFiles)}";
in
mkTest {
name = "lint-deadnix";
src = sourceFilesBySuffices self [".nix"];
checkInputs = [deadnix];
checkPhase = ''
mkdir -p $out
deadnix --fail ${excludes} | tee $out/test.log
'';
}
13 changes: 12 additions & 1 deletion checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
flake-inputs,
}: let
inherit (lib) callPackageWith;

generatedFiles = [
"home-config/dotfiles/emacs.d/share/templates"
"pkgs/_sources"
"nixos-config/yui/hardware-configuration.nix"
"nixos-config/ren/hardware-configuration.nix"
];

mkTest = test:
pkgs.stdenv.mkDerivation ({
dontPatch = true;
Expand All @@ -13,9 +21,10 @@
doCheck = true;
}
// test);

callPackage = callPackageWith (pkgs
// {
inherit flake-inputs mkTest;
inherit flake-inputs mkTest generatedFiles;
# Work around `self` technically being a store path when
# evaluated as a flake - `builtins.filter` can otherwise not be
# called on it.
Expand All @@ -27,5 +36,7 @@
in {
# Linters and formatters
alejandra = callPackage ./alejandra.nix {};
deadnix = callPackage ./deadnix.nix {};
shellcheck = callPackage ./shellcheck.nix {};
statix = callPackage ./statix.nix {};
}
19 changes: 19 additions & 0 deletions checks/statix.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
self,
lib,
mkTest,
statix,
generatedFiles,
}: let
inherit (lib) concatStringsSep sourceFilesBySuffices;
excludes = "--ignore ${concatStringsSep " " generatedFiles}";
in
mkTest {
name = "lint-statix";
src = sourceFilesBySuffices self [".nix"];
checkInputs = [statix];
checkPhase = ''
mkdir -p $out
statix check ${excludes} | tee $out/test.log
'';
}
104 changes: 98 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
url = "github:berberman/nvfetcher";
inputs.nixpkgs.follows = "nixpkgs";
};
deadnix.url = "github:astro/deadnix";
};

outputs = {
Expand Down Expand Up @@ -118,14 +119,14 @@
};

checks.x86_64-linux = import ./checks {
inherit (nixpkgs) lib;
pkgs = nixpkgs.legacyPackages.x86_64-linux;
lib = nixpkgs.lib;
flake-inputs = inputs;
};

devShells.x86_64-linux.default = let
inherit (sops-nix.packages.x86_64-linux) sops-init-gpg-key sops-import-keys-hook;
commit-nvfetcher = self.packages.x86_64-linux.commit-nvfetcher;
inherit (self.packages.x86_64-linux) commit-nvfetcher;
home-manager-bin = home-manager.packages.x86_64-linux.default;
in
nixpkgs.legacyPackages.x86_64-linux.mkShell {
Expand Down
4 changes: 0 additions & 4 deletions home-config/config/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
config,
lib,
...
}: {
imports = [
./options.nix
./non-nixos.nix
Expand Down
1 change: 0 additions & 1 deletion home-config/config/desktop/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
pkgs,
config,
lib,
...
Expand Down
1 change: 0 additions & 1 deletion home-config/config/desktop/dunst.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
config,
lib,
pkgs,
...
}: let
screenHeight = 1080;
Expand Down
2 changes: 1 addition & 1 deletion home-config/config/desktop/hyprland.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ in {
xdg.configFile."hypr/hyprland.conf" = {
source = ../../dotfiles/hyprland.conf;
onChange = let
hyprland = flake-inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.hyprland;
inherit (flake-inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}) hyprland;
in ''
( # execute in subshell so that `shopt` won't affect other scripts
shopt -s nullglob # so that nothing is done if /tmp/hypr/ does not exist or is empty
Expand Down
2 changes: 1 addition & 1 deletion home-config/config/graphical-applications/keepassxc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
flake-inputs,
...
}: let
nextcloudcmd = flake-inputs.self.packages.${pkgs.system}.nextcloudcmd;
inherit (flake-inputs.self.packages.${pkgs.system}) nextcloudcmd;
in {
config = lib.mkIf config.custom.graphical-applications {
home.packages = with pkgs; [
Expand Down
7 changes: 1 addition & 6 deletions home-config/config/options.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
config,
lib,
...
}: let
{lib, ...}: let
inherit (lib) mkEnableOption;
cfg = config.custom;
in {
options.custom = {
desktop-environment = mkEnableOption "Set up a stumpwm-based desktop environment";
Expand Down
2 changes: 0 additions & 2 deletions home-config/config/tty-applications/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
config,
lib,
pkgs,
flake-inputs,
...
}: {
imports = [
Expand Down
1 change: 0 additions & 1 deletion home-config/config/tty-applications/emacs.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
config,
pkgs,
flake-inputs,
...
Expand Down
2 changes: 1 addition & 1 deletion home-config/config/xdg-settings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}: let
inherit (pkgs) writeText;
inherit (lib.strings) concatStringsSep;
xdg = config.xdg;
inherit (config) xdg;
in {
home.activation = {
xdg-dir-prep = lib.hm.dag.entryAfter ["writeBoundary"] ''
Expand Down
1 change: 0 additions & 1 deletion home-config/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
lib,
pkgs,
flake-inputs,
...
}: {
Expand Down
Loading