Skip to content

Commit

Permalink
Merge branch 'main' into release/2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Nov 10, 2024
2 parents 05ff3db + 1cf9ec0 commit 0f6f697
Show file tree
Hide file tree
Showing 20 changed files with 123 additions and 57 deletions.
6 changes: 3 additions & 3 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
callPackage
stdenv
;
nix = nixVersions.nix_2_19;
nix = nixVersions.nix_2_24;
llvmPackages = llvmPackages_16;
nixf = callPackage ./libnixf { };
nixt = callPackage ./libnixt { inherit nix; };
Expand Down
6 changes: 6 additions & 0 deletions libnixt/include/nixt/InitEval.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#pragma once

#include <nix/common-eval-args.hh>
#include <nix/eval-gc.hh>
#include <nix/eval-settings.hh>
#include <nix/eval.hh>
#include <nix/flake/flake.hh>
#include <nix/plugin.hh>
#include <nix/shared.hh>
#include <nix/store-api.hh>

Expand All @@ -9,6 +14,7 @@ namespace nixt {
inline void initEval() {
nix::initNix();
nix::initLibStore();
nix::flake::initLib(nix::flakeSettings);
nix::initPlugins();
nix::initGC();
}
Expand Down
6 changes: 3 additions & 3 deletions libnixt/lib/Flake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ void nixt::callDirtyFlake(EvalState &State, std::string_view Src,
nix::Value &VRes) {

nix::Value *VSrc = State.allocValue();
VSrc->mkPath(State.rootPath(nix::CanonPath(Src, nix::CanonPath::fromCwd())));
VSrc->mkPath(State.rootPath(nix::CanonPath(Src)));

auto *VFlakeCompat = State.allocValue();

nix::Expr *EFlakeCompat = State.parseExprFromString(
FlakeCompat, State.rootPath(nix::CanonPath::fromCwd()));
nix::Expr *EFlakeCompat =
State.parseExprFromString(FlakeCompat, State.rootPath("."));
State.eval(EFlakeCompat, *VFlakeCompat);

State.callFunction(*VFlakeCompat, *VSrc, VRes, noPos);
Expand Down
17 changes: 9 additions & 8 deletions libnixt/lib/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ std::optional<nix::Value> nixt::getField(nix::EvalState &State, nix::Value &V,
return std::nullopt;

nix::Symbol SFiled = State.symbols.create(Field);
if (auto *It = V.attrs->find(SFiled); It != V.attrs->end())
if (auto *It = V.attrs()->find(SFiled); It != V.attrs()->end())
return *It->value;

return std::nullopt;
Expand Down Expand Up @@ -86,11 +86,11 @@ nix::Value &nixt::selectAttr(nix::EvalState &State, nix::Value &V,
State.forceValue(V, nix::noPos);

if (V.type() != nix::ValueType::nAttrs)
throw nix::TypeError("value is not an attrset");
throw nix::TypeError(State, "value is not an attrset");

assert(V.attrs && "nix must allocate non-null attrs!");
auto *Nested = V.attrs->find(Attr);
if (Nested == V.attrs->end())
assert(V.attrs() && "nix must allocate non-null attrs!");
auto *Nested = V.attrs()->find(Attr);
if (Nested == V.attrs()->end())
throw nix::AttrPathNotFound("attrname " + State.symbols[Attr] +
" not found in attrset");

Expand Down Expand Up @@ -145,11 +145,12 @@ nix::Value getSubOptions(nix::EvalState &State, nix::Value &Type) {
nix::Value &GetSubOptions =
selectAttr(State, Type, State.symbols.create("getSubOptions"));

nix::Value EmptyList;
EmptyList.mkList(0);
auto list = State.buildList(0);
auto EmptyList = State.allocValue();
EmptyList->mkList(list);
// Invoke "GetSubOptions"
nix::Value VResult;
State.callFunction(GetSubOptions, EmptyList, VResult, nix::noPos);
State.callFunction(GetSubOptions, *EmptyList, VResult, nix::noPos);
return VResult;
}

Expand Down
4 changes: 2 additions & 2 deletions libnixt/lib/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
libnixt_deps = [ nix_expr, nix_main, nix_cmd, boost ]
libnixt_deps = [ nix_expr, nix_flake, nix_main, nix_cmd, boost ]

libnixd_inc = include_directories('../include')

Expand All @@ -19,7 +19,7 @@ pkgconfig.generate(name: 'nixt',
description: 'nix compatible layer',
subdirs: [ 'nixt' ],
libraries: libnixt,
requires: [ 'nix-expr', 'nix-main', 'nix-cmd' ]
requires: [ 'nix-expr', 'nix-main', 'nix-cmd', 'nix-flake' ]
)


Expand Down
1 change: 1 addition & 0 deletions libnixt/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pkgconfig = import('pkgconfig')
nix_main = dependency('nix-main')
nix_expr = dependency('nix-expr')
nix_cmd = dependency('nix-cmd')
nix_flake = dependency('nix-flake')

subdir('lib')
subdir('test')
7 changes: 6 additions & 1 deletion libnixt/test/StateTest.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#include <gtest/gtest.h>

#include <nix/common-eval-args.hh>
#include <nix/eval.hh>
#include <nix/store-api.hh>

namespace nixt {

struct StateTest : testing::Test {
std::unique_ptr<nix::EvalState> State;
StateTest() : State(new nix::EvalState{{}, nix::openStore("dummy://")}) {}
StateTest()
: State(new nix::EvalState{{},
nix::openStore("dummy://"),
nix::fetchSettings,
nix::evalSettings}) {}
};

} // namespace nixt
4 changes: 2 additions & 2 deletions libnixt/test/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using namespace nixt;
namespace {

struct ValueTest : StateTest {
nix::SourcePath cwd() { return State->rootPath(nix::CanonPath::fromCwd()); }
nix::SourcePath cwd() { return State->rootPath("."); }
};

TEST_F(ValueTest, IsOption_neg) {
Expand Down Expand Up @@ -58,7 +58,7 @@ TEST_F(ValueTest, selectAttrPath) {
nix::Value &Kern = selectStringViews(*State, Nested, {"c", "d"});

ASSERT_EQ(Kern.type(), nix::ValueType::nInt);
ASSERT_EQ(Kern.integer, 1);
ASSERT_EQ(Kern.integer(), 1);
}

} // namespace
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ subdir('libnixf/test')
nix_main = dependency('nix-main')
nix_expr = dependency('nix-expr')
nix_cmd = dependency('nix-cmd')
nix_flake = dependency('nix-flake')


subdir('libnixt/lib')
Expand Down
27 changes: 27 additions & 0 deletions nixd/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ nvim_lsp.nixd.setup({
```
</details>

<details>
<summary>Emacs</summary>

Configuration via [lsp-mode](https://github.com/emacs-lsp/lsp-mode) plugin. As of Oct 24, 2024, lsp-mode master has support for nixd autocompletion and formatting options.

```elisp
(use-package nix-mode
:after lsp-mode
:ensure t
:hook
(nix-mode . lsp-deferred) ;; So that envrc mode will work
:custom
(lsp-disabled-clients '((nix-mode . nix-nil))) ;; Disable nil so that nixd will be used as lsp-server
:config
(setq lsp-nix-nixd-server-path "nixd"
lsp-nix-nixd-formatting-command [ "nixfmt" ]
lsp-nix-nixd-nixpkgs-expr "import <nixpkgs> { }"
lsp-nix-nixd-nixos-options-expr "(builtins.getFlake \"/home/nb/nixos\").nixosConfigurations.mnd.options"
lsp-nix-nixd-home-manager-options-expr "(builtins.getFlake \"/home/nb/nixos\").homeConfigurations.\"nb@mnd\".options"))
(add-hook! 'nix-mode-hook
;; enable autocompletion with company
(setq company-idle-delay 0.1))
```
</details>

### Configuration overview

> [!NOTE]
Expand Down
17 changes: 16 additions & 1 deletion nixd/docs/editor-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ According to `:help coc-config.txt`, `coc-settings.json`:
### Neovim

Neovim native LSP and [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig).
We are officially supported by nvim-lspconfig, see [upstream docs](https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.txt#nixd)
We are officially supported by nvim-lspconfig, see [upstream docs](https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.txt#nixd)

### Emacs

Expand Down Expand Up @@ -110,6 +110,21 @@ A simple Emacs Lisp configuration that adds nixd to LSP Mode in the mean time is
:server-id 'nixd)))
```

### Helix

`nixd` will be supported by default in the next release after 24.07.

#### languages.toml

```toml
[[language]]
name = "nix"
language-servers = ["nixd","nil"]

[language-server.nixd]
command = "nixd"
```

## Change the configuration.

Read the [configuration](configuration.md) docs here.
4 changes: 3 additions & 1 deletion nixd/docs/editors/vscodium.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ pkgs ? import <nixpkgs> { } }:
{
pkgs ? import <nixpkgs> { },
}:
with pkgs;
let
codium = vscode-with-extensions.override {
Expand Down
27 changes: 17 additions & 10 deletions nixd/docs/examples/NixOS_Home-Manager/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
flake-parts.url = "github:hercules-ci/flake-parts";
};

outputs = inputs@{ self, flake-parts, ... }:
outputs =
inputs@{ self, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
debug = true;

Expand All @@ -23,12 +24,15 @@
hostname = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
({ pkgs, ... }: {
networking.hostName = "hostname";
environment.systemPackages = with pkgs; [
nixd
];
})
(
{ pkgs, ... }:
{
networking.hostName = "hostname";
environment.systemPackages = with pkgs; [
nixd
];
}
)
];
};
};
Expand All @@ -42,9 +46,12 @@
home.username = "user";
home.homeDirectory = "/home/user";
}
({ pkgs, ... }: {
wayland.windowManager.hyprland.enable = true;
})
(
{ pkgs, ... }:
{
wayland.windowManager.hyprland.enable = true;
}
)
];
};
};
Expand Down
2 changes: 1 addition & 1 deletion nixd/lib/Controller/Definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class WorkerReportedException : std::exception {
llvm::Error E;

public:
WorkerReportedException(llvm::Error E) : E(std::move(E)){};
WorkerReportedException(llvm::Error E) : E(std::move(E)) {};

llvm::Error takeError() { return std::move(E); }
[[nodiscard]] const char *what() const noexcept override {
Expand Down
Loading

0 comments on commit 0f6f697

Please sign in to comment.