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

Unable to run kcl 0.10.x on NixOS #153

Open
diefans opened this issue Oct 17, 2024 · 7 comments · Fixed by #154
Open

Unable to run kcl 0.10.x on NixOS #153

diefans opened this issue Oct 17, 2024 · 7 comments · Fixed by #154

Comments

@diefans
Copy link

diefans commented Oct 17, 2024

Bug Report

I am using NixOS, where the directories of packages are readonly.

The kcl installer v0.10.3 seems to try to create a directory kcl under $KCL_LIB_HOME

panic: mkdir /nix/store/kyhhm0yx0h7ckrjzx28kazvp8vmx237c-kclvm-0.10.3/lib/kcl: read-only file system

goroutine 1 [running]:
kcl-lang.io/lib/go/native.initClient.func1()
	kcl-lang.io/[email protected]/go/native/client.go:41 +0x147
sync.(*Once).doSlow(0xa75e28?, 0x1ea3020?)
	sync/once.go:76 +0xb4
sync.(*Once).Do(...)
	sync/once.go:67
kcl-lang.io/lib/go/native.initClient(0x1ea2f40?)
	kcl-lang.io/[email protected]/go/native/client.go:38 +0x3a
kcl-lang.io/lib/go/native.NewNativeServiceClientWithPluginAgent(...)
	kcl-lang.io/[email protected]/go/native/client.go:62
kcl-lang.io/lib/go/native.NewNativeServiceClient()
	kcl-lang.io/[email protected]/go/native/client.go:58 +0x29
kcl-lang.io/kcl-go/pkg/kcl.Service(...)
	kcl-lang.io/[email protected]/pkg/kcl/service.go:10
kcl-lang.io/kcl-go/pkg/kcl.runWithHooks({0xc000867728, 0x0, 0x0}, {0x3b47dd0, 0x1, 0x1}, {0xc0008677f8, 0x1, 0x1})
	kcl-lang.io/[email protected]/pkg/kcl/api.go:436 +0x15f
kcl-lang.io/kcl-go/pkg/kcl.run(...)
	kcl-lang.io/[email protected]/pkg/kcl/api.go:445
kcl-lang.io/kcl-go/pkg/kcl.RunWithOpts({0xc0008677f8?, 0xc000000fc0?, 0x0?})
	kcl-lang.io/[email protected]/pkg/kcl/api.go:372 +0x45
kcl-lang.io/kpm/pkg/client.(*KpmClient).Run.func1(0xc000000fc0)
	kcl-lang.io/[email protected]/pkg/client/run.go:599 +0x3aa
kcl-lang.io/kpm/pkg/client.(*PkgVisitor).Visit(0xc000550638, 0x0?, 0xc00086ca20)
	kcl-lang.io/[email protected]/pkg/client/visitor.go:52 +0x62
kcl-lang.io/kpm/pkg/client.(*KpmClient).Run(0xc0008726e0, {0xc000867bc0, 0xe, 0x90?})
	kcl-lang.io/[email protected]/pkg/client/run.go:574 +0x20d
kcl-lang.io/cli/pkg/options.(*RunOptions).Run(0xc00018b400)
	kcl-lang.io/cli/pkg/options/run.go:128 +0x6a5
kcl-lang.io/cli/cmd/kcl/commands.NewRunCmd.func1(0xc000510400?, {0xc0004f4a10?, 0x4?, 0x23d698b?})
	kcl-lang.io/cli/cmd/kcl/commands/run.go:61 +0x49
github.com/spf13/cobra.(*Command).execute(0xc00045ec08, {0xc0004f4930, 0x7, 0x7})
	github.com/spf13/[email protected]/command.go:985 +0xaaa
github.com/spf13/cobra.(*Command).ExecuteC(0xc00045e908)
	github.com/spf13/[email protected]/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:1041
main.main()
	kcl-lang.io/cli/cmd/kcl/main.go:14 +0x2a
make: *** [makefile:12: search.lti] Error 2

This commit was introducing it: 3c73ffd

1. Minimal reproduce step (Required)

build kcl v0.10.3 for nix and run it, so that the internal installer is called...

IMHO for NixOS the whole installer and caching thingy should be disabled since there is not much "dynamic" expected in terms of installing/downloading/caching the kclvm library... Or there should be some pre-fetch/prepare stage for this cache, which then gets commited into the nix package.

@Peefy Peefy mentioned this issue Oct 18, 2024
2 tasks
@Peefy
Copy link
Contributor

Peefy commented Oct 18, 2024

Thanks for the feedback.

#154 Can this modification solve the problem of creating subfolders?

@diefans
Copy link
Author

diefans commented Oct 23, 2024

Hey @Peefy your fix is only solving half of the issue, and I would like to reopen this issue. The application now tries to create a lockfile in the readonly directories:

panic: open /nix/store/kyhhm0yx0h7ckrjzx28kazvp8vmx237c-kclvm-0.10.3/lib/install.lock: read-only file system

IMHO the application should perform its "userspace business" wholly somewhere in ${XDG_CACHE_HOME} resp. ${HOME}/.cache. The assumption to have write permission in the library directory cannot be hold.

Despite all that, thank you for your efforts!

@Peefy Peefy reopened this Oct 24, 2024
@Peefy Peefy changed the title Unable to run kcl 0.10.3 on NixOS Unable to run kcl 0.10.x on NixOS Oct 24, 2024
@Peefy
Copy link
Contributor

Peefy commented Oct 24, 2024

@diefans Thank you!

e4b1362

Do you mean I should modify it this way?

@diefans
Copy link
Author

diefans commented Oct 24, 2024

@Peefy I think the problem is related to the override of the libPath by env var KCL_LIB_HOME, which in the NixOS case points to a readonly directory.

In https://github.com/kcl-lang/lib/blob/main/go/native/loader.go#L31-L34 the libPath() call result gets overridden and points to this readonly directory. So maybe the definition of KCL_LIB_HOME in https://github.com/NixOS/nixpkgs/blob/master/pkgs/by-name/kc/kcl/package.nix#L49 is not right...

@Peefy
Copy link
Contributor

Peefy commented Oct 24, 2024

@diefans Thank you! 👍

Do you mean we should modify the KCL nix configuration here?

@diefans
Copy link
Author

diefans commented Oct 24, 2024

The following patch will fix the issue for NixOS

diff --git a/pkgs/by-name/kc/kcl/package.nix b/pkgs/by-name/kc/kcl/package.nix
index 0200265bb6d6..fe9d71af73f6 100644
--- a/pkgs/by-name/kc/kcl/package.nix
+++ b/pkgs/by-name/kc/kcl/package.nix
@@ -11,16 +11,16 @@
 }:
 buildGo123Module rec {
   pname = "kcl";
-  version = "0.10.0";
+  version = "0.10.6";

   src = fetchFromGitHub {
     owner = "kcl-lang";
     repo = "cli";
     rev = "v${version}";
-    hash = "sha256-0KxT4t77EDB7Vr/cb+P20ARRR+7g5uZiF5QYOArUhgI=";
+    hash = "sha256-NyqiypzKjMcT61bEjUHa1QGyeoJtcx78qzch9sdgn2k=";
   };

-  vendorHash = "sha256-9APQDYCBvG38y0ZYuacfyUmjoEV9jGqRg7OZ7mArzIU=";
+  vendorHash = "sha256-uFtEKIPL052BwN7NdIvgoQWR4EbVMoMKkQ3cvd2S0Ww=";

   # By default, libs and bins are stripped. KCL will crash on darwin if they are.
   dontStrip = stdenv.isDarwin;
@@ -46,7 +46,6 @@ buildGo123Module rec {
   postFixup = ''
      wrapProgram $out/bin/kcl \
     --prefix PATH : "${lib.makeBinPath [kclvm kclvm_cli]}" \
-    --prefix KCL_LIB_HOME : "${lib.makeLibraryPath [kclvm]}" \
     --prefix KCL_GO_DISABLE_INSTALL_ARTIFACT : false
   '';

While digging into the code I am also quite confident now, that the env vars for disabling certain installer features are not longer respected: https://github.com/kcl-lang/kcl-go/blob/main/pkg/env/env.go#L33-L34 see kcl-lang/kcl-go#259
At least a code search shows only the implementation of the setting, but no usage: https://github.com/search?q=repo%3Akcl-lang%2Fkcl-go%20GetDisableInstallArtifact&type=code

@Peefy
Copy link
Contributor

Peefy commented Oct 24, 2024

Thanks for the feedback. This config will be deprecated in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants