• Stars
    star
    362
  • Rank 113,669 (Top 3 %)
  • Language
    Rust
  • License
    GNU General Publi...
  • Created over 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Scan Nix files for dead code

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
Find dead code in .nix files

Usage: deadnix [OPTIONS] [FILE_PATHS]...

Arguments:
  [FILE_PATHS]...  .nix files, or directories with .nix files inside [default: .]

Options:
  -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)
  -_, --no-underscore                  Don't check any bindings that start with a _
  -q, --quiet                          Don't print dead code report
  -e, --edit                           Remove unused code and write to source file
  -h, --hidden                         Recurse into hidden subdirectories and process hidden .*.nix files
      --help
  -f, --fail                           Exit with 1 if unused code has been found
  -o, --output-format <OUTPUT_FORMAT>  Output format to use [default: human-readable] [possible values: human-readable, json]
      --exclude <EXCLUDES>...          Files to exclude from analysis
  -V, --version                        Print version

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

The --exclude parameter accepts multiple paths. Separate them with -- to pass [FILE_PATHS]....

Scan for unused code

nix run github:astro/deadnix example.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

Usage with pre-commit

Add the following to your project's .pre-commit-config.yaml:

repos:
  - repo: https://github.com/astro/deadnix
    rev: ID # frozen: VERSION
    hooks:
      - id: deadnix
        #args: [--edit] # Uncomment to automatically modify files
        stages: [commit]

Replace ID and VERSION above with the relevant version tag and commit ID for reference, for example:

rev: da39a3ee5e6b4b0d3255bfef95601890afd80709  # frozen: v1.2.3

Behavior

Renaming of all unused to lambda args to start with _

If you disfavor marking them as unused, use option -l/--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 -L/--no-lambda-pattern-names in this case.

Skipping reports for certain declarations

As of 1.1.0 deadnix supports the following pragma to skip check of bindings in the following line:

# deadnix: skip

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.

More Repositories

1

microvm.nix

NixOS MicroVMs
Nix
874
star
2

gitpop

More popular than Git*ub
JavaScript
583
star
3

socksify-ruby

Redirect any TCP connection initiated by a Ruby script through a SOCKS5 proxy
Ruby
161
star
4

skyflake

NixOS Hyperconverged Infrastructure on Nomad/NixOS
Nix
132
star
5

bitford

BitTorrent Client in a Chrome Packaged App
JavaScript
97
star
6

prittorrent

BitTorrent Content Distribution for Podcasts
Erlang
92
star
7

nix-openwrt-imagebuilder

Build OpenWRT images in Nix derivations
Nix
90
star
8

buzzrelay

Source to relay.fedi.buzz: relay the streaming API of Mastodon instances
Rust
64
star
9

remcached

Ruby EventMachine memcached client
Ruby
50
star
10

erlang-collectd

Send collectd statistics from your Erlang applications
Erlang
49
star
11

node-oembed

oEmbed consumer library for node.js & tools
JavaScript
37
star
12

em-dns

tmm1's em/dns_cache for asynchronous DNS resolving from EventMachine
Ruby
35
star
13

chaosbay

BitTorrent Tracker with upload & browsing, written on the 25th Chaos Communication Congress
Erlang
34
star
14

bitlove-ui

Bitlove.org on Yesod
JavaScript
31
star
15

noattach

Instant Personal Temporary File Sharing
JavaScript
19
star
16

firetail

HTTP REST to XMPP PubSub with node.js
JavaScript
18
star
17

rexml-dropin

Drop-in replacement for REXML using libxml-ruby and libxml-parser-ruby (expat binding)
Ruby
17
star
18

harvester

Web-based feed aggregator in Ruby
Ruby
13
star
19

norrent

Norrent is going to be a BitTorrent toolkit for node.js
JavaScript
13
star
20

collectd

Some personal modifications to collectd, the kick-ass data collector
C
13
star
21

lxc-top

Bird's eye view of Linux Containers
Ruby
13
star
22

ifdyndnsd

Watch netlink for interface address updates to do DynDNS just like nsupdate does (RFC2136 + RFC2845)
Rust
12
star
23

ruby-sasl

Simple Authentication and Security Layer (RFC 4422) for Ruby
Ruby
12
star
24

irssi-xmpp

Modifications to irssi-plugin-xmpp from CVS
C
12
star
25

deadnix-action

Workflow to find and delete dead nix code
12
star
26

hashvortex

Playing with the BitTorrent DHT in Haskell
Haskell
11
star
27

libxml-ruby

Make LibXML-Ruby's SAX parser a SAX push parser
11
star
28

em-asyncns

Resolve domain names from EventMachine with libasyncns
Ruby
11
star
29

s3erl

Erlang bindings for Amazon S3 storage web service
Erlang
11
star
30

utf8cleaner

Efficiently clean your UTF8 for Ruby in C
C
11
star
31

tokio-xmpp

XMPP with Rust and Tokio [MOVED]
10
star
32

rad1o-rust

Run Rust on the rad1o embedded hardware from Chaos Communication Camp 2015
Rust
9
star
33

spacesocket

WebSocket server for Node.js not invented here
JavaScript
9
star
34

tigger

XMPP Multi-User Chat Bot
Nix
9
star
35

superhighway

Superfeedr.com-powered feed reader webapp for standalone installation
JavaScript
9
star
36

faucheuse

Feed Aggregator (Harvester rewrite in Erlang)
Erlang
8
star
37

rust-waveshare-4inch-tft-touch-shield

Embedded Rust implementation of display+touchscreen drivers for STM32F429
Rust
8
star
38

node-vnc-client

VNC client implementation in JavaScript for node.js
JavaScript
8
star
39

dat-osm-import

Import OpenStreetMap data into dat
JavaScript
7
star
40

rust-pulse-simple

Simple Pulseaudio crate for the Rust language
Rust
7
star
41

pile

Programmatically Illuminated Lightening Environment
Rust
7
star
42

b-runner

JavaScript
7
star
43

sawrocket

Portable Raw Socket API for Firefox OS & Chrome Packaged Apps
JavaScript
7
star
44

dat-elasticsearch-upload

Upload from dat into ElasticSearch
JavaScript
7
star
45

sub2text

XMPP PubSub bridge in Erlang
Erlang
7
star
46

libpulse-sys

**Outdated!** Replaced by https://github.com/jnqnfe/pulse-binding-rust
Rust
7
star
47

node-collectdout

Periodically send values out to a Collectd server for statistics
JavaScript
6
star
48

superradar

Persistent Web Feed Reader powered by Superfeedr
JavaScript
6
star
49

rust-lpc43xx

Register definitions for the NXP LPC43xx microcontroller platform, generated through svd2rust
Rust
6
star
50

feedmonster

Push Parsing XML in Ruby
Ruby
5
star
51

sigh

HTTP signatures for ActivityPub in Rust
Rust
5
star
52

ceilingled

Yet another hackerspace illumination
CoffeeScript
5
star
53

atomstreamr

Ruby interface to http://updates.sixapart.com/atom-stream.xml
4
star
54

erlxslt

Dirty little libxslt Port for Erlang
Erlang
4
star
55

nix-cache-cut

Trim Nix binary caches according to GC roots
Rust
4
star
56

bitorama

A BitTorrent gadget on node.js
JavaScript
4
star
57

channels-xep

Condensing the Buddycloud channels protocol into a single document
4
star
58

jerry

The incredibly simple Jabber MUC client to run in screens
Ruby
3
star
59

ejabberd

Clone of Proccess One's Erlang jabber implementation from SVN.
Erlang
3
star
60

rust-kenburns

Ken Burns effect slideshow with Glium in Rust
Rust
3
star
61

youtube_to_feed

Free my content for Podcast feeds!
JavaScript
3
star
62

rust-protobuf-iter

Iterate over Protobuf messages while decoding on the fly
Rust
3
star
63

rust-sgtl5000

I2S/I2C sound output driver. Does not work.
Rust
3
star
64

network-protocol-xmpp

My branch of Network.Protocol.XMPP for Haskell
Haskell
3
star
65

spacemsg

Connecting sensors with 0mq
Haskell
3
star
66

exif-annex

node.js script to put EXIF metadata into git-annex using ffmpeg's ffprobe
JavaScript
3
star
67

superfeedr.github.com

Superfeedr's Blog
2
star
68

rust-r0ket

Embedded Rust on the CCCamp2011 r0ket badge
Rust
2
star
69

mcbench

memcached benchmark
Haskell
2
star
70

sharing2

Sharing Is Caring reimplemented
Haskell
2
star
71

openarena-distro

I accidently the whole OpenArena
2
star
72

h3c

Program โ€œDie Drei Cโ€ in Haskell
Haskell
2
star
73

rust-osm-pbf-iter

Parse OpenStreetMap .pbf dumps while trying to avoid copying
Rust
2
star
74

osm-poi-db

Extract POIs from OSM PBFs and put them into LevelDB, ready for nearby query
JavaScript
2
star
75

dresden-haushalt

Visuallizing Public Data
JavaScript
2
star
76

democropticon

My Open Data Playground
JavaScript
2
star
77

underpass-turbo

[WIP] OSM query engine with zero runtime dependencies
Rust
2
star
78

HTTPbis

Clone of the Haskell HTTP package
Haskell
2
star
79

rust-lpc13xx

Peripheral access API for NXP LPC13xx microcontrollers generated through svd2rust
Rust
2
star
80

lazy_bencoding

Lazy BEncoding parser that gives you iterators over byte slices
Rust
2
star
81

ruby-feed-parser-benchmark

Ever wanted to know what was the most effiscient Ruby Library to parse feed, check this benchmark.
Ruby
2
star
82

luft-heatmap

Luftdaten.info visualisiert
CSS
1
star
83

rust-hash2hwaddr

Hashes anything to a private MAC address
Rust
1
star
84

moers-haushalt

Converts some XML to CSV
JavaScript
1
star
85

prittorrent2

Next-gen Bitlove.org backend
JavaScript
1
star
86

dht22-rs

Rust implementation for reading from DHT22 1-wire humidity/temperature sensor
Rust
1
star
87

remind2ics

Remind to iCalendar converter
Haskell
1
star
88

petze

Service monitoring not invented here
CoffeeScript
1
star
89

hashimi

Hash Torrents in da Browser
JavaScript
1
star
90

strom

STream Real-time Online Media
Rust
1
star
91

srtsplit

Split SRT subtitle files with too long lines
Rust
1
star
92

podleech

Download Podcast Enclosures
Shell
1
star
93

osm-pbf-parser

streaming open street maps protocol buffer parser
JavaScript
1
star
94

t1mel1ne

Who has got the longest Github profile timeline?
1
star