nix-community / nix-vscode-extensions

Nix expressions for VSCode and OpenVSX extensions [maintainers: @deemp, @AmeerTaweel]
MIT License
206 stars 11 forks source link

Is it Possible to use with Home-Manager? #49

Closed andar1an closed 10 months ago

andar1an commented 10 months ago

I have tried a few ways to use nix-vscode-extensions with vscode module in home-manager. I have not had luck yet.

My current attempt looks something like this:

Flake.nix

inputs = {
nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions";
};

outputs = inputs@{. . ., nix-vscode-extensions,...}:
let 
 open-vsx = nix-vscode-extensions.extensions.${system}.open-vsx;
in
{ 
. . .
    home-manager.nixosModules.home-manager
    {
      home-manager.useGlobalPkgs = true;
      home-manager.useUserPackages = true;
      home-manager.users.stephen = import ./${hostname}/home.nix;
      home-manager.extraSpecialArgs = {nix-vscode-extensions = open-vsx;}; # have tried a few different things here, this is just current attempt
      # also tried inherit inputs above
    }
. . .

Home.nix

  { config, pkgs, lib, open-vsx, ... }: <=== I have tried passing "inputs" here, and referencing it differently below.
  {
   programs.vscode = {
      enable = true;
      package = pkgs.vscodium;
      mutableExtensionsDir = false;
      # settings.json
      userSettings = {

      };
      extensions = with open-vsx; [ <===== TRYING TO USE INPUT HERE
        ...
        arrterian.nix-env-selector
        ...
      ];
    };

I am new to nix, and it would be helpful if I could get some direction or guidance please.

Thanks :)

andar1an commented 10 months ago

Going to try to learn and use an overlay.

veneficium42 commented 4 months ago

So did you figure out how to do this? 😅

veneficium42 commented 4 months ago

Oh wait, nvm, I looked into the other issues, I think I got it

andar1an commented 4 months ago

I did but on Debian using bash haha. Glad you figured out! I still love nix/nixos but it didn't fit for my personal needs.

artur-sannikov commented 1 month ago

For anyone dealing with this issue on a non-NixOS system with with a standalone installation.

This should be a minimal reproducible example:

# flake.nix
{
  description = "Home Manager configuration";

  inputs = {
    nixpkgs.url = "nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    # VS Code extensions
    nix-vscode-extensions = {
      url = "github:nix-community/nix-vscode-extensions";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    {
      nixpkgs,
      home-manager,
      nix-vscode-extensions,
      ...
    }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs { inherit system; };
    in
    {
      homeConfigurations = {
        my-pc = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [
            ./home.nix
            {
              nixpkgs.overlays = [
                nix-vscode-extensions.overlays.default # Also have a look at https://github.com/nix-community/nix-vscode-extensions/issues/29
              ]; 
            }
          ];
        };
      };
    };
}
# home.nix
{ config, pkgs, ... }:

{
  home.username = "user";
  home.homeDirectory = "/home/user";

  # This value determines the Home Manager release that your configuration is
  # compatible with. This helps avoid breakage when a new Home Manager release
  # introduces backwards incompatible changes.
  #
  # You should not change this value, even if you update Home Manager. If you do
  # want to update the value, then make sure to first check the Home Manager
  # release notes.
  home.stateVersion = "24.05"; # Please read the comment before changing.

  # The home.packages option allows you to install Nix packages into your
  # environment.
  home.packages =
    [
    ];

  # Let Home Manager install and manage itself
  programs = {
    home-manager = {
      enable = true;
    };
  };

  programs.vscode = {
    enable = true;
    package = pkgs.vscodium;
    extensions = with pkgs.vscode-marketplace; [
      jnoortheen.nix-ide
      quarto.quarto # I added Quarto extensions that cannot be installed without nix-vscode-extensions 
    ];
  };
}