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

nix-instantiate --json incorrectly uses store path #5612

Closed
lapp0 opened this issue Nov 20, 2021 · 3 comments · Fixed by #6909
Closed

nix-instantiate --json incorrectly uses store path #5612

lapp0 opened this issue Nov 20, 2021 · 3 comments · Fixed by #6909
Labels

Comments

@lapp0
Copy link

lapp0 commented Nov 20, 2021

Describe the bug

Inconsistent output fornix-instantiate between use of --json, --xml, and no encoding argument. In the case of --json it uses the nix-store path.

Steps To Reproduce

Set imports = [(modulesPath + "/installer/scan/not-detected.nix")]; in my-file.nix

Observe the output for

# no encoding
nix-instantiate --eval -E '(import my-file.nix {config = {}; pkgs = import <nixpkgs> {}; lib = {}; modulesPath = <nixpkgs/nixos/modules>;}).imports' --strict
[ /etc/nixos/nixpkgs/nixos/modules/installer/scan/not-detected.nix ]

# xml
nix-instantiate --xml --eval -E '(import my-file.nix {config = {}; pkgs = import <nixpkgs> {}; lib = {}; modulesPath = <nixpkgs/nixos/modules>;}).imports' --strict
<?xml version='1.0' encoding='utf-8'?>
<expr>
  <list>
    <path value="/etc/nixos/nixpkgs/nixos/modules/installer/scan/not-detected.nix" />
  </list>
</expr>

# json
nix-instantiate --json --eval -E '(import my-file.nix {config = {}; pkgs = import <nixpkgs> {}; lib = {}; modulesPath = <nixpkgs/nixos/modules>;}).imports' --strict
["/nix/store/5vc99s7pn69w6mnhh7rfnzcrdl8mf7dn-not-detected.nix"]%

Expected behavior

--json output should be [ "/etc/nixos/nixpkgs/nixos/modules/installer/scan/not-detected.nix" ]

nix-env --version output

nix-env (Nix) 2.4pre20211006_53e4794

@milahu
Copy link
Contributor

milahu commented Nov 21, 2021

what exactly is in your my-file.nix file?

# my-file.nix
{ modulesPath, ... }:
{ imports = [(modulesPath + "/installer/scan/not-detected.nix")]; }

case nPath:
doc.writeEmptyElement("path", singletonAttrs("value", v.path));
break;

case nPath:
out.write(state.copyPathToStore(context, v.path));
break;

... but i have no idea why json should print store paths

same for builtins.toJSON

nix-repl> (import ./my-file.nix { config = {}; pkgs = import <nixpkgs> {}; lib = {}; modulesPath = <nixpkgs/nixos/modules>; }).imports
[ /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/installer/scan/not-detected.nix ]

nix-repl> builtins.toJSON (import ./my-file.nix { config = {}; pkgs = import <nixpkgs> {}; lib = {};
"[\"/nix/store/5vc99s7pn69w6mnhh7rfnzcrdl8mf7dn-not-detected.nix\"]"

@stale stale bot added the stale label Aug 12, 2022
@ncfavier
Copy link
Member

Just ran into this, is there any reason the JSON printer behaves differently? I can't think of a reason to copy paths to the store when printing JSON.

@stale stale bot removed the stale label Aug 16, 2022
ncfavier added a commit to ncfavier/nix that referenced this issue Aug 16, 2022
ncfavier added a commit to ncfavier/nix that referenced this issue Aug 22, 2022
Makes `printValueAsJSON` not copy paths to the store for `nix eval
--json`, `nix-instantiate --eval --json` and `nix-env --json`.

Fixes NixOS#5612
@ncfavier
Copy link
Member

This is now fixed for nix eval, but not for nix-instantiate.

Minion3665 pushed a commit to Minion3665/nix that referenced this issue Feb 23, 2023
Makes `printValueAsJSON` not copy paths to the store for `nix eval
--json`, `nix-instantiate --eval --json` and `nix-env --json`.

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

Successfully merging a pull request may close this issue.

3 participants