All Projects → astro → deadnix

astro / deadnix

Licence: GPL-3.0 license
Scan Nix files for dead code

Programming Languages

rust
11053 projects
Nix
1067 projects

Projects that are alternatives of or similar to deadnix

digga
A flake utility library to craft shell-, home-, and hosts- environments.
Stars: ✭ 818 (+576.03%)
Mutual labels:  nix, nixos, nix-flake
nyx
⚙️Nix[OS] Configuration
Stars: ✭ 50 (-58.68%)
Mutual labels:  nix, nixos, nix-flake
dotfiles
🏠
Stars: ✭ 53 (-56.2%)
Mutual labels:  nix, nixos, nix-flake
flake-utils-plus
Use Nix flakes without any fluff.
Stars: ✭ 280 (+131.4%)
Mutual labels:  nix, nixos, nix-flake
base16.nix
Quickly theme programs in your favourite base16 colorscheme
Stars: ✭ 61 (-49.59%)
Mutual labels:  nix, nixos, nix-flake
microvm.nix
NixOS MicroVMs
Stars: ✭ 136 (+12.4%)
Mutual labels:  nix, nixos, nix-flake
dotfiles
Dotfiles
Stars: ✭ 25 (-79.34%)
Mutual labels:  nix, nixos, nix-flake
nixdots
I have no idea what the hell I'm doing
Stars: ✭ 46 (-61.98%)
Mutual labels:  nix, nixos, nix-flake
nix-config
A collection of my system configs and dotfiles
Stars: ✭ 35 (-71.07%)
Mutual labels:  nix, nixos, nix-flake
nix-configs
My Nix{OS} configuration files
Stars: ✭ 54 (-55.37%)
Mutual labels:  nix, nixos, nix-flake
dotnix
nix stuff
Stars: ✭ 27 (-77.69%)
Mutual labels:  nix, nixos, nix-flake
system
The system configuration of a professional yak shaver
Stars: ✭ 42 (-65.29%)
Mutual labels:  nix, nixos, nix-flake
nix2container
An archive-less dockerTools.buildImage implementation
Stars: ✭ 133 (+9.92%)
Mutual labels:  nix, nixos
nixops-tutorial
Tutorial for practical deployments with NixOps
Stars: ✭ 93 (-23.14%)
Mutual labels:  nix, nixos
config
My NixOS configurations
Stars: ✭ 17 (-85.95%)
Mutual labels:  nixos, nix-flake
nix-tutorials
Tutorials for Nix and Nixpkgs. Note so far it is a proof of concept.
Stars: ✭ 23 (-80.99%)
Mutual labels:  nix, nixos
yants
Yet Another Nix Type System | Source has moved to https://git.tazj.in/tree/nix/yants
Stars: ✭ 35 (-71.07%)
Mutual labels:  nix, nixos
nixpkgs
Nix Packages collection used in Nubank
Stars: ✭ 24 (-80.17%)
Mutual labels:  nix, nixos
nix-config
My personal nix config
Stars: ✭ 32 (-73.55%)
Mutual labels:  nix, nixos
nix-rice
A library to functionally define your configuration and theme (rice) with Nix
Stars: ✭ 43 (-64.46%)
Mutual labels:  nix, nixos

deadnix

Scan .nix files for dead code (unused variable bindings).

Usage with Github Actions

See deadnix-action

Usage with Nix Flakes

Help

$ nix run github:astro/deadnix -- --help
USAGE:
    deadnix [OPTIONS] [FILE_PATHS]...

ARGS:
    <FILE_PATHS>...    .nix files, or directories with .nix files inside [default: .]

OPTIONS:
    -_, --no-underscore
            Don't check any bindings that start with a _

    -e, --edit
            Remove unused code and write to source file

    -f, --fail
            Exit with 1 if unused code has been found

    -h, --hidden
            Recurse into hidden subdirectories and process hidden .*.nix files

        --help
            Print help information

    -l, --no-lambda-arg
            Don't check lambda parameter arguments

    -L, --no-lambda-pattern-names
            Don't check lambda attrset pattern names (don't break nixpkgs callPackage)

    -o, --output-format <OUTPUT_FORMAT>
            Output format to use [default: human-readable] [possible values: human-readable, json]

    -q, --quiet
            Don't print dead code report

    -V, --version
            Print version information

Reports contain ANSI color escape codes unless the $NO_COLOR environment variable is set.

Scan for unused code

$ nix run github:astro/deadnix test.nix
Warning: Unused declarations were found.
    ╭─[example.nix:1:1]
    │
  1 │ unusedArgs@{ unusedArg, usedArg, ... }:
    · ─────┬────   ────┬────
    ·      │           ╰────── Unused lambda pattern: unusedArg
    ·      │
    ·      ╰────────────────── Unused lambda pattern: unusedArgs
  3 │   inherit (builtins) unused_inherit;
    ·                      ───────┬──────
    ·                             ╰──────── Unused let binding: unused_inherit
  5 │   unused = "fnord";
    ·   ───┬──
    ·      ╰──── Unused let binding: unused
 10 │   shadowed = 42;
    ·   ────┬───
    ·       ╰───── Unused let binding: shadowed
 11 │   _unused = unused: false;
    ·   ───┬───   ───┬──
    ·      │         ╰──── Unused lambda argument: unused
    ·      │
    ·      ╰────────────── Unused let binding: _unused
 13 │   x = { unusedArg2, x ? args.y, ... }@args: used1 + x;
    ·         ─────┬────
    ·              ╰────── Unused lambda pattern: unusedArg2
────╯

Remove unused code automatically

Do commit your changes into version control before!

$ nix run github:astro/deadnix -- -eq test.nix

Behavior

Renaming of all unused to lambda args to start with _

If you disfavor marking them as unused, use option --no-lambda-arg.

nixpkgs callPackages with multiple imports

callPackages guesses the packages to inject by the names of a packages' lambda attrset pattern names. Some packages alias these with @args to pass them to another import ...nix args.

As the used args are only named in the imported file they will be recognized as dead in the package source file that is imported by callPackage, rendering it unable to guess the dependencies to call the packages with.

Use option --no-lambda-pattern-names in this case.

What if the produced reports are wrong?

Please open an issue. Do not forget to include the .nix code that produces incorrect results.

Commercial Support

The author can be hired to implement the features that you wish, or to integrate this tool into your toolchain.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].