I have seen this little project .
It shows an example of how to create a Linux kernel module in Nim and how to compile it.
But it only compiles if a modified Nim compiler is used.
My question is:
Is it possible to write a kernel module without having to modify the Nim compiler?
I'm completely ignorant in Nim, but looking at that modification in the Nim compiler I realize (a bit) that it could be replaced by a manually written library for the kernel module.
I found how to override the system definitions: https://forum.nim-lang.org/t/501
Very interesting.
Another question, if I want to insert an elif between an if statement in a compiler builtin library, is it possible to do that without having to copy the .nim file from compiler source and modifying? Such a feature I have never heard about in any programming language.
Sorry Man, Nim is so flexible that anything I imagine I think it's already implemented. ;)
One think I have been perceiving: even not studied the Nim manuals, I can understand 35~40% of Nim code, such a thing never happened with other dynamic languages such as Python and Ruby.
I have been wondering why Nim was not adopted as a C replacement or it was not adopted as a new language for developing kernel modules as it was with Rust.
Thanks.
Don't be silly, it always was possible to build Kernel modules, you could always use --gc:none and importc kalloc and write C style code in Nim with cast and ptr. Now with --gc:arc it's more convenient than ever but it always was possible. You also likely want to use --compileOnly and move the generated C code to where the build system can find it. But this is all not particulary hard, you only need to know what you're doing.
Of course, if you think that you need Nim's XML parser in your kernel module, you probably have trouble but then this is like trying to use GTK in a kernel module.
From what I can see, the modifications in the compiler was only to add a command line facility to the Nim compiler in the Makefile.
That project of @zevv in the Github could be used as a base for writing kernel modules, I think.
From what I can see, the modifications in the compiler was only to add a command line facility to the Nim compiler in the Makefile.
Should be, the compiler switch is the only bit you can't tweak locally. It's pretty nice for developing as all of the stdlib can be modified since it's all compiled at build time.
I've actually wanted to write a kernel module in Nim for a while, but haven't found an excuse ... ahem reason. However from my experience on embedded stuff it should be feasible.
Things from the top of my head:
I'd be up for helping make a PR for supporting Linux kernel kmalloc. Also that'd make a cool blog post for someone for Nim. ;)