[[!meta date="2024-07-19 14:33"]]
[[!tag nix nixos libnix fixPath]]
[[!series libnix]]
[[!summary libnix roadmap]]
[[!img media/nlnet-logo.gif class="noFancy" style="float: right"]]
[[!img posts/libnix/Nix_snowflake_windows.svg class="noFancy" style="float: right" width="200px"]]
# motivation
status of **native windows nix using MinGW** from my series [libnix](https://lastlog.de/blog/timeline.html?filter=series::libnix)
we also cover these topics:
* libnix: **why we picked MinGW** vs. other solutions
* general roadmap
# libnix: MinGW vs. other solutions
making **nix work native on windows** there are a few options, here are a few updates reaching out to these communities:
## Tvix
[tvix](https://tvix.dev/) is a rust reimplementation of the c++ nix implementation, recent news:
* **store implementation** since [last update](https://tvl.fyi/blog/tvix-update-february-24)
* **nix evaluation** comes close to upstream c++ nix, however, still effort to get to 100%
* not all **builtins** are supported yet
* no builders yet
* could be used to **replace the tour of nix emscripten based backend** but not much more
**too early for considering tvix to 'building software using nix' on windows**. tvix is amazing, i hope one day this code base replaces the c++ one.
## cosmopolitan
[cosmopolitan](https://justine.lol/cosmopolitan/) developers on discord mentioned to me that they had tried porting nix with cosmopolitan:
> ariel nunez: Bash on windows was only possible last year, after a lot of work by jart and contributors, and now Windows Terminal Preview can use it.
> I read my logs and last attempt to compile Nix was on August 2023, at that point in time we found out Nix used Boost and that was a blocker at the time.
the **cosmopolitan idea** has a lot of potential. i'm uncertain of OS specific traits and how well they map to this POSIX generalization. for instance, when normalizing paths with
std::filesystem it is decided on compile time for which platform the paths resolve. cosmopolitan runs on all systems, so std::filesystem would have to make this choice a runtime resolution instead.
**but for now i probably follow the john ericson / volth path with MinGW.**
## MinGW
[MinGW](https://en.wikipedia.org/wiki/MinGW) cross compiler setup:
* using `mingw cross compiler from nixos-wsl` to build nix for windows
* john ericson's MinGW contributions are ongoing and promising ~early 2024
the toolchain is neatly done! in particular we want to use instead of gcc/ld.
so **lld/clang** will be used:
* to build nix
* nixpkgs toolchain to build c/c++ programs for windows
# libnix: general roadmap
here is a list of things which need to be done still, see for detailed tickets.
## 1. meson build system
* in order to build nix on windows natively, we need a build system which is not tied to bash. therefore meson is a good candidate for this and there have been a couple of patches already.
## 2. create test suite for nix on windows
* adapt unix specific tests to work on windows
* write windows specific tests for symlinks / path length / permissions and such
* run them in [wine](https://winehq.org) / docker windows
## 3. assemble prototype windows bootstrap system
* make `nix` evaluate on windows use the store on `c:\` and
* get `runProgram` working to execute tools like `git` for `fetchUrl`
* use third-party built tools from MSYS2 (not built by nix)
## 4. build 'hello world' nixpkgs-win
* minimal nixpkgs like abstraction
* instead of trying to adapt nixpkgs we should start small with our own `stdenv` with `mingw` to show how to use it
## 5. make nix + toolchain build from windows
* use the prototype toolchain to built itself
* adapt `bash` and unix favoring build systems into a windows world
## 6. nix installer / channel
* create an **installer for nix**
* create a nix **channel**
* create a channel for windows
## 7. cargo with nix support
* we start with `rust/cargo` on linux to make it work with nix as backend, see for this
# libnix: future nix work
these items need to be done outside of the [libnix](https://nlnet.nl/project/libnix/) funding but are still worth mentioning.
## 1. sandboxing
* process isolation in windows, for sandboxing `nix-build`, see
## 2. user environments (pure powershell environment)
* `source $HOME/.nix-profile/etc/profile.d/nix.sh` for powershell
## 3. nix-daemon & multi user mode
* nix-daemon
* calls `nix-build` (with different UID/GID)
* windows **unix domain socket support** can be used
## 4. nixos module system `systemd` like windows abstraction
* the nixos module system creates `systemd` targets on linux and it would be nice if we had something similar for windows, see [systemd equivalent on windows](https://www.reddit.com/r/selfhosted/comments/8ijs26/systemdlike_to_create_windows_services_from/)
## 5. store interoperability
* think `/nix/store` vs. `c:\nix\store`
* - Use std::filesystem::path for Path
* - Encoding store Paths on Windows and Unix
## 6. usability & documentation
* support `nix repl`
* support `man pages` in `nix build --help`
* ...
# summary
this is a **short summary of libnix topics what we are aiming for till the end of 2024**.
additional we think that **llvm-mingw** is a potent toolchain for windows which enables us to use [fixPath](https://github.com/nixcloud/fixPath).