about summary refs log tree commit diff
path: root/pkgs/applications/editors/vscode/extensions/vscodeExts2nix.nix
blob: 96b892911b06dc16b1a79c03755c90e12dcfce19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# based on the passed vscode will stdout a nix expression with the installed vscode extensions
{
  lib,
  vscodeDefault,
  writeShellScriptBin,
}:

##User input
{
  vscode ? vscodeDefault,
  extensionsToIgnore ? [ ],
  # will use those extensions to get sha256 if still exists when executed.
  extensions ? [ ],
}:
let
  mktplcExtRefToFetchArgs = import ./mktplcExtRefToFetchArgs.nix;
in
writeShellScriptBin "vscodeExts2nix" ''
  echo '['

  for line in $(${vscode}/bin/code --list-extensions --show-versions \
    ${
      lib.optionalString (extensionsToIgnore != [ ]) ''
        | grep -v -i '^\(${
          lib.concatMapStringsSep "\\|" (e: "${e.publisher}.${e.name}") extensionsToIgnore
        }\)'
      ''
    }
  ) ; do
    [[ $line =~ ([^.]*)\.([^@]*)@(.*) ]]
    name=''${BASH_REMATCH[2]}
    publisher=''${BASH_REMATCH[1]}
    version=''${BASH_REMATCH[3]}

    extensions="${lib.concatMapStringsSep "." (e: "${e.publisher}${e.name}@${e.sha256}") extensions}"
    reCurrentExt=$publisher$name"@([^.]*)"
    if [[ $extensions =~ $reCurrentExt ]]; then
      sha256=''${BASH_REMATCH[1]}
    else
      sha256=$(
        nix-prefetch-url "${
          (mktplcExtRefToFetchArgs {
            publisher = ''"$publisher"'';
            name = ''"$name"'';
            version = ''"$version"'';
          }).url
        }" 2> /dev/null
      )
    fi

    echo "{ name = \"''${name}\"; publisher = \"''${publisher}\"; version = \"''${version}\"; sha256 = \"''${sha256}\";  }"
  done


  echo ']'
''