kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.42k stars 110 forks source link

[Enhancement] Nix package of KCL CLI and Language Server #1169

Open vfarcic opened 3 months ago

vfarcic commented 3 months ago

Feature Request

Is your feature request related to a problem? Please describe: I tend to use nix-shell for all the projects I work on. That way I create ephemeral environments with all the tools I need without installing any of them permanently on my laptop. kcl CLI is not available as a Nix package.

Describe the feature you'd like: Make kcl available as a Nix package.

Describe alternatives you've considered: Installing it permanently on my laptop.

Teachability, Documentation, Adoption, Migration Strategy: Users can start a session with nix-shell or devbox shell and get the tools they need to work on a project, including kcl.

Peefy commented 3 months ago

Hello @vfarcic

Thank you for your feedback. That's a very good suggestion. Later, I will add it at https://github.com/NixOS/nixpkgs and PRs also welcome. ❤️

Peefy commented 2 months ago

The KCL Nix Package PR: https://github.com/NixOS/nixpkgs/pull/302285 The KCL Language Server Nix Package PR: https://github.com/NixOS/nixpkgs/pull/302286

Peefy commented 2 months ago

The KCL CLI Nix Package PR has been merged 🎉 https://github.com/NixOS/nixpkgs/pull/302488 Note that the Nix community suggests that we use the kcl-cli package, the initial version is 0.8.5. I will update the relevant documents on the KCL website later.

Peefy commented 2 months ago

image

Peefy commented 2 months ago

Thank you @diefans for the kcl-nix package: https://github.com/diefans/kcl-nix

sanzoghenzo commented 2 months ago

Hi, thanks for this! Is there a reason why the kcl-lsp was not added to nix packages? It feels a bit awkward to have kcli cli in nix/devbox, but then having to install the lsp manually to make vscode happy...

Peefy commented 2 months ago

Hello @sanzoghenzo, we have plans to support this, and prior to that, we have done some refactoring and pre work on the kcl-language-server rust project. It is expected that we can provide nix package soon.

Peefy commented 2 months ago

I've opened the kcl-language-server nix package PR at https://github.com/NixOS/nixpkgs/pull/306538

selfuryon commented 2 months ago

Hey! I tried to use kcl-cli from nixpkgs but failed:

$ nix shell nixpkgs#kcl-cli
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish

$ cat main.k 
hello = "KCL"

$  kcl run main.k
Init kcl runtime failed, path:  /home/syakovlev/go
Tip: Have you used a binary version of KCL in your PATH that is not consistent with the KCL Go SDK? You can upgrade or reduce the KCL version or delete the KCL in your PATH
If not, you can run `rm -r /home/syakovlev/go/bin` to fix this issue
panic: unexpected EOF: stderr = Could not start dynamically linked executable: kclvm_cli
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld

goroutine 1 [running]:
kcl-lang.io/kcl-go/pkg/runtime.initRuntime(0xc00093f6d8?)
    kcl-lang.io/kcl-go@v0.8.5/pkg/runtime/init.go:62 +0x42f
kcl-lang.io/kcl-go/pkg/runtime.GetRuntime.func1()
    kcl-lang.io/kcl-go@v0.8.5/pkg/runtime/init.go:26 +0x15
sync.(*Once).doSlow(0x0?, 0x0?)
    sync/once.go:74 +0xc2
sync.(*Once).Do(...)
    sync/once.go:65
kcl-lang.io/kcl-go/pkg/runtime.GetRuntime()
    kcl-lang.io/kcl-go@v0.8.5/pkg/runtime/init.go:26 +0x2c
kcl-lang.io/kcl-go/pkg/service.NewKclvmServiceClient()
    kcl-lang.io/kcl-go@v0.8.5/pkg/service/client_kclvm_service.go:21 +0x13
kcl-lang.io/kcl-go/pkg/kcl.runWithHooks({0xc00093f890, 0x0, 0x0}, {0x5cae350, 0x1, 0x1}, {0xc00093faa8, 0x1, 0x1})
    kcl-lang.io/kcl-go@v0.8.5/pkg/kcl/api.go:477 +0x16e
kcl-lang.io/kcl-go/pkg/kcl.run(...)
    kcl-lang.io/kcl-go@v0.8.5/pkg/kcl/api.go:486
kcl-lang.io/kcl-go/pkg/kcl.RunWithOpts({0xc00093faa8?, 0xc00093faa8?, 0xc00093fa58?})
    kcl-lang.io/kcl-go@v0.8.5/pkg/kcl/api.go:373 +0x45
kcl-lang.io/kpm/pkg/api.RunWithOpt(0xc000b87200)
    kcl-lang.io/kpm@v0.8.5/pkg/api/kpm_run.go:89 +0x36a
kcl-lang.io/cli/pkg/options.(*RunOptions).Run(0xc0008f80e0)
    kcl-lang.io/cli/pkg/options/run.go:126 +0x1e9
kcl-lang.io/cli/cmd/kcl/commands.NewRunCmd.func1(0xc00058c400?, {0xc0005a8990?, 0x4?, 0x2263e4c?})
    kcl-lang.io/cli/cmd/kcl/commands/run.go:49 +0x5a
github.com/spf13/cobra.(*Command).execute(0xc00015e908, {0xc0005a8950, 0x1, 0x1})
    github.com/spf13/cobra@v1.8.0/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc00015e608)
    github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
    github.com/spf13/cobra@v1.8.0/command.go:1039
main.main()
    kcl-lang.io/cli/cmd/kcl/main.go:14 +0x1c

$ kcl version
0.8.6-linux-amd64

That means it isn't a full package of all needed binaries for using kcl, right? I also need kclvm_cli at least? Is it planned to package kclvm_cli too?

I'm a newbie at KCL, just wanted to compare it with CUE, but can't get it work on NixOS still.

Peefy commented 2 months ago

Oh, it seems to conflict with the running mode of nix package management. You can use the download script to get the kcl cli. I will fix it later.

NixOS cannot run dynamically linked executables intended for generic linux environments out of the box. For more information, see: https://nix.dev/permalink/stub-ld

diefans commented 2 months ago

@selfuryon you may try https://github.com/diefans/kcl-nix at least I fixed my problems...

aldoborrero commented 1 week ago

We also need to provide the LSP, after PR nixpkgs#31827 is merged a separate PR will be prepared for tackling that.

diefans commented 1 week ago

@aldoborrero I had problems building the LSP...

I was pointing sourceRoot = "source/kclvm/tools/src/LSP"; but got

error: Permission denied (os error 13) at path "/build/source/kclvm/targetlnQ0hp"

so to me it seems, that the build process wants to modify a "higher" directory, which nix prevents.... IMHO I am wondering, why you have all that tools not in separate repos/crates...

aldoborrero commented 1 week ago

@diefans have you tried using cargoBuildHooks? With that you don't need to point sourceRoot to that specific path (or it shouldn't be the case).