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

initial nix language support #1911

Draft
wants to merge 20 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
25 changes: 25 additions & 0 deletions data/playground/nix/asserts.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# https://nixos.org/manual/nix/stable/language/constructs.html#assertions

{ localServer ? false
, httpServer ? false
, sslSupport ? false
, pythonBindings ? false
, javaSwigBindings ? false
, javahlBindings ? false
, stdenv, fetchurl
, openssl ? null, httpd ? null, db4 ? null, expat, swig ? null, j2sdk ? null
}:

assert localerver -> db4 != null;
assert httpServer -> httpd != null && httpd.expat == expat;
assert sslSupport -> openssl != null && (httpServer -> httpd.openssl == openssl);
assert pythonBindings -> swig != null && swig.pythonSupport;
assert javaSwigBindings -> swig != null && swig.javaSupport;
assert javahlBindings -> j2sdk != null;

stdenv.mkDerivation {
(name = "subversion-1.1.1";)
...
openssl = if sslSupport then openssl else null;
...
}
19 changes: 19 additions & 0 deletions data/playground/nix/attrsets.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
a = { a = b; c = d; };
a = {
a = b;
c = d;
};

a = {
a = {
b = 1; };

c = { d = [ "1" 2 ] };
};

a = rec {
a = b;
b = a + 1;
};
}
8 changes: 8 additions & 0 deletions data/playground/nix/comments.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Single-line comment
/*
Multi-line comment
*/
{
a = b; # Inline comment (test)
b = c; # Inline comment 2
}
67 changes: 67 additions & 0 deletions data/playground/nix/complex.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
home-manager = {
url = "github:nix-community/home-manager/release-23.05";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, home-manager }:
let
mkHost = hostName: system:
(({ my-config, zfs-root, pkgs, system, ... }:
nixpkgs.lib.nixosSystem {
inherit system;
modules = [
# Module 0: zfs-root and my-config
./modules

# Module 1: host-specific config, if exist
(if (builtins.pathExists
./hosts/${hostName}/configuration.nix) then
(import ./hosts/${hostName}/configuration.nix { inherit pkgs; })
else
{ })

# Module 2: entry point
(({ my-config, zfs-root, pkgs, lib, ... }: {
inherit my-config zfs-root;
system.configurationRevision = if (self ? rev) then
self.rev
else
throw "refuse to build: git tree is dirty";
system.stateVersion = "23.05";
imports = [
"${nixpkgs}/nixos/modules/installer/scan/not-detected.nix"
# "${nixpkgs}/nixos/modules/profiles/hardened.nix"
# "${nixpkgs}/nixos/modules/profiles/qemu-guest.nix"
];
}) {
inherit my-config zfs-root pkgs;
lib = nixpkgs.lib;
})

# Module 3: home-manager
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}

# Module 4: config shared by all hosts
(import ./configuration.nix { inherit pkgs; })
];
})

# configuration input
(import ./hosts/${hostName} {
system = system;
pkgs = nixpkgs.legacyPackages.${system};
}));
in {
nixosConfigurations = {
exampleHost = mkHost "exampleHost" "x86_64-linux";
};
};
}
13 changes: 13 additions & 0 deletions data/playground/nix/functions.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
# Anonymous function
a = foo: (foo + 1);
x = a: b: a + b;

# Non-built-in function
ba = test( foo: bar: {
b = foo;
});

# Built-in function
x = map (x: y: x + x) [ 1 2 3 ];
}
7 changes: 7 additions & 0 deletions data/playground/nix/lists.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
foo = [ "a" a/b/c "b" ];
bar = [ A
B
C # foo
];
}
36 changes: 36 additions & 0 deletions data/playground/nix/statements.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
key = if a then b else c;
key =
if a
then b
else c;

a = b; # Inline comment (test)
b = c; # Inline comment 2
a = 1 + 1;
a = a/b/c ? 0;
a = b: b + 1;

