Skip to content
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ let
inherit (self.derivations) lazyDerivation;
inherit (self.meta) addMetaAttrs dontDistribute setName updateName
appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
hiPrioSet getLicenseFromSpdxId getExe;
hiPrioSet getLicenseFromSpdxId getLicenseFromSpdxId' getExe;
inherit (self.sources) pathType pathIsDirectory cleanSourceFilter
cleanSource sourceByRegex sourceFilesBySuffices
commitIdFromGitRepo cleanSourceWith pathHasContext
Expand Down
33 changes: 25 additions & 8 deletions lib/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ rec {
lib.all (elem: !platformMatch platform elem) (pkg.meta.badPlatforms or []);

/* Get the corresponding attribute in lib.licenses
from the SPDX ID.
from the SPDX ID,
or fallback to a lisence attrset of the corresponding name.
For SPDX IDs, see
https://spdx.org/licenses

Expand All @@ -114,18 +115,34 @@ rec {
lib.getLicenseFromSpdxId "mIt" == lib.licenses.mit
=> true
lib.getLicenseFromSpdxId "MY LICENSE"
=> trace: warning: getLicenseFromSpdxId: No license matches the given SPDX ID: MY LICENSE
=> { shortName = "MY LICENSE"; }
*/
getLicenseFromSpdxId =
getLicenseFromSpdxId = licstr:
getLicenseFromSpdxId' licstr { shortName = licstr; };

/* Get the corresponding attribute in lib.licenses
from the SPDX ID,
or fallback to the given default value.

Type:
getLicenseFromSpdxId' :: str -> Any -> Any

Example:
lib.getLicenseFromSpdxId' "MIT" null == lib.licenses.mit
=> true
lib.getLicenseFromSpdxId' "MY LICENSE" lib.licenses.free == lib.licenses.free
=> true
lib.getLicenseFromSpdxId' "MY LICENSE" null
=> null
lib.getLicenseFromSpdxId' "MY LICENSE" (builtins.abort "No SPDX ID matches MY LICENSE")
=> error: evaluation aborted with the following error message: 'No SPDX ID matches MY LICENSE'
*/
getLicenseFromSpdxId' =
let
spdxLicenses = lib.mapAttrs (id: ls: assert lib.length ls == 1; builtins.head ls)
(lib.groupBy (l: lib.toLower l.spdxId) (lib.filter (l: l ? spdxId) (lib.attrValues lib.licenses)));
in licstr:
spdxLicenses.${ lib.toLower licstr } or (
lib.warn "getLicenseFromSpdxId: No license matches the given SPDX ID: ${licstr}"
{ shortName = licstr; }
);
in licstr: default:
spdxLicenses.${ lib.toLower licstr } or default;

/* Get the path to the main program of a derivation with either
meta.mainProgram or pname or name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ lib, callPackage }:
{
registry-lib = import ./registry-lib.nix { inherit lib; };

unpackVsixHook = callPackage ./unpack-vsix-hook { };

mkExtensionGeneral = callPackage ./make-extension-general.nix { };

modifiers = callPackage ./modifiers { };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ callPackage }:
{ registryRef, vsix, meta ? { } }:
callPackage
(a@{ stdenv
, unzip
, vscode-registry-commons
, registryRef
, vsix
, meta ? { }
, configurePhase ? ":"
, buildPhase ? ":"
, dontPatchELF ? true
, dontStrip ? true
, nativeBuildInputs ? [ ]
, ...
}:
stdenv.mkDerivation ((removeAttrs a [ "stdenv" "unzip" "vscode-registry-commons" "registryRef" "vsix" ]) // {
pname = "vscode-extension-${registryRef.publisher}-${registryRef.name}";
inherit (registryRef) version;

inherit configurePhase buildPhase dontPatchELF dontStrip;

passthru = {
extensionPublisher = registryRef.publisher;
extensionName = registryRef.name;
inherit vsix;
};

src = vsix;

nativeBuildInputs = [ unzip vscode-registry-commons.unpackVsixHook ];

installPrefix = "share/vscode/extensions/${registryRef.publisher}.${registryRef.name}";

installPhase = ''

runHook preInstall

mkdir -p "$out/$installPrefix"
find . -mindepth 1 -maxdepth 1 | xargs -d'\n' mv -t "$out/$installPrefix/"

runHook postInstall
'';

}))
{ inherit registryRef vsix meta; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{ lib, fetchurl, vscode-registry-commons }:

/* Provide the build result

Order-independent

Main outputs
- extensions
- mkExtensionFromRef

Main inputs
- registry-reference-attrs
- meta-attrs ? { }
- vsix-attrs
- make-extension-attrs ? { }
*/

with vscode-registry-commons.registry-lib;

final: prev:

{

meta-attrs = prev.meta-attrs or { };

make-extension-attrs = prev.make-extension-attrs or { };

registryRefAttrnames = uniquelyUnionLists (prev.registryRefAttrnames or [ ]) [ "name" "publisher" "version" ];

inherit (vscode-registry-commons) mkExtensionGeneral;

mkExtensionFromRefSimple = registryRef:
let
builder =
if (lib.hasAttrByPath [ (escapeAttrPrefix registryRef.publisher) (escapeAttrPrefix registryRef.name) ] final.make-extension-attrs)
then final.make-extension-attrs."${escapeAttrPrefix registryRef.publisher}"."${escapeAttrPrefix registryRef.name}"
else final.mkExtensionGeneral;
in
builder {
inherit registryRef;
vsix = final.vsix-attrs."${escapeAttrPrefix registryRef.publisher}".${escapeAttrPrefix registryRef.name};
meta = final.meta-attrs."${escapeAttrPrefix registryRef.publisher}"."${escapeAttrPrefix registryRef.name}";
};

extensions = recurseIntoExtensionAttrs (mapRegistryRefAttrs final.mkExtensionFromRefSimple final.registry-reference-attrs);

mkExtensionFromRef = registryRef: (
final.mkExtensionFromRefSimple
(lib.getAttrs final.registryRefAttrnames registryRef)
).override
(removeAttrs final.registryRefAttrnames registryRef);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{ lib
, vscode-registry-commons
}:

/*
Turn the fetched registry reference data
to registry-reference-attrs and meta-attrs-fetched.

Order-independent

Main inputs:
- registry-reference-attrs-fetched

Main outputs:
- registry-reference-attrs
- meta-attrs-fetched
*/

with vscode-registry-commons.registry-lib;

let
getLicenseFromSpdxId = licstr:
lib.getLicenseFromSpdxId' licstr (
if lib.toUpper licstr == "UNLICENSED"
then lib.licenses.unfree
else null
);
in
final: prev:

{
registry-reference-attrs = (mapRegistryRefAttrs (lib.getAttrs final.registryRefAttrnames)
final.registry-reference-attrs-fetched);

meta-attrs-fetched = mapRegistryRefAttrs
(ref:
(getExistingAttrs [ "description" "homepage" ] ref)
// (
let
license = getLicenseFromSpdxId ref.license-raw;
in
lib.optionalAttrs (builtins.hasAttr "license-raw" ref && license != null) {
inherit license;
}
))
final.registry-reference-attrs-fetched;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ lib, callPackage }:
{
build = callPackage ./build.nix { };

urls2vsix = callPackage ./urls2vsix.nix { };

cookrefs = callPackage ./cookrefs.nix { };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ lib, vscode-registry-commons, fetchurl }:

/* Map urls-attrs to vsix-attrs

Order-independent

Main outputs
- vsix-attrs

Main inputs
- registry-reference-attrs
- urls-attrs
*/

final: prev:

with vscode-registry-commons.registry-lib;

{
registryRefAttrnames = uniquelyUnionLists (prev.registryRefAttrnames or [ ]) [ "name" "publisher" "version" "sha256" ];

vsix-attrs = mapRegistryRefAttrs
(ref:
fetchurl {
name = "${ref.publisher}.${ref.name}-${ref.version}.vsix";
urls = final.urls-attrs.${escapeAttrPrefix ref.publisher}.${escapeAttrPrefix ref.name};
inherit (ref) sha256;
}
)
final.registry-reference-attrs;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{ lib
, stdenvNoCC
, shellcheck
, coreutils
, curl
, jq
, nix
, unzip
}:

stdenvNoCC.mkDerivation {
pname = "nix-prefetch-vsix-lib";
version = "0.1.0";

preferLocalBuild = true;

src = [
./nix-prefetch-vsix-lib.sh
];

dontUnpack = true;

installPhase = ''
runHook preInstall
mkdir -p "$out/bin"
substitute "$src" "$out/bin/$(stripHash "$src")" \
--replace "###PLACEHOLDER_PATH_PREFIXING###" "PATH=\"${lib.makeBinPath [
coreutils
curl
jq
nix
unzip
]}\''${PATH:+:}\''${PATH-}\"; export PATH"
runHook postInstall
'';

doInstallCheck = true;

installCheckInputs = [
shellcheck
];

installCheckPhase = ''
runHook preInstallCheck

# Run through shellcheck
find "$out/bin" -mindepth 1 -type f,l -exec shellcheck --shell=bash "{}" \;

# Test sourcing
(
set -eu -o pipefail
source "$out/bin/nix-prefetch-vsix-lib.sh"
)

runHook postInstallCheck
'';

meta = with lib; {
description = "Bash library to construct a VSCode extension fetcher";
license = licenses.mit;
platforms = platforms.all;
maintainers = with maintainers; [ ShamrockLee ];
};
}
Loading