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

Rewrite flake (fix overlay) #9

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 78 additions & 82 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,102 +6,98 @@

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/dbc68fa4bb132d990945d39801b0d7f2ba15b08f";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};

outputs = { self, nixpkgs, flake-utils, flake-compat }: flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
outputs = {
self,
nixpkgs,
...
}: let
inherit (nixpkgs) lib;
defaultSystems = [
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
"x86_64-linux"
];
genSystems = lib.genAttrs defaultSystems;
in {
templates = {
vscodium-with-extensions = {
path = ./template;
description = "VSCodium with extensions";
};
};

loadGenerated = set:
with builtins; with pkgs; let
generated = import ./data/generated/${set}.nix {
inherit fetchurl fetchFromGitHub;
fetchgit = fetchGit;
};
extensions =
genSystems (system:
self.overlays.default null nixpkgs.legacyPackages.${system});

groupedByPublisher = (groupBy (e: e.publisher) (attrValues generated));
pkgDefinition = {
open-vsx = e: with e; with vscode-utils; {
inherit name;
value = buildVscodeMarketplaceExtension {
vsix = src;
mktplcRef = {
inherit version;
publisher = publisher;
name = name;
};
meta = with lib; {
inherit changelog downloadPage homepage;
license = licenses.${license};
};
overlays = {
default = _: prev: let
utils = prev.vscode-utils;
loadGenerated = path:
lib.pipe path [
(path:
import path {
inherit (prev) fetchurl fetchFromGitHub;
fetchgit = prev.fetchGit;
})
(lib.mapAttrsToList (_: extension: {
inherit (extension) name;
value = utils.buildVscodeMarketplaceExtension {
vsix = extension.src;
mktplcRef = {
inherit (extension) name publisher version;
};
};
vscode-marketplace = e: with e; with vscode-utils; {
inherit name;
value = buildVscodeMarketplaceExtension {
vsix = src;
mktplcRef = {
inherit version;
publisher = publisher;
name = name;
};
};
};
};
in
mapAttrs (_: val: listToAttrs (map pkgDefinition.${set} val)) groupedByPublisher;
}))
(builtins.groupBy ({value, ...}: value.vscodeExtPublisher))
(builtins.mapAttrs (_: lib.listToAttrs))
];
in {
vscode-marketplace = loadGenerated ./data/generated/vscode-marketplace.nix;
open-vsx = loadGenerated ./data/generated/open-vsx.nix;
};
};

extensions = {
vscode-marketplace = loadGenerated "vscode-marketplace";
open-vsx = loadGenerated "open-vsx";
};
packages = genSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};

vscodiumWithExtensions =
let
inherit (pkgs) vscode-with-extensions vscodium;
vscodium_ =
(vscode-with-extensions.override {
vscode = vscodium;
vscodeExtensions = builtins.attrValues {
inherit (extensions.vscode-marketplace.golang) go;
inherit (extensions.vscode-marketplace.vlanguage) vscode-vlang;
};
});
in
vscodium_ // {
meta = (builtins.removeAttrs vscodium_.meta [ "description" ]) // {
longDescription = ''
This is a sample `VSCodium` (= `VS Code` without proprietary stuff) with a couple of extensions.

The [repo](https://github.com/nix-community/nix-vscode-extensions) provides
`VS Code Marketplace` (~40K) and `Open VSX` (~3K) extensions as `Nix` expressions.
# overrideAttrs is avoided so that Nix can still hit binary cache
examplePackage = pkgs.vscode-with-extensions.override {
vscode = pkgs.vscodium;
vscodeExtensions = with self.extensions.${system}.vscode-marketplace; [
golang.go
vlanguage.vscode-vlang
];
};
examplePackage' =
examplePackage
// {
meta =
(removeAttrs examplePackage.meta ["description"])
// {
longDescription = lib.mdDoc ''
This is a sample overridden VSCodium (FOSS fork of VS Code) with a couple extensions.
You can override this package and set `vscodeExtensions` to a list of extension
derivations, namely those provided by this flake.

The [repository] provides about 40K extensions from [Visual Studio Marketplace]
and another ~3K from [Open VSX Registry].

[repository]: https://github.com/nix-community/nix-vscode-extensions
[Visual Studio Marketplace]: https://marketplace.visualstudio.com/vscode
[Open VSX Registry]: https://open-vsx.org/
'';
};
};
in
{
packages = {
inherit vscodiumWithExtensions;
};
inherit extensions;
}
) // {
overlays.default = final: prev: {
vscode-extensions = self.extensions.${prev.system};
};
}
// {
templates = {
default = {
path = ./template;
description = "VSCodium with extensions";
};
};
in {
vscodium-with-extensions = examplePackage';
});
};
}