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

False positive UnnededRec when 'chaining' inherit #59

Open
chriswarbo opened this issue Aug 28, 2021 · 3 comments
Open

False positive UnnededRec when 'chaining' inherit #59

chriswarbo opened this issue Aug 28, 2021 · 3 comments

Comments

@chriswarbo
Copy link

Similar to #43

The following code defines an attrset containing lib (taken from import <nixpkgs> {}) and escapeShellArg (taken from lib):

rec {
  inherit (import <nixpkgs> {}) lib;
  inherit (lib) escapeShellArg;
}
Welcome to Nix version 2.3.11. Type :? for help.

nix-repl> import ./example.nix
{ escapeShellArg = «lambda @ /nix/store/xdk4f76azzwg5qami5w250kh9l79sszh-nixpkgs-src/lib/strings.nix:318:20»; lib = { ... }; }

This needs rec, otherwise we can't inherit from the lib variable.

Welcome to Nix version 2.3.11. Type :? for help.

nix-repl> import ./example.nix
error: undefined variable 'lib' at /Users/chrisw/DeleteMe/example.nix:3:12

However, nix-linter thinks the rec is not needed:

$ nix-linter example.nix 
Unneeded `rec` on set at example.nix:1:1-4:2

For context, I often use this pattern alongside with, e.g. a non-toy example:

with rec {
  inherit (builtins) isList toJSON;
  inherit (nixpkgs)
    bash
    callPackage
    coreutils
    gnugrep
    gnused
    jq
    lib
    runCommand
    writeReferencesToFile;
  inherit (lib) concatMapStringsSep escapeShellArg;
  inherit (helpers.util) script;
};
rec {
  ...
}
@expipiplus1
Copy link
Collaborator

expipiplus1 commented Aug 31, 2021 via email

@Radvendii
Copy link

@chriswarbo I'm curious; is there a reason you use with rec { ... }; rather than let ...; in?

@chriswarbo
Copy link
Author

@Radvendii I wrote up my reasoning at NixOS/nix#1361 (comment) (Warbo is my personal account; chriswarbo is my work account)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants