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

Attempt to support vscode extensions. #206

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
111 changes: 111 additions & 0 deletions examples/vscode-exts/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions examples/vscode-exts/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
inputs.organist.url = "github:nickel-lang/organist";

nixConfig = {
extra-substituters = ["https://organist.cachix.org"];
extra-trusted-public-keys = ["organist.cachix.org-1:GB9gOx3rbGl7YEh6DwOscD1+E/Gc5ZCnzqwObNH2Faw="];
};

outputs = {organist, ...} @ inputs:
organist.flake.outputsFromNickel ./. inputs {};
}
3 changes: 3 additions & 0 deletions examples/vscode-exts/nickel.lock.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
organist = import "../../lib/organist.ncl",
}
29 changes: 29 additions & 0 deletions examples/vscode-exts/project.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let inputs = import "./nickel.lock.ncl" in
let organist = inputs.organist in

{
shells = organist.shells.Bash,

shells.dev = {
packages.hello = organist.import_nix "nixpkgs#hello",
},

vscode = {
extensions = {
"nickel" = {
publisher = "Tweag",
name = "vscode-nickel",
version = "0.3.0",
sha256 = "sha256-OntQfxh51B3x92IE4y62bw8csBGukqUzmUJIr/rGioU=",
},
"test" = {
name = "vscode-markdownlint",
publisher = "DavidAnson",
version = "0.55.0",
sha256 = "sha256-slfHfRPcuRu+649n6kAr2bv9H6J+DvYVN/ysq1QpPQM=",
},
},
},
}
| organist.OrganistExpression
& organist.tools.vscode.Schema
1 change: 1 addition & 0 deletions lib/organist.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

tools.editorconfig = import "./editorconfig.ncl",
tools.direnv = import "./direnv.ncl",
tools.vscode = import "./vscode.ncl",
}
#TODO: currently, Nickel forbids doc at the toplevel. It's most definitely
# temporary, as the implementation of RFC005 is ongoing. Once the capability is
Expand Down
1 change: 1 addition & 0 deletions lib/schema.ncl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let nix = import "./nix-interop/nix.ncl" in
let filegen = import "files.ncl" in
let vscode = import "vscode.ncl" in
{
OrganistShells = {
dev
Expand Down
56 changes: 56 additions & 0 deletions lib/vscode.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
let nix = import "./nix-interop/nix.ncl" in
let ExtensionFromMarketplace = {
publisher | String,
name | String,
version | String,
sha256 | String
} in
let VSCodeSchema = {
extensions
| doc "Extensions to install locally in the workspace"
| { _ : ExtensionFromMarketplace }
| default = {}
} in
let BuiltExtensionDetails = {
name | String,
path | nix.derivation.NixString,
} in
let buildExtension : String -> ExtensionFromMarketplace -> BuiltExtensionDetails = fun extName efm =>
{ name = extName,
path = nix.derivation.CallNix & { function = m%"
{vscode-utils, extension-ref}:
vscode-utils.buildVscodeMarketplaceExtension
{ mktplcRef = extension-ref; }
"%,
args = {
vscode-utils = nix.import_nix "nixpkgs#vscode-utils",
extension-ref = {
publisher = efm.publisher,
name = efm.name,
version = efm.version,
sha256 = efm.sha256
},
}
}} | BuiltExtensionDetails in
let regenerate-vscode | { _ : ExtensionFromMarketplace} -> nix.derivation.Derivation = fun exts =>
{ name = "regenerate-vscode",
content.text = exts
|> std.record.to_array
|> std.array.map (fun {field = extName, value = ext} => buildExtension extName ext)
|> std.array.fold_left
( fun acc elt =>
nix-s%"
%{acc}
ln -sf %{elt.path}/share/vscode/extensions/* ".vscode/extensions/"
"%)
"",
} | nix.builders.ShellApplication
in {
Schema = {
vscode | doc m%"
VSCode configuration
"% | VSCodeSchema | default
= {},
flake.apps.regenerate-vscode.program = nix-s%"%{regenerate-vscode vscode.extensions}/bin/regenerate-vscode"%,
},
}
Loading