From 9da8955598b7a9030e14f1b6cd4a78fe5b11afc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Thu, 23 Nov 2023 23:40:00 +0100 Subject: [PATCH 1/2] treewide: Introduce deadnix --- checks/alejandra.nix | 12 +- checks/deadnix.nix | 24 ++++ checks/default.nix | 12 +- flake.lock | 104 +++++++++++++++++- flake.nix | 1 + home-config/config/default.nix | 4 - home-config/config/desktop/default.nix | 1 - home-config/config/desktop/dunst.nix | 1 - home-config/config/options.nix | 7 +- .../config/tty-applications/default.nix | 2 - home-config/config/tty-applications/emacs.nix | 1 - home-config/default.nix | 1 - home-modules/firefox-webapp.nix | 1 - nixos-config/default.nix | 1 - nixos-config/ren/default.nix | 6 +- nixos-config/yui/nvidia.nix | 2 +- pkgs/applications/deepfilternet.nix | 2 +- pkgs/applications/emacs/default.nix | 9 +- pkgs/configuration/phosphor-icons.nix | 2 - 19 files changed, 146 insertions(+), 47 deletions(-) create mode 100644 checks/deadnix.nix diff --git a/checks/alejandra.nix b/checks/alejandra.nix index 6191e3db..f2f45117 100644 --- a/checks/alejandra.nix +++ b/checks/alejandra.nix @@ -3,8 +3,11 @@ mkTest, lib, alejandra, + generatedFiles, }: let + inherit (lib) concatStringsSep; inherit (lib.sources) sourceFilesBySuffices; + excludes = concatStringsSep " " (map (f: "--exclude ./${f}") generatedFiles); in mkTest { name = "lint-alejandra"; @@ -12,12 +15,7 @@ in 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 ''; } diff --git a/checks/deadnix.nix b/checks/deadnix.nix new file mode 100644 index 00000000..8f279d8e --- /dev/null +++ b/checks/deadnix.nix @@ -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 + ''; + } diff --git a/checks/default.nix b/checks/default.nix index 31455ac4..afdf69b0 100644 --- a/checks/default.nix +++ b/checks/default.nix @@ -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; @@ -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. @@ -27,5 +36,6 @@ in { # Linters and formatters alejandra = callPackage ./alejandra.nix {}; + deadnix = callPackage ./deadnix.nix {}; shellcheck = callPackage ./shellcheck.nix {}; } diff --git a/flake.lock b/flake.lock index 5190655c..2286ecae 100644 --- a/flake.lock +++ b/flake.lock @@ -22,6 +22,26 @@ "type": "github" } }, + "deadnix": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs", + "utils": "utils" + }, + "locked": { + "lastModified": 1698768041, + "narHash": "sha256-xaaXGzTd+t1GjD2KpiS/c8acv6bXufv/lTN+ACRGVJw=", + "owner": "astro", + "repo": "deadnix", + "rev": "efcd46e3827d1e42e8f2f9cb045dfb34caeb43f5", + "type": "github" + }, + "original": { + "owner": "astro", + "repo": "deadnix", + "type": "github" + } + }, "disko": { "inputs": { "nixpkgs": [ @@ -136,7 +156,7 @@ }, "flake-utils": { "inputs": { - "systems": "systems" + "systems": "systems_2" }, "locked": { "lastModified": 1692799911, @@ -188,6 +208,28 @@ "type": "github" } }, + "naersk": { + "inputs": { + "nixpkgs": [ + "deadnix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1698420672, + "narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=", + "owner": "nix-community", + "repo": "naersk", + "rev": "aeb58d5e8faead8980a807c840232697982d47b9", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, "nix-gaming": { "inputs": { "flake-parts": "flake-parts", @@ -295,16 +337,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1699291058, - "narHash": "sha256-5ggduoaAMPHUy4riL+OrlAZE14Kh7JWX4oLEs22ZqfU=", + "lastModified": 1700538105, + "narHash": "sha256-uZhOCmwv8VupEmPZm3erbr9XXmyg7K67Ul3+Rx2XMe0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "41de143fda10e33be0f47eab2bfe08a50f234267", + "rev": "51a01a7e5515b469886c120e38db325c96694c2f", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-23.05", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } @@ -363,6 +405,22 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1699291058, + "narHash": "sha256-5ggduoaAMPHUy4riL+OrlAZE14Kh7JWX4oLEs22ZqfU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "41de143fda10e33be0f47eab2bfe08a50f234267", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nurpkgs": { "locked": { "lastModified": 1699509948, @@ -403,6 +461,7 @@ "root": { "inputs": { "aagl": "aagl", + "deadnix": "deadnix", "disko": "disko", "fenix": "fenix", "home-manager": "home-manager", @@ -410,7 +469,7 @@ "nix-gaming": "nix-gaming", "nixos-anywhere": "nixos-anywhere", "nixos-hardware": "nixos-hardware", - "nixpkgs": "nixpkgs", + "nixpkgs": "nixpkgs_2", "nixpkgs-unfree": "nixpkgs-unfree", "nixpkgs-unstable": "nixpkgs-unstable", "nurpkgs": "nurpkgs", @@ -473,6 +532,21 @@ "type": "github" } }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "treefmt-nix": { "inputs": { "nixpkgs": [ @@ -493,6 +567,24 @@ "repo": "treefmt-nix", "type": "github" } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 98829006..a657c777 100644 --- a/flake.nix +++ b/flake.nix @@ -57,6 +57,7 @@ url = "github:berberman/nvfetcher"; inputs.nixpkgs.follows = "nixpkgs"; }; + deadnix.url = "github:astro/deadnix"; }; outputs = { diff --git a/home-config/config/default.nix b/home-config/config/default.nix index 13e51c36..b294f3f4 100644 --- a/home-config/config/default.nix +++ b/home-config/config/default.nix @@ -1,8 +1,4 @@ { - config, - lib, - ... -}: { imports = [ ./options.nix ./non-nixos.nix diff --git a/home-config/config/desktop/default.nix b/home-config/config/desktop/default.nix index c44196be..155bb7f3 100644 --- a/home-config/config/desktop/default.nix +++ b/home-config/config/desktop/default.nix @@ -1,5 +1,4 @@ { - pkgs, config, lib, ... diff --git a/home-config/config/desktop/dunst.nix b/home-config/config/desktop/dunst.nix index 6a66a4e6..59e2bff7 100644 --- a/home-config/config/desktop/dunst.nix +++ b/home-config/config/desktop/dunst.nix @@ -1,7 +1,6 @@ { config, lib, - pkgs, ... }: let screenHeight = 1080; diff --git a/home-config/config/options.nix b/home-config/config/options.nix index 35d3a8dc..0e9dd552 100644 --- a/home-config/config/options.nix +++ b/home-config/config/options.nix @@ -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"; diff --git a/home-config/config/tty-applications/default.nix b/home-config/config/tty-applications/default.nix index 2975263a..69abd385 100644 --- a/home-config/config/tty-applications/default.nix +++ b/home-config/config/tty-applications/default.nix @@ -1,8 +1,6 @@ { config, - lib, pkgs, - flake-inputs, ... }: { imports = [ diff --git a/home-config/config/tty-applications/emacs.nix b/home-config/config/tty-applications/emacs.nix index 3f072886..5a677ddd 100644 --- a/home-config/config/tty-applications/emacs.nix +++ b/home-config/config/tty-applications/emacs.nix @@ -1,5 +1,4 @@ { - config, pkgs, flake-inputs, ... diff --git a/home-config/default.nix b/home-config/default.nix index 8f21dc16..a06c0655 100644 --- a/home-config/default.nix +++ b/home-config/default.nix @@ -1,6 +1,5 @@ { lib, - pkgs, flake-inputs, ... }: { diff --git a/home-modules/firefox-webapp.nix b/home-modules/firefox-webapp.nix index 6e58e98b..f031aed4 100644 --- a/home-modules/firefox-webapp.nix +++ b/home-modules/firefox-webapp.nix @@ -1,5 +1,4 @@ { - pkgs, config, lib, ... diff --git a/nixos-config/default.nix b/nixos-config/default.nix index e588b1b0..d22c34cb 100644 --- a/nixos-config/default.nix +++ b/nixos-config/default.nix @@ -1,6 +1,5 @@ { lib, - config, pkgs, flake-inputs, ... diff --git a/nixos-config/ren/default.nix b/nixos-config/ren/default.nix index b6cf0eee..e8124959 100644 --- a/nixos-config/ren/default.nix +++ b/nixos-config/ren/default.nix @@ -1,8 +1,4 @@ -{ - lib, - flake-inputs, - ... -}: { +{flake-inputs, ...}: { imports = [ flake-inputs.impermanence.nixosModules.impermanence flake-inputs.disko.nixosModules.disko diff --git a/nixos-config/yui/nvidia.nix b/nixos-config/yui/nvidia.nix index 659ba2e2..7ef2f93a 100644 --- a/nixos-config/yui/nvidia.nix +++ b/nixos-config/yui/nvidia.nix @@ -64,7 +64,7 @@ # Downgrade to 0.5.0 because 1.2.2 doesn't currently work on nvidia # (for me) xdg.portal.extraPortals = lib.mkOverride 49 [ - (pkgs.xdg-desktop-portal-hyprland.overrideAttrs (old: { + (pkgs.xdg-desktop-portal-hyprland.overrideAttrs (_old: { version = "0.5.0"; src = pkgs.fetchFromGitHub { owner = "hyprwm"; diff --git a/pkgs/applications/deepfilternet.nix b/pkgs/applications/deepfilternet.nix index 04670962..a9de2451 100644 --- a/pkgs/applications/deepfilternet.nix +++ b/pkgs/applications/deepfilternet.nix @@ -21,7 +21,7 @@ rustc = toolchain; }; - hdf5-12 = hdf5.overrideAttrs (old: { + hdf5-12 = hdf5.overrideAttrs (_old: { version = "1.12.2"; src = fetchurl { diff --git a/pkgs/applications/emacs/default.nix b/pkgs/applications/emacs/default.nix index 1a643624..9c9451b4 100644 --- a/pkgs/applications/emacs/default.nix +++ b/pkgs/applications/emacs/default.nix @@ -6,10 +6,7 @@ emacsPackagesFor, emacsMacport, emacs, - runCommand, runCommandLocal, - fetchurl, - lzip, }: let emacsPlatform = if hostPlatform.isDarwin @@ -25,7 +22,7 @@ ''; }; - overrides = self: super: { + overrides = _self: super: { dashboard = super.dashboard.overrideAttrs (_old: { patches = [ # See https://github.com/emacs-dashboard/emacs-dashboard/issues/81 @@ -37,7 +34,7 @@ emacsPkgs = (emacsPackagesFor emacsPlatform).overrideScope' overrides; # Compute the list of use-package-d packages. - package-list = runCommand "package-list" {buildInputs = [emacsPkgs.emacs];} '' + package-list = runCommandLocal "package-list" {buildInputs = [emacsPkgs.emacs];} '' HOME=/tmp SCANNING_PACKAGES=true emacs --batch --quick \ -L ${emacsPkgs.use-package}/share/emacs/site-lisp/elpa/use-package-* \ -L ${emacsPkgs.bind-key}/share/emacs/site-lisp/elpa/bind-key-* \ @@ -54,7 +51,7 @@ emacsPkgs.emacs.pkgs.withPackages (epkgs: map (package: builtins.getAttr package epkgs) required-packages); - compiled-dotfiles = runCommand "compiled-init" {buildInputs = [custom-emacs];} '' + compiled-dotfiles = runCommandLocal "compiled-init" {buildInputs = [custom-emacs];} '' cp -r '${self}/home-config/dotfiles/emacs.d/' "$out" chmod -R u+w "$out" diff --git a/pkgs/configuration/phosphor-icons.nix b/pkgs/configuration/phosphor-icons.nix index 4dd285a5..7f481758 100644 --- a/pkgs/configuration/phosphor-icons.nix +++ b/pkgs/configuration/phosphor-icons.nix @@ -1,8 +1,6 @@ { - lib, sources, stdenv, - fetchFromGitHub, }: stdenv.mkDerivation { inherit (sources.phosphor-icons) pname version src; From ad5eb8c91eab5f050c4e9b5af1c31c7ae8c8b969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Dani=C3=ABl=20Maat?= Date: Fri, 24 Nov 2023 00:45:41 +0100 Subject: [PATCH 2/2] treewide: Introduce statix --- checks/default.nix | 1 + checks/statix.nix | 19 +++++++++++++++++++ flake.nix | 4 ++-- home-config/config/desktop/hyprland.nix | 2 +- .../graphical-applications/keepassxc.nix | 2 +- home-config/config/xdg-settings.nix | 2 +- home-modules/firefox-webapp.nix | 2 +- nixos-config/greeter/default.nix | 2 +- nixos-config/ren/disko.nix | 2 +- pkgs/applications/deepfilternet.nix | 2 +- 10 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 checks/statix.nix diff --git a/checks/default.nix b/checks/default.nix index afdf69b0..cda4f0c2 100644 --- a/checks/default.nix +++ b/checks/default.nix @@ -38,4 +38,5 @@ in { alejandra = callPackage ./alejandra.nix {}; deadnix = callPackage ./deadnix.nix {}; shellcheck = callPackage ./shellcheck.nix {}; + statix = callPackage ./statix.nix {}; } diff --git a/checks/statix.nix b/checks/statix.nix new file mode 100644 index 00000000..65ae8686 --- /dev/null +++ b/checks/statix.nix @@ -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 + ''; + } diff --git a/flake.nix b/flake.nix index a657c777..13363ec1 100644 --- a/flake.nix +++ b/flake.nix @@ -119,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 { diff --git a/home-config/config/desktop/hyprland.nix b/home-config/config/desktop/hyprland.nix index 7e990bde..3eea2ddf 100644 --- a/home-config/config/desktop/hyprland.nix +++ b/home-config/config/desktop/hyprland.nix @@ -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 diff --git a/home-config/config/graphical-applications/keepassxc.nix b/home-config/config/graphical-applications/keepassxc.nix index 9596ef3a..6807b7c4 100644 --- a/home-config/config/graphical-applications/keepassxc.nix +++ b/home-config/config/graphical-applications/keepassxc.nix @@ -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; [ diff --git a/home-config/config/xdg-settings.nix b/home-config/config/xdg-settings.nix index ed42fc0a..77d39648 100644 --- a/home-config/config/xdg-settings.nix +++ b/home-config/config/xdg-settings.nix @@ -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"] '' diff --git a/home-modules/firefox-webapp.nix b/home-modules/firefox-webapp.nix index f031aed4..e13180d9 100644 --- a/home-modules/firefox-webapp.nix +++ b/home-modules/firefox-webapp.nix @@ -11,7 +11,7 @@ make-app-profiles = cfg: mapAttrs' (name: cfg: nameValuePair "home-manager-webapp-${name}" { - id = cfg.id; + inherit (cfg) id; userChrome = '' @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); diff --git a/nixos-config/greeter/default.nix b/nixos-config/greeter/default.nix index 1f9c2d20..30321fa4 100644 --- a/nixos-config/greeter/default.nix +++ b/nixos-config/greeter/default.nix @@ -71,7 +71,7 @@ in { ''; systemd.tmpfiles.rules = let - user = config.services.greetd.settings.default_session.user; + inherit (config.services.greetd.settings.default_session) user; in [ "d /var/log/gtkgreet 0755 greeter ${user} - -" "d /var/cache/gtkgreet 0755 greeter ${user} - -" diff --git a/nixos-config/ren/disko.nix b/nixos-config/ren/disko.nix index eb99ba9e..0faec2bf 100644 --- a/nixos-config/ren/disko.nix +++ b/nixos-config/ren/disko.nix @@ -1,4 +1,4 @@ -{...}: let +_: let disks = [ "/dev/sda" ]; diff --git a/pkgs/applications/deepfilternet.nix b/pkgs/applications/deepfilternet.nix index a9de2451..b8b1dd93 100644 --- a/pkgs/applications/deepfilternet.nix +++ b/pkgs/applications/deepfilternet.nix @@ -14,7 +14,7 @@ # Need to use unstable rust platform until this is resolved: # https://github.com/rust-lang/rust/issues/63292 rustPlatform = let - toolchain = flake-inputs.fenix.packages.${system}.minimal.toolchain; + inherit (flake-inputs.fenix.packages.${system}.minimal) toolchain; in makeRustPlatform { cargo = toolchain;