Closed Scandiravian closed 1 year ago
I couldn't reproduce the error. I created this minimal flake:
{
inputs = {
nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions";
};
outputs = { ... }: {
# None
};
}
Then ran the same thing with nix repl
and didn't get any error:
$ nix repl
Welcome to Nix 2.13.2. Type :? for help.
nix-repl> :lf .
Added 8 variables.
nix-repl> inputs.nix-vscode-extensions.extensions.x86_64-linux.vscode-marketplace.golang.go
«derivation /nix/store/0b2w4ak4xz8fm7zgxci7l2hsv765h7zb-vscode-extension-golang-go-0.37.1.drv»
nix-repl> inputs.nix-vscode-extensions.extensions.x86_64-linux.open-vsx.golang.go
«derivation /nix/store/plannn5mbpip1qzwc6bmgwmwr9xzxkaq-vscode-extension-golang-go-0.37.1.drv»
Can you please provide a minimal flake to reproduce the issue?
The issue occurs when you'll import the flake as an overlay. Please do not use REPL for debugging because it doesn't evaluate the outputs.overlays.default
And obviously you can't reproduce the error if you're not touching the right code. Nix is a functional lazily evaluated language, that means it only launches the code only and only if it's concerned with execution by higher-level functions. It's probable that the @Scandiravian has overlay import in his dotfile, which is not accounted for in the report :D
The issue occurs when you'll import the flake as an overlay. Please do not use REPL for debugging because it doesn't evaluate the
outputs.overlays.default
And obviously you can't reproduce the error if you're not touching the right code. Nix is a functional lazily evaluated language, that means it only launches the code only and only if it's concerned with execution by higher-level functions. It's probable that the @Scandiravian has overlay import in his dotfile, which is not accounted for in the report :D
@bppdddqqqq You're right - I'm using it as an overlay. I used the repl to reproduce the error, since it was difficult to create a concise description of the issue using my dotfiles.
Here's how to reproduce the issue using configuration files and home-manager
# flake.nix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
nix-vscode-extensions = {
url = "github:nix-community/nix-vscode-extensions";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nix-vscode-extensions, nixpkgs, home-manager, ... }:
{
homeConfigurations = {
"test-home" = home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance
extraSpecialArgs = { };
modules = [
./home.nix
{
nixpkgs.overlays = [
nix-vscode-extensions.overlays.default
];
}
];
};
};
};
}
# home.nix
{ pkgs, ... }: {
programs.vscode = {
enable = true;
package = pkgs.vscode;
extensions = with pkgs.vscode-marketplace; [
eamodio.gitlens
];
};
home.username = "test-user";
home.homeDirectory = "/home/test-user";
home.stateVersion = "22.11";
}
When running home-manager build --flake .#test-home
it produces the error:
error: attribute 'vscodeExtPublisher' missing
at /nix/store/z8z0bjp8y8ah0qy1kwhgzhiklp0cqibq-source/flake.nix:42:52:
41| }))
42| (builtins.groupBy ({ value, ... }: value.vscodeExtPublisher))
| ^
43| (builtins.mapAttrs (_: lib.listToAttrs))
(use '--show-trace' to show detailed location information)
Thanks @bppdddqqqq and @Scandiravian. Now I can reproduce the error. Will take a look.
I found the issue.
This flake uses nixpkgs/dbc68fa4bb132d990945d39801b0d7f2ba15b08f
, which is a fairly recent version.
In this version, vscode-utils.buildVscodeExtension
is defined as:
buildVscodeExtension = a@{
name,
src,
# Same as "Unique Identifier" on the extension's web page.
# For the moment, only serve as unique extension dir.
vscodeExtPublisher,
vscodeExtName,
vscodeExtUniqueId,
configurePhase ? ''
runHook preConfigure
runHook postConfigure
'',
buildPhase ?''
runHook preBuild
runHook postBuild
'',
dontPatchELF ? true,
dontStrip ? true,
nativeBuildInputs ? [],
...
}:
stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // {
name = "vscode-extension-${name}";
passthru = {
inherit vscodeExtPublisher vscodeExtName vscodeExtUniqueId;
};
inherit configurePhase buildPhase dontPatchELF dontStrip;
installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";
nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
installPhase = ''
runHook preInstall
mkdir -p "$out/$installPrefix"
find . -mindepth 1 -maxdepth 1 | xargs -d'\n' mv -t "$out/$installPrefix/"
runHook postInstall
'';
});
In your flake, you use the older nixpkgs/nixos-22.11
.
In this version, vscode-utils.buildVscodeExtension
is defined as:
buildVscodeExtension = a@{
name,
src,
# Same as "Unique Identifier" on the extension's web page.
# For the moment, only serve as unique extension dir.
vscodeExtUniqueId,
configurePhase ? ''
runHook preConfigure
runHook postConfigure
'',
buildPhase ?''
runHook preBuild
runHook postBuild
'',
dontPatchELF ? true,
dontStrip ? true,
nativeBuildInputs ? [],
...
}:
stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // {
name = "vscode-extension-${name}";
inherit vscodeExtUniqueId;
inherit configurePhase buildPhase dontPatchELF dontStrip;
installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}";
nativeBuildInputs = [ unzip ] ++ nativeBuildInputs;
installPhase = ''
runHook preInstall
mkdir -p "$out/$installPrefix"
find . -mindepth 1 -maxdepth 1 | xargs -d'\n' mv -t "$out/$installPrefix/"
runHook postInstall
'';
});
The difference is that passthru
is not used in nixpkgs/nixos-22.11
, so vscodeExtPublisher
does not get passed.
But why does the overlay use vscode-utils
from nixpkgs/nixos-22.11
, and not nixpkgs/dbc68fa4bb132d990945d39801b0d7f2ba15b08f
? Line 25:
utils = prev.vscode-utils;
The issue would be resolve by replacing this line with something like:
utils = nixpkgs.legacyPackages.x86_64-linux.vscode-utils;
Basically, using the nixpkgs
input instead of prev
. But for this to work, you also shouldn't do:
nix-vscode-extensions.inputs.nixpkgs.follows = "nixpkgs";
However, the problem with this approach is that I have thrown x86_64-linux
in the mix. This should be ${system}
but I don't know how to get ${system}
in that context.
Any help on how to approach this would be appreciated.
@AmeerTaweel Thanks for taking a look at this, I really appreciate it!
https://github.com/NixOS/nixpkgs/commit/dbc68fa4bb132d990945d39801b0d7f2ba15b08f is a commit to the nixpkg master branch, so I'm curious if there's a reason for the flake using a commit from the master branch instead of either the stable
or unstable
branch (nixos-22.11
or nixos-unstable
)?
I think that the nixos-22.11
that is referenced by my flake.lock
is actually newer than https://github.com/NixOS/nixpkgs/commit/dbc68fa4bb132d990945d39801b0d7f2ba15b08f (that commit is from December, while my flake.lock
points to a commit in the nixos-22.11
branch from this Monday)
Since the issue is caused by the nixpkg version of this flake pointing to a commit instead of a branch, I tried removing inputs.nixpkgs.follows = "nixpkgs";
from the nix-vscode-extensions
in my configuration inputs
This throws a different error:
error: attribute 'toExtensionJson' missing
at /nix/store/df977wnmxn0iv0nx0wngbplllix1zkvk-source/modules/programs/vscode.nix:38:19:
37|
38| extensionJson = pkgs.vscode-utils.toExtensionJson cfg.extensions;
| ^
39| extensionJsonFile = pkgs.writeTextFile {
(use '--show-trace' to show detailed location information)
Which I think is due to toExtensionJson
only being in the master branch and not in stable branch yet.
I think most users will be using either stable or unstable nixpkg inputs, so to avoid others running into the same issue, would it be possible to change the input in this flake to either nixos-22.11
or nixos-unstable
and then use nix flake update
to keep it up to date in flake.lock
?
I wrote this pretty hastily, as I have to go to a meeting in two minutes. If anything is unclear or non-sense, please let me know. I'll read through my post again later and try to fix it up :sweat_smile:
However, the problem with this approach is that I have thrown x86_64-linux in the mix. This should be ${system} but I don't know how to get ${system} in that context.
@AmeerTaweel If this is done in an overlay, ${system}
, should be available like this
final: prev: {
utils = nixpkgs.legacyPackages.${final.system}.vscode-utils;
}
Though I would still suggest changing to a stable branch as input for the flake as mentioned in my comment above :smile:
@Scandiravian Yeah I think we have to do both things.
nixpkgs.legacyPackages.${final.system}.vscode-utils;
nixos-unstable
.The first part is easy, but the second part I just want to check why it is the way it is right now.
@deemp is there any specific reason for:
nixpkgs.url = "github:NixOS/nixpkgs/dbc68fa4bb132d990945d39801b0d7f2ba15b08f";
I don't want to change it carelessly.
@AmeerTaweel , nope, that specific rev isn't required. Could you please apply the fixes that you've suggested?
Fixed in fcbae002f8d62db5ef4f6e1739037963aecd6e7a.
Howdy @AmeerTaweel,
Apologies for not being able to follow along if this has already been mentioned, but is there a fix (other than pinning to an older nix-vscode-extensions) if I don't want my flake to depend an unstable version of nixpkgs?
Like @Scandiravian, I'm on nixos-21.11 and the latest master of nix-vscode-extensions.
Thanks, smkuehnhold
@smkuehnhold I don't understand the issue. Even if our flake uses unstable this does not affect your main flake, it will still be on nixos-21.11
. Can you elaborate?
@smkuehnhold I don't understand the issue. Even if our flake uses unstable this does not affect your main flake, it will still be on
nixos-21.11
. Can you elaborate?
Ah, I get it now. There is one thing I neglected to mention: I've specified nix-vscode-extensions.follows=system-nixpkgs
basically (where system-nixpkgs is some version of nixos-21.11 that my system uses). I guess it was my mistake to assume the original poster had done the same? 🤔
As for why I do this, it's really just hygiene. It is my preference to not depend on more than one version of nixpkgs unless otherwise necessary. My guess now is that this flake falls into the latter case? If so, that's a little annoying (to me) but understandable.
Thanks for the clarification @AmeerTaweel 👍
@smkuehnhold I actually do use "follows", but as I use a mix of packages from nixos-22-11
and nixos-unstable
, I configured the extensions flake to follow the unstable one instead.
When trying to add extensions using this flake I'm seeing the error
attribute 'vscodeExtPublisher' missing
. I rannix flake update
last Friday, where I could build my configuration successfully. I tried using the example with the nix repl found here and the error is present there as seen below:Looking through the commit history, it seems to be caused by the changes in https://github.com/nix-community/nix-vscode-extensions/commit/46be1e77328c79878e698dd075842c7552546007, since the line that is referenced in the error message was added in this commit.
I've unfortunately not had time to look into what could resolve this issue.
Please let me know if you need any additional information or I can help out in any other way. This flake is great and it's made it much easier for me to maintain my configuration, so I'll be happy to help out if I can.