{ lib, config, pkgs, ... }: with lib; let cfg = config.custom.wsl; in { options.custom.wsl.enable = mkEnableOption "Enable WSL2 settings"; config = mkIf cfg.enable { # Enable native Docker support virtualisation.docker.enable = true; # Antigravity's install script needs these symlinked into /usr/bin wsl.extraBin = [ {src = "${pkgs.coreutils}/bin/dirname";} {src = "${pkgs.coreutils}/bin/readlink";} {src = "${pkgs.coreutils}/bin/uname";} {src = "${pkgs.coreutils}/bin/mkdir";} {src = "${pkgs.coreutils}/bin/rm";} {src = "${pkgs.coreutils}/bin/wc";} {src = "${pkgs.coreutils}/bin/date";} {src = "${pkgs.coreutils}/bin/mv";} {src = "${pkgs.coreutils}/bin/sleep";} {src = "${pkgs.gnutar}/bin/tar";} {src = "${pkgs.gzip}/bin/gzip";} {src = "${pkgs.wget}/bin/wget";} # Antigravity uses this to download the server {src = "${pkgs.procps}/bin/ps";} # Used for process health checks ]; # Standard nix-ld is now very stable and works with Antigravity/VS Code # It solves the "Could not start dynamically linked executable" error programs.nix-ld = { enable = true; libraries = with pkgs; [ stdenv.cc.cc zlib fuse3 icu nss openssl curl expat libxml2 ]; }; wsl = { enable = true; wslConf.automount.root = "/mnt"; defaultUser = "sstent"; startMenuLaunchers = true; wslConf.network.generateResolvConf = false; # nativeSystemd = true; # Enable if you need complex service management }; # Fix for /dev/shm (shared memory) for Electron-based tools like Antigravity systemd.services.nixs-wsl-systemd-fix = { description = "Fix the /dev/shm symlink to be a mount"; unitConfig = { DefaultDependencies = "no"; Before = [ "sysinit.target" "systemd-tmpfiles-setup-dev.service" "systemd-tmpfiles-setup.service" "systemd-sysctl.service" ]; ConditionPathExists = "/dev/shm"; ConditionPathIsSymbolicLink = "/dev/shm"; ConditionPathIsMountPoint = "/run/shm"; }; serviceConfig = { Type = "oneshot"; ExecStart = [ "${pkgs.coreutils-full}/bin/rm /dev/shm" "/run/wrappers/bin/mount --bind -o X-mount.mkdir /run/shm /dev/shm" ]; }; wantedBy = ["sysinit.target"]; }; }; }