Nix as openscad package manager

Openscad is a pure functional (similar to nix) language for designing 3d objects. It is a unique program in it’s class. Other cad tools are visual and have graphical interface which is not so reusable and humans can make errors. So openscad is a cool software.

What openscad lacks is a package manager. Openscad has good module system but if you want to use an external library, you should copy its files in your project or install it globally (similar to C somehow)

Will nix be a good choice for native package manager in openscad? Or it has too much overhead? Build step and reproducible build simply does not make sense in openscad because 3D objects are visible with human eyes. (There is a export step to for example stl file, but everyone wants to configure that manually) So what we want from package management is just installing packages by their id (for example their name in NixPkgs or OpenscadPkgs) automatically and not pollute global namespace.

Is nix good for this propose? Please share your thought here or in this issue about package management in openscad. Thank you.

2 Likes

Something to note: it says Openscad works on Windows, but Nix does not have a Windows implementation.

3 Likes

That’s a problem, but is the only one? In this case it is ok I think and WSL and similar are come to my mind.

I’m very new to nix. In openscad, there is a global store of libraries (For example $HOME/.local/share/OpenSCAD/libraries/) Is it possible to have isolated packages with dependencies with nix in a user-friendly way without change the code of openscad? User-friendly means with no hash or global address in the user’s openscad code for importing package.

You could probably make a tool which is “nix aware” and able to create some symlinks into that directory. But I don’t think nix would be able to do this by default. However, Nix is capable of building any arbitrarily large dependency tree and realizing it as a store path.

example workflow

# install
nix_path=$(nix-build <nixpkgs> -A openscadPackages.<pkg> )
# prevent nix-collect-garbage from cleaning it up
nix-store --add-root "$nix_path"
# add to user's env
ln -s "$nix_path" $HOME/.local/share/OpenSCAD/libraries/<pkg>
2 Likes

In your example workflow, how we can solve global namespace polluting? And so you suggest a tool like scadpm that scadpm install xxx add xxx to package expression and then run that script?

What global namespace are you worried about polluting?