Nix on Windows?

The problem was not compile llvm successfully but to calculate sha256 for fetchurl and friends without losing files. In llvm case those dangling links are among test cases (and that is why they are so weird intentionally), their disappearance does not hurt the build. But affects hashes.

1 Like

Also GitHub - google/zx: A tool for writing better scripts

apparently there are posix shells that work on windows: GitHub - AdaCore/gsh: A POSIX shell for Windows.

1 Like

May I add Lua to the list?
It is very small
It is very fast
It is easy to bootstrap
Its syntax could be better, if that’s a deal-breaker stuff like moon/yue script exist (GitHub - hengestone/lua-languages: Languages that compile to Lua)


Last time I seen Lua, it was compiled for Windows using MinGW.
So the same problem as Python and Perl (when without special Windows libs): no paths longer than 255 chars and bad symlink support.

I am a fan of Lua for this too. GitHub - rjpcomputing/luaforwindows: Lua for Windows is a 'batteries included environment' for the Lua scripting language on Windows. NOTICE: Looking for maintainer. shows MSVC lua is no problem.

Absence of function to get size of a set in both Nix and Lua reveals some influence :slight_smile:

There is no problems with MSVC. Perl, Python (and probably even Bash) can be compiled by MSVC.

The problem is the filesystem library must support long file names and symlinks (including dangling and recursive).

Remember, there is no reliable cp -r on Windows. All software I tested: from built-in copy and xcopy through MinGW bash and coreutils, to 3-rd party robocopy do fail on doing cp -r with real-world directory structure which has both long filenames, recursive symlinks and non-printable characters (such as checked out LLVM and Chromium monorepos), so cp -r, ln -s, … have been written in Perl with some external modules (and even this choice required patches in C code of those modules).

The test question for Lua, Rakudo, NodeJs, … is as such: can it be used to write cp -r and ln -s which won’t fail on long filenames, recursive symlinks and non-printable characters ?


On Linux, I am currently on stripped Nixpkgs with only ~3000 packages to ease maintainability.
Anyway, it has lost compatibility with mainstream Nix (it small nuances, like { name = "xx"; = "yy"; } is verboten). I will try to replace bash with something else, keeping in mind eventual merging that Nixpkgs-lite/Linux with Nixpkgs/Window. So far, Rakudo is the cutest but a bit exotic option. JavaScript is more practical.

1 Like

Sounded nice as first, though: Running scripts without extensions errors if they are on a RO filesystem · Issue #176 · google/zx · GitHub

Therefore a bit nasty to deal with when on nix.

Even leaving Windows aside, there is a need for a scripting language to replace Bash in builtins.exec (why? 1. bash alone is not enough, bash does almost nothing except running other program, which have to be build somehow … so it quickly evolves to maintaining another “bootstraping” copy of <nixpkgs> for programs to run in builtins.exec 2. safety. builtins.exec code runs under user account and can do weird things, Nix own scripting engine could limit what paths the code can access, etc. Guix can happily use Scheme everywhere, but we have to use Bash every time when we need imperative code). As an embedded scripting language, it has to use the I/O functions used by Nix and therefore works in Windows if Nix is running there. And it gives us additional options to choose the language: there are much more embedded languages than standalone ones. But here 1:1 type matching with Nix would be desirable, and it is the weak point of JavaScript which lacks Int64.

1 Like

Just to note: although Ruby does not support Windows well, Chef made the work to support UTF-16 strings, long file names and symlinks:

So Ruby looks like a good candidate to replace Bash in build scripts. Maybe on Linux too.

It has bigger fan base than Perl, and… Homebrew uses Ruby - that might simplify copy-pasting of buildPhase from there

PS: also, embedding MRuby into Nix might allow syntax like

buildPhase = do
   # ruby code here

instead of concatenating opaque strings with Bash inside (“do” can also be read as “here begins something imperative” by people used to Haskell)


don’t you need admin access to create symlinks on Windows? this basically ruins any attempt at scripting symlinks, and why msys2 has a really bad workaround (it copies files instead).

IMHO adding an imperative DSL directly to nix makes the most sense, why can’t we just use nix directly instead of using an alternative language, embedded inside a nix-script?

Python is terrible for scripting external apps, I really hate using the subprocess module.

To make another bad suggestion: how about haskell-turtle? Turtle.Tutorial


yes, it needs elevated privileges, but we need to get them anyway to create C:\nix

And you only need it once, because the permissions w/r/t creating symlinks on Windows is configurable. You could have the Nix installer grant those permissions to the build users

Nobody answered your question.

why can’t we just use nix directly instead of using an alternative language, embedded inside a nix-script?

1 Like

Nix is a pure expression language. It has no runtime that could cause arbitrary side-effects like invoking a compiler.

Some sort of light-weight functional language which does have one would be really cool to at least have as an option for use inside a derivation though IMO.

Echoing others; I want to use Nix professionally but a massive portion of my users won’t bite until it supports windows natively. WSL, and WSL2 are not installed on machines by default and require users to create a new mental model of their machine.


Nix is already a new “mental model” and in many aspects much bigger than WSL2 on windows. WSL2 seems to become pretty typical software to be installed. I have positive experience advertising and deploying NixOS for professional usage on WSL2 for employees on windows. Though, if it’s about selling products with Nix as a deployment tool then WSL2 is hardly an option and you’re much better off compile with Nix mingw cross-toolchain.


Yes, besides the compiler CI that is my main shortter term goal for Nix on Windows, I am interested in getting Nix working on regular non-developer Nix machines for e.g, dreams like allowing governments to migrate to free software more incrementally. So this “regular user, no time for WSL” use-case is I think is important and not to be dismissed.


Agreed but I can get someone to install a binary and execute one command easier than I can get them to install WSL, create a new linux user, pick a wsl shell, understand where in the heck they are in the filesystem, and then install nix and learn a whole other mental model.