From 80e8e1e2f613bdc8749461899f0959312eb4a54e Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Sun, 16 Jun 2024 15:08:25 +0100 Subject: [PATCH] treewide: add linters and apply pending suggestions (#426) --- .github/workflows/lint.yml | 42 +++++++++++++++++++++++++++++++++++ modules/alacritty/hm.nix | 2 +- modules/bat/hm.nix | 2 +- modules/bemenu/hm.nix | 4 ++-- modules/dunst/hm.nix | 2 +- modules/fish/hm.nix | 4 ++-- modules/fish/nixos.nix | 4 ++-- modules/fish/prompt.nix | 2 +- modules/foot/hm.nix | 2 +- modules/fuzzel/hm.nix | 2 +- modules/fzf/hm.nix | 2 +- modules/gedit/hm.nix | 2 +- modules/gnome/hm.nix | 6 +++-- modules/gnome/nixos.nix | 6 +++-- modules/gnome/theme.nix | 14 ++++++------ modules/gtk/nixos.nix | 2 +- modules/i3/hm.nix | 2 +- modules/kitty/hm.nix | 2 +- modules/mako/hm.nix | 4 ++-- modules/mangohud/hm.nix | 5 ++--- modules/nixos-icons/nixos.nix | 2 +- modules/nixvim/nixvim.nix | 23 ++++--------------- modules/qutebrowser/hm.nix | 2 +- modules/sxiv/hm.nix | 4 ++-- modules/tmux/hm.nix | 2 +- modules/tofi/hm.nix | 2 +- modules/vim/hm.nix | 2 +- modules/xfce/hm.nix | 2 +- modules/zellij/hm.nix | 2 +- stylix/autoload.nix | 2 +- stylix/cursor.nix | 2 +- stylix/fonts.nix | 2 +- stylix/hm/cursor.nix | 4 +--- stylix/hm/default.nix | 2 +- stylix/nixos/fonts.nix | 2 +- 35 files changed, 97 insertions(+), 69 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..1a965610 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,42 @@ +name: Lint + +on: pull_request + +permissions: + contents: read + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + extra-conf: | + extra-experimental-features = nix-command flakes + + - name: Set up cache + uses: DeterminateSystems/magic-nix-cache-action@main + + - name: Install tools + run: | + flake='github:nixos/nixpkgs/e913ae340076bbb73d9f4d3d065c2bca7caafb16' + nix profile install "${flake}#statix" + nix profile install "${flake}#deadnix" + nix profile install "${flake}#jq" + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run statix + run: | + statix check --format json |\ + jq --raw-output '.file as $file | .report[] | .severity as $severity | .diagnostics[] | "::warning file=\($file),line=\(.at.from.line),col=\(.at.from.column)::\(.message)"' + + - name: Run deadnix + run: | + deadnix --no-lambda-arg --output-format json |\ + jq --raw-output '.file as $file | .results[] | "::warning file=\($file),line=\(.line),col=\(.column)::\(.message)"' diff --git a/modules/alacritty/hm.nix b/modules/alacritty/hm.nix index e8d45b17..e9974f31 100644 --- a/modules/alacritty/hm.nix +++ b/modules/alacritty/hm.nix @@ -43,7 +43,7 @@ in white = base07; red = bright-red; green = bright-green; - yellow = yellow; + inherit yellow; blue = bright-blue; magenta = bright-magenta; cyan = bright-cyan; diff --git a/modules/bat/hm.nix b/modules/bat/hm.nix index c3e54be7..e38751e6 100644 --- a/modules/bat/hm.nix +++ b/modules/bat/hm.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... }: +{ config, lib, ... }: { options.stylix.targets.bat.enable = diff --git a/modules/bemenu/hm.nix b/modules/bemenu/hm.nix index 6806d27f..e629e4db 100644 --- a/modules/bemenu/hm.nix +++ b/modules/bemenu/hm.nix @@ -1,9 +1,9 @@ -{pkgs, config, lib, ... }: +{ config, lib, ... }: with config.lib.stylix.colors.withHashtag; with config.stylix.fonts; let - bemenuOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100)); + bemenuOpacity = lib.toHexString (((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100); in { options.stylix.targets.bemenu = { enable = config.lib.stylix.mkEnableTarget "bemenu" true; diff --git a/modules/dunst/hm.nix b/modules/dunst/hm.nix index 46b234ea..7c4ad0ba 100644 --- a/modules/dunst/hm.nix +++ b/modules/dunst/hm.nix @@ -3,7 +3,7 @@ with config.lib.stylix.colors.withHashtag; with config.stylix.fonts; let - dunstOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100)); + dunstOpacity = lib.toHexString (((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100); in { options.stylix.targets.dunst.enable = config.lib.stylix.mkEnableTarget "Dunst" true; diff --git a/modules/fish/hm.nix b/modules/fish/hm.nix index 4d54cc54..4493aecc 100644 --- a/modules/fish/hm.nix +++ b/modules/fish/hm.nix @@ -1,10 +1,10 @@ -{ pkgs, config, lib, ... }: +{ config, lib, ... }: { options.stylix.targets.fish.enable = config.lib.stylix.mkEnableTarget "Fish" true; config = lib.mkIf (config.stylix.enable && config.stylix.targets.fish.enable) { - programs.fish.interactiveShellInit = import ./prompt.nix { inherit pkgs config; }; + programs.fish.interactiveShellInit = import ./prompt.nix config; }; } diff --git a/modules/fish/nixos.nix b/modules/fish/nixos.nix index 4e84ad80..2fa26dd9 100644 --- a/modules/fish/nixos.nix +++ b/modules/fish/nixos.nix @@ -1,10 +1,10 @@ -{ pkgs, config, lib, ... }: +{ config, lib, ... }: { options.stylix.targets.fish.enable = config.lib.stylix.mkEnableTarget "Fish" true; config = lib.mkIf (config.stylix.enable && config.stylix.targets.fish.enable) { - programs.fish.promptInit = import ./prompt.nix { inherit pkgs config; }; + programs.fish.promptInit = import ./prompt.nix config; }; } diff --git a/modules/fish/prompt.nix b/modules/fish/prompt.nix index f6b4e2e0..dccce63e 100644 --- a/modules/fish/prompt.nix +++ b/modules/fish/prompt.nix @@ -1,4 +1,4 @@ -{ pkgs, config }: +config: let theme = config.lib.stylix.colors { diff --git a/modules/foot/hm.nix b/modules/foot/hm.nix index 8a4865f4..d9e191de 100644 --- a/modules/foot/hm.nix +++ b/modules/foot/hm.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... }: +{ config, lib, ... }: let cfg = config.stylix.targets.foot; diff --git a/modules/fuzzel/hm.nix b/modules/fuzzel/hm.nix index 20c57ed2..62ce2d6b 100644 --- a/modules/fuzzel/hm.nix +++ b/modules/fuzzel/hm.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... }: +{ config, lib, ... }: with config.lib.stylix.colors; diff --git a/modules/fzf/hm.nix b/modules/fzf/hm.nix index 67604f9b..586f9ded 100644 --- a/modules/fzf/hm.nix +++ b/modules/fzf/hm.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... }: +{ config, lib, ... }: let mkFzfKeyValue = lib.generators.mkKeyValueDefault { } ":"; diff --git a/modules/gedit/hm.nix b/modules/gedit/hm.nix index d548ec73..4f974d5b 100644 --- a/modules/gedit/hm.nix +++ b/modules/gedit/hm.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... }: +{ config, lib, ... }: let style = config.lib.stylix.colors { diff --git a/modules/gnome/hm.nix b/modules/gnome/hm.nix index ca9b1580..ea98eccc 100644 --- a/modules/gnome/hm.nix +++ b/modules/gnome/hm.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... }@args: +{ pkgs, config, lib, ... }: let inherit (config.stylix.fonts) sansSerif serif monospace; @@ -39,7 +39,9 @@ in { xdg.dataFile."themes/Stylix/gnome-shell/gnome-shell.css" = { source = - let theme = import ./theme.nix args; + let theme = pkgs.callPackage ./theme.nix { + inherit (config.lib.stylix) colors templates; + }; in "${theme}/share/gnome-shell/gnome-shell.css"; onChange = '' if [[ -x "$(command -v gnome-extensions)" ]]; then diff --git a/modules/gnome/nixos.nix b/modules/gnome/nixos.nix index 472fb3be..5960395e 100644 --- a/modules/gnome/nixos.nix +++ b/modules/gnome/nixos.nix @@ -1,7 +1,9 @@ -{ lib, pkgs, config, ... }@args: +{ lib, pkgs, config, ... }: let - theme = import ./theme.nix args; + theme = pkgs.callPackage ./theme.nix { + inherit (config.lib.stylix) colors templates; + }; in { options.stylix.targets.gnome.enable = diff --git a/modules/gnome/theme.nix b/modules/gnome/theme.nix index bf8023e0..6a6ea7c9 100644 --- a/modules/gnome/theme.nix +++ b/modules/gnome/theme.nix @@ -1,21 +1,21 @@ -{ config, pkgs, ... }: +{ stdenv, sass, glib, colors, templates }: let - colors = config.lib.stylix.colors { + colorsScss = colors { template = ./colors.mustache; extension = "scss"; }; -in pkgs.stdenv.mkDerivation { - name = "${config.lib.stylix.colors.slug}-gnome-shell-theme"; - src = config.lib.stylix.templates.gnome-shell; +in stdenv.mkDerivation { + name = "${colors.slug}-gnome-shell-theme"; + src = templates.gnome-shell; patches = [ ./shell_colors.patch ]; postPatch = '' rm data/theme/gnome-shell-sass/{_colors.scss,_default-colors.scss,_palette.scss} - cp ${colors} data/theme/gnome-shell-sass/_colors.scss + cp ${colorsScss} data/theme/gnome-shell-sass/_colors.scss ''; - nativeBuildInputs = with pkgs; [ sass glib.dev ]; + nativeBuildInputs = [ sass glib.dev ]; buildPhase = '' sass data/theme/gnome-shell-light.scss \ >data/theme/gnome-shell-light.css diff --git a/modules/gtk/nixos.nix b/modules/gtk/nixos.nix index 953ebee6..3368857a 100644 --- a/modules/gtk/nixos.nix +++ b/modules/gtk/nixos.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... }: +{ config, lib, ... }: { options.stylix.targets.gtk.enable = diff --git a/modules/i3/hm.nix b/modules/i3/hm.nix index fffe30f6..6004e1cc 100644 --- a/modules/i3/hm.nix +++ b/modules/i3/hm.nix @@ -9,7 +9,7 @@ let unfocused = base03; fonts = let - fonts = config.stylix.fonts; + inherit (config.stylix) fonts; in { names = [ fonts.sansSerif.name ]; size = fonts.sizes.desktop * 1.0; diff --git a/modules/kitty/hm.nix b/modules/kitty/hm.nix index b4fc514e..5c82e8d3 100644 --- a/modules/kitty/hm.nix +++ b/modules/kitty/hm.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, ... }: let cfg = config.stylix.targets.kitty; diff --git a/modules/mako/hm.nix b/modules/mako/hm.nix index 89b7c39d..b999b8d3 100644 --- a/modules/mako/hm.nix +++ b/modules/mako/hm.nix @@ -1,9 +1,9 @@ -{pkgs, config, lib, options, ... }: +{ config, lib, options, ... }: with config.lib.stylix.colors.withHashtag; with config.stylix.fonts; let - makoOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100)); + makoOpacity = lib.toHexString (((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100); in { options.stylix.targets.mako.enable = config.lib.stylix.mkEnableTarget "Mako" true; diff --git a/modules/mangohud/hm.nix b/modules/mangohud/hm.nix index e3373c14..d13deedf 100644 --- a/modules/mangohud/hm.nix +++ b/modules/mangohud/hm.nix @@ -1,9 +1,8 @@ { config, lib, ... }: let - fonts = config.stylix.fonts; - colors = config.lib.stylix.colors; - opacity = config.stylix.opacity; + inherit (config.stylix) fonts opacity; + inherit (config.lib.stylix) colors; in { options.stylix.targets.mangohud.enable = config.lib.stylix.mkEnableTarget "mangohud" true; diff --git a/modules/nixos-icons/nixos.nix b/modules/nixos-icons/nixos.nix index 4e151f6c..75074d09 100644 --- a/modules/nixos-icons/nixos.nix +++ b/modules/nixos-icons/nixos.nix @@ -9,7 +9,7 @@ with config.lib.stylix.colors; config.nixpkgs.overlays = lib.mkIf (config.stylix.enable && config.stylix.targets.nixos-icons.enable) [(self: super: { nixos-icons = super.nixos-icons.overrideAttrs (oldAttrs: { src = pkgs.applyPatches { - src = oldAttrs.src; + inherit (oldAttrs) src; prePatch = '' substituteInPlace logo/nix-snowflake-white.svg --replace-fail '#ffffff' '#${base05}' diff --git a/modules/nixvim/nixvim.nix b/modules/nixvim/nixvim.nix index e6ee0436..050e7f85 100644 --- a/modules/nixvim/nixvim.nix +++ b/modules/nixvim/nixvim.nix @@ -17,25 +17,10 @@ lib.optionalAttrs (builtins.hasAttr "nixvim" options.programs) { programs.nixvim = { colorschemes.base16 = { - colorscheme = let - colors = config.lib.stylix.colors.withHashtag; - in { - base00 = colors.base00; - base01 = colors.base01; - base02 = colors.base02; - base03 = colors.base03; - base04 = colors.base04; - base05 = colors.base05; - base06 = colors.base06; - base07 = colors.base07; - base08 = colors.base08; - base09 = colors.base09; - base0A = colors.base0A; - base0B = colors.base0B; - base0C = colors.base0C; - base0D = colors.base0D; - base0E = colors.base0E; - base0F = colors.base0F; + colorscheme = { + inherit (config.lib.stylix.colors.withHashtag) + base00 base01 base02 base03 base04 base05 base06 base07 + base08 base09 base0A base0B base0C base0D base0E base0F; }; enable = true; diff --git a/modules/qutebrowser/hm.nix b/modules/qutebrowser/hm.nix index b15751c0..033ad4b7 100644 --- a/modules/qutebrowser/hm.nix +++ b/modules/qutebrowser/hm.nix @@ -199,7 +199,7 @@ in { }; indicator = { - error = error; + inherit error; start = secondary-info; stop = info; }; diff --git a/modules/sxiv/hm.nix b/modules/sxiv/hm.nix index ba452260..a1695030 100644 --- a/modules/sxiv/hm.nix +++ b/modules/sxiv/hm.nix @@ -1,8 +1,8 @@ { config, lib, ... }: let - colors = config.lib.stylix.colors; - fonts = config.stylix.fonts; + inherit (config.lib.stylix) colors; + inherit (config.stylix) fonts; in { options.stylix.targets.sxiv.enable = config.lib.stylix.mkEnableTarget "Sxiv" true; diff --git a/modules/tmux/hm.nix b/modules/tmux/hm.nix index 2c886e79..16d839c8 100644 --- a/modules/tmux/hm.nix +++ b/modules/tmux/hm.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... }: +{ config, lib, ... }: let theme = config.lib.stylix.colors { diff --git a/modules/tofi/hm.nix b/modules/tofi/hm.nix index 925199ed..ce7e4f67 100644 --- a/modules/tofi/hm.nix +++ b/modules/tofi/hm.nix @@ -10,7 +10,7 @@ with config.lib.stylix.colors.withHashtag; { config = lib.mkIf (config.stylix.enable && config.stylix.targets.tofi.enable) { programs.tofi.settings = let - opacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100)); + opacity = lib.toHexString (((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100); background = base00 + opacity; foreground = base05; darkForeground = base04 + opacity; diff --git a/modules/vim/hm.nix b/modules/vim/hm.nix index a6d9cfa0..8af789a3 100644 --- a/modules/vim/hm.nix +++ b/modules/vim/hm.nix @@ -18,7 +18,7 @@ let }; vimOptions = let - fonts = config.stylix.fonts; + inherit (config.stylix) fonts; in { plugins = [ themePlugin ]; extraConfig = with config.lib.stylix.colors.withHashtag; '' diff --git a/modules/xfce/hm.nix b/modules/xfce/hm.nix index 75a78782..4c8a4389 100644 --- a/modules/xfce/hm.nix +++ b/modules/xfce/hm.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... }@args: +{ config, lib, ... }: { # Disabled by default due to https://github.com/danth/stylix/issues/180 diff --git a/modules/zellij/hm.nix b/modules/zellij/hm.nix index 4a555e0d..e6ed23dc 100644 --- a/modules/zellij/hm.nix +++ b/modules/zellij/hm.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... }: +{ config, lib, ... }: { options.stylix.targets.zellij.enable = diff --git a/stylix/autoload.nix b/stylix/autoload.nix index 1b7f373c..bfb2fe68 100644 --- a/stylix/autoload.nix +++ b/stylix/autoload.nix @@ -9,6 +9,6 @@ for: if kind == "directory" then let file = "${../modules}/${path}/${for}.nix"; - in (if builtins.pathExists file then [ file ] else [ ]) + in if builtins.pathExists file then [ file ] else [ ] else [ ]) (builtins.readDir ../modules)) diff --git a/stylix/cursor.nix b/stylix/cursor.nix index fa2cfee3..fadbd367 100644 --- a/stylix/cursor.nix +++ b/stylix/cursor.nix @@ -1,4 +1,4 @@ -{ pkgs, lib, ... } @ args: +{ pkgs, lib, ... }: { options.stylix.cursor = { diff --git a/stylix/fonts.nix b/stylix/fonts.nix index 02d5f524..07e10c54 100644 --- a/stylix/fonts.nix +++ b/stylix/fonts.nix @@ -1,4 +1,4 @@ -{ pkgs, config, lib, ... } @ args: +{ pkgs, config, lib, ... }: let cfg = config.stylix.fonts; diff --git a/stylix/hm/cursor.nix b/stylix/hm/cursor.nix index f03b4e3c..dd279471 100644 --- a/stylix/hm/cursor.nix +++ b/stylix/hm/cursor.nix @@ -8,9 +8,7 @@ in { config = lib.mkIf (config.stylix.enable && pkgs.stdenv.hostPlatform.isLinux) { home.pointerCursor = { - name = cfg.name; - package = cfg.package; - size = cfg.size; + inherit (cfg) name package size; x11.enable = true; gtk.enable = true; }; diff --git a/stylix/hm/default.nix b/stylix/hm/default.nix index c27dec24..a5cae177 100644 --- a/stylix/hm/default.nix +++ b/stylix/hm/default.nix @@ -1,6 +1,6 @@ inputs: { palette-generator, base16 }: -{ config, lib, ... }: +{ lib, ... }: let autoload = import ../autoload.nix { inherit lib; } "hm"; diff --git a/stylix/nixos/fonts.nix b/stylix/nixos/fonts.nix index 0845ec0e..495c842c 100644 --- a/stylix/nixos/fonts.nix +++ b/stylix/nixos/fonts.nix @@ -5,7 +5,7 @@ let in { imports = [ ../fonts.nix ]; config.fonts = lib.mkIf config.stylix.enable { - packages = cfg.packages; + inherit (cfg) packages; fontconfig.defaultFonts = { monospace = [ cfg.monospace.name ];