foo = let
a = b;
c = d;
in
{
output = b;
};

bar = let
a = 1;
b = 2;
in a + b;

bar =
with key;
let
a = key;
in
a;

a = x: x + 1;
b = x: y: x + y + 1;
}
13 changes: 13 additions & 0 deletions data/playground/nix/strings.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
a = "double quoted string";
b = ''two single quote string'';
c = ''
multi-line
quote string'';
d = "Interpolated ${value} string";
e = "Escaped \${string} ";
f = ''
"Nested"
string
'';
}
1 change: 1 addition & 0 deletions packages/common/src/extensionDependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const extensionDependencies = [
"scala-lang.scala", // scala
"mrob95.vscode-talonscript", // talon
"jrieken.vscode-tree-sitter-query", // scm
"bbenoist.nix", // nix
"mathiasfrohlich.kotlin", // kotlin

// Necessary for the `drink cell` and `pour cell` tests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: nix
command:
version: 6
spokenForm: change arg
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: { type: argumentOrParameter }
usePrePhraseSnapshot: true
initialState:
documentContents: |-
{ pkgs, ... }:
{ a = 1; }
selections:
- anchor: { line: 0, character: 10 }
active: { line: 0, character: 10 }
marks: {}
finalState:
documentContents: |-
:
{ a = 1; }
selections:
- anchor: { line: 0, character: 0 }
active: { line: 0, character: 0 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: nix
command:
version: 6
spokenForm: change arg
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: { type: argumentOrParameter }
usePrePhraseSnapshot: true
initialState:
documentContents: |
{ pkgs, ... }:
{ a = 1; }
selections:
- anchor: { line: 0, character: 3 }
active: { line: 0, character: 3 }
marks: {}
finalState:
documentContents: |
:
{ a = 1; }
selections:
- anchor: { line: 0, character: 0 }
active: { line: 0, character: 0 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
languageId: nix
command:
version: 6
spokenForm: change arg
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: { type: argumentOrParameter }
usePrePhraseSnapshot: true
initialState:
documentContents: |
{
outputs = { self, nix-darwin, nixpkgs, home-manager, sops-nix, ... }@inputs:
{};
}
selections:
- anchor: { line: 1, character: 39 }
active: { line: 1, character: 39 }
marks: {}
finalState:
documentContents: |
{
outputs = :
{};
}
selections:
- anchor: { line: 1, character: 14 }
active: { line: 1, character: 14 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
languageId: nix
command:
version: 6
spokenForm: change arg
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: { type: argumentOrParameter }
usePrePhraseSnapshot: true
initialState:
documentContents: |
{
outputs = inputs@{ self, nix-darwin, nixpkgs, home-manager, sops-nix, ... }:
{};
}
selections:
- anchor: { line: 1, character: 44 }
active: { line: 1, character: 44 }
marks: {}
finalState:
documentContents: |
{
outputs = :
{};
}
selections:
- anchor: { line: 1, character: 14 }
active: { line: 1, character: 14 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
languageId: nix
command:
version: 6
spokenForm: change branch
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: { type: branch }
usePrePhraseSnapshot: true
initialState:
documentContents: |-
{
foo = if a then b else c;
}
selections:
- anchor: { line: 1, character: 9 }
active: { line: 1, character: 9 }
marks: {}
finalState:
documentContents: |-
{
foo = else c;
}
selections:
- anchor: { line: 1, character: 8 }
active: { line: 1, character: 8 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
languageId: nix
command:
version: 6
spokenForm: change branch
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: { type: branch }
usePrePhraseSnapshot: true
initialState:
documentContents: |
{
foo = if a
then b
else c;
}
selections:
- anchor: { line: 1, character: 9 }
active: { line: 1, character: 9 }
marks: {}
finalState:
documentContents: |
{
foo =
else c;
}
selections:
- anchor: { line: 1, character: 8 }
active: { line: 1, character: 8 }
Loading
Loading