nix-community / nix-vscode-extensions

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

I'm not sure how to use this with homemanager? #44

Closed spott closed 1 year ago

spott commented 1 year ago

I'm far from a nix pro, but I wanted to add this to my (flaked) homemanager config so I can get all the nice benefits.

Unfortunately, I can't figure out how to do this.

My flake:

{
  description = "Home Manager configuration of Spott";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";

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

    nix-vscode-extensions.url = "github:nix-community/nix-vscode-extensions";
    /*
       flake-utils = {
      url = "github:numtide/flake-utils";
    };
    */
  };

  outputs = {
    nixpkgs,
    home-manager,
    nix-vscode-extensions,
    ...
  }:
  let
    extensions = sys:
      nix-vscode-extensions.extensions.${sys}; # I can't figure out how to put this somewhere I can pass to the modules below
    overlays = sys: [
        (self: super: {
          python = super.python310;
        })
# is there some way I can pass this here, so I can use it with something like pkgs.nix-vscode-extensions?
      ];

    pkgs = sys:
      import nixpkgs {
        system = sys;
        config = {allowUnfree = true;};
        overlays = overlays sys;
      };
  in {
    packages = {
      aarch64-darwin.homeConfigurations = {
        "spott@Normandy.local" = home-manager.lib.homeManagerConfiguration {
          pkgs = pkgs "aarch64-darwin";
          modules = [
            ./normandy.nix
            ./common.nix # I want common.nix to have access to the extensions object, but I'm not sure how to do that.
            ./darwin-common.nix
            ./zsh/zsh.nix
          ];
        };
        "spott@Endeavor.local" = home-manager.lib.homeManagerConfiguration {
          pkgs = pkgs "aarch64-darwin";
          modules = [
            ./endeavor.nix
            ./common.nix
            ./darwin-common.nix
            ./zsh/zsh.nix
          ];
        };
      };
      x86_64-linux.homeConfigurations = {
        "spott@devbox" = home-manager.lib.homeManagerConfiguration {
          pkgs = pkgs "x86_64-linux";
          modules = [
            ./devbox.nix
            ./common.nix
            ./zsh/zsh.nix
          ];
        };
      };
    };
  };
}

I'd appreciate any help, not sure if this is the right place to post this, if not, point me in the right direction.

AmeerTaweel commented 1 year ago

On way to do it is to use this flake's overlay. You can modify your overlays to be:

overlays = sys: [
    # Your Original Overlay
    (self: super: {
        python = super.python310;
    })
    # Nix VSCode Extensions Overlay
    nix-vscode-extensions.overlays.default
];

Notice that you don't need to use the system attribute with overlays. You can safely convert overlays to a list instead of a function taking sys as input:

overlays = [
    # Your Original Overlay
    (self: super: {
        python = super.python310;
    })
    # Nix VSCode Extensions Overlay
    nix-vscode-extensions.overlays.default
];

And then you would use it like this:

pkgs = system: import nixpkgs {
    inherit system overlays;
    config = {allowUnfree = true;};
};

Now you can use pkgs.vscode-marketplace.PUBLISHER.NAME to use extensions from within your home-manager config.

spott commented 1 year ago

Thanks a ton! That definitely makes sense.