From 0bdefdd1ee44d476fa1bb1e542bb02561103ed81 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sat, 3 Jan 2026 09:23:12 -0400 Subject: [PATCH 001/119] nixos: add cygwin system builder --- nixos/maintainers/scripts/cygwin/profile.nix | 94 ++++++++++++ nixos/maintainers/scripts/cygwin/system.nix | 76 ++++++++++ nixos/maintainers/scripts/cygwin/tarball.nix | 146 +++++++++++++++++++ nixos/release.nix | 26 ++++ 4 files changed, 342 insertions(+) create mode 100644 nixos/maintainers/scripts/cygwin/profile.nix create mode 100644 nixos/maintainers/scripts/cygwin/system.nix create mode 100644 nixos/maintainers/scripts/cygwin/tarball.nix diff --git a/nixos/maintainers/scripts/cygwin/profile.nix b/nixos/maintainers/scripts/cygwin/profile.nix new file mode 100644 index 0000000000000..2ccc1be8bec6a --- /dev/null +++ b/nixos/maintainers/scripts/cygwin/profile.nix @@ -0,0 +1,94 @@ +{ + lib, + pkgs, + config, + ... +}: + +{ + imports = [ + ../../../modules/profiles/minimal.nix + ]; + + config = lib.mkIf pkgs.stdenv.hostPlatform.isCygwin { + boot = { + bcache.enable = false; + initrd = { + supportedFilesystems = [ ]; + }; + kernel.sysctl = lib.mkForce { }; + loader.grub.enable = false; + modprobeConfig.enable = false; + supportedFilesystems = [ ]; + }; + + console.enable = false; + + fonts.fontconfig.enable = false; + + # the default requires glibcLocales + i18n.supportedLocales = [ ]; + + networking = { + dhcpcd.enable = false; + firewall.enable = false; + resolvconf.enable = false; + }; + + programs = { + fuse.enable = false; + less.enable = lib.mkForce false; + nano.enable = false; + ssh.systemd-ssh-proxy.enable = false; + }; + + security = { + pam.enable = false; + shadow.enable = false; + sudo.enable = false; + }; + + services = { + lvm.enable = false; + udev.enable = false; + }; + + system = { + disableInstallerTools = true; + # this is needed because tasks/filesystems.nix unconditionally adds + # dosfstools, and tasks/filesystems/ext adds e2fsprogs + fsPackages = lib.mkForce [ ]; + # these match the cygwin defaults when "file" is prepended + nssDatabases = { + passwd = [ "db" ]; + group = [ "db" ]; + }; + }; + + systemd = { + enable = false; + coredump.enable = false; + }; + + users = { + users = lib.mkForce { }; + groups = lib.mkForce { }; + }; + + environment.corePackages = + with pkgs; + lib.mkForce [ + bash + coreutils + openssh + curl + config.nix.package + ]; + environment.defaultPackages = lib.mkForce [ ]; + + nix = { + settings.sandbox = false; + package = pkgs.nixVersions.git; + }; + }; +} diff --git a/nixos/maintainers/scripts/cygwin/system.nix b/nixos/maintainers/scripts/cygwin/system.nix new file mode 100644 index 0000000000000..56027a7678959 --- /dev/null +++ b/nixos/maintainers/scripts/cygwin/system.nix @@ -0,0 +1,76 @@ +{ + lib, + pkgs, + config, + ... +}: + +let + inherit (pkgs) + bash + buildEnv + coreutils + runCommand + writeShellScript + cygwin + ; + + nix = config.nix.package; + + sw = buildEnv { + name = "cygwin-root"; + + paths = config.environment.systemPackages; + + nativeBuildInputs = [ + ../../../../pkgs/build-support/setup-hooks/make-symlinks-relative.sh + ]; + }; + + activate = writeShellScript "activate" '' + ( + export PATH=${ + lib.makeBinPath [ + coreutils + nix + ] + }:/bin + mkdir -p /nix/var/nix/gcroots + ln -sfn /run/current-system /nix/var/nix/gcroots/current-system + mkdir -p /run + ln -sfn '${lib.getExe bash}' /bin/sh + ln -sfn '@out@' /run/current-system + ln -sfn /run/current-system/etc /etc + if [[ -f /nix-path-registration ]]; then + nix-store --load-db < /nix-path-registration + rm -f /nix-path-registration + fi + ) + ''; + + cygwin1 = cygwin.newlib-cygwin.out + "/bin/cygwin1.dll"; + +in +{ + options = { + system.cygwin.toplevel = lib.mkOption { + type = lib.types.package; + readOnly = true; + }; + }; + + imports = [ + ./profile.nix + ]; + + config = { + system.cygwin.toplevel = runCommand "cygwin-system" { } '' + mkdir "$out" + ln -sr "${sw}" "$out"/sw + ln -sr "${cygwin1}" "$out"/ + cp "${activate}" "$out"/activate + substituteInPlace $out/activate --subst-var-by out "$out" + ln -sr "${config.system.build.etc}"/etc $out/etc + ''; + }; +} diff --git a/nixos/maintainers/scripts/cygwin/tarball.nix b/nixos/maintainers/scripts/cygwin/tarball.nix new file mode 100644 index 0000000000000..3f05487b18d77 --- /dev/null +++ b/nixos/maintainers/scripts/cygwin/tarball.nix @@ -0,0 +1,146 @@ +{ + lib, + pkgs, + config, + ... +}: + +let + inherit (pkgs) + bash + buildPackages + cygwin + gnutar + lib + runCommand + writeShellScript + writeText + ; + + nix = config.nix.package; + + bootScript = writeText "cygwin.ps1" ( + lib.replaceString "\n" "\r\n" '' + $ErrorActionPreference = 'Stop' + cp $PSScriptRoot\nix\var\nix\profiles\system\cygwin1.dll $PSScriptRoot\bin\cygwin1.dll + $bash = "$PSScriptRoot${lib.replaceString "/" "\\" (lib.getBin bash).outPath}\bin\bash.exe" + & $bash /nix/var/nix/profiles/system/activate + if (!$?) { throw 'activation script failed' } + & $bash --login -i $args + if (!$?) { exit 1 } + '' + ); + + cygwin1 = cygwin.newlib-cygwin.out + "/bin/cygwin1.dll"; + +in +{ + options.system.cygwin.tarball = lib.mkOption { + type = lib.types.package; + readOnly = true; + }; + + config = { + environment.etc."profile".text = '' + export CYGWIN=winsymlinks=native\ $CYGWIN + ''; + + system.cygwin = { + + tarball = + let + install = writeText "install.ps1" ( + lib.replaceString "\n" "\r\n" '' + param ([Parameter(Mandatory=$true)][string]$dir) + + $ErrorActionPreference = 'Stop' + + $_ = mkdir -force $dir + + fsutil file setCaseSensitiveInfo $dir enable + if (!$?) { throw 'setCaseSensitiveInfo failed, this may require: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux' } + + $_ = ni $dir\.test-target + try { + cmd /c mklink $dir\.test-link $dir\.test-target + if (!$?) { + throw 'failed to create symbolic link: developer mode may need to be enabled' + } + } catch { + throw + } finally { + rm $dir\.test-target + } + rm $dir\.test-link + + $env:CYGWIN = "winsymlinks=native" + # create cygwin1.dll so that symlinks to it are created properly + if(!(Test-Path $dir\bin\cygwin1.dll)) + { + mkdir -f $dir\bin + ni $dir\bin\cygwin1.dll + } + & $PSScriptRoot\tar -C $dir --force-local -xpf $PSScriptRoot\${config.system.cygwin.tarball.fileName}.tar${config.system.cygwin.tarball.extension} + if (!$?) { throw 'failed to extract tarball' } + '' + ); + + system = config.system.cygwin.toplevel; + in + (pkgs.callPackage ../../../lib/make-system-tarball.nix { + # HACK: disable compression + compressCommand = "cat"; + compressionExtension = ""; + + contents = [ + { + source = bootScript; + target = "cygwin.ps1"; + } + ]; + + storeContents = [ + { + object = system; + symlink = "none"; + } + ]; + + extraCommands = buildPackages.writeShellScript "extra-commands.sh" '' + chmod -R +w nix + mkdir -p tmp nix/var/nix/profiles dev + mkdir -m 01777 dev/{shm,mqueue} + ln -s "$(realpath -s --relative-to=/nix/var/nix/profiles "${system}")" nix/var/nix/profiles/system + find . -type l -print0 | while read -r -d "" f; do + symlinkTarget=$(readlink "$f") + if [[ "$symlinkTarget"/ != /nix/store* ]]; then + # skip this symlink as it doesn't point to /nix/store + continue + fi + + relativeTarget=''${symlinkTarget#/} + + if [ ! -e "$relativeTarget" ]; then + echo "the symlink $f is broken, it points to $relativeTarget (which is missing)" + fi + + relativeTarget=$(realpath -s --relative-to=$(dirname "$f") "$relativeTarget") + + echo "changing symlink $f -> $symlinkTarget to $relativeTarget" + ln -snf "$relativeTarget" "$f" + done + + mkdir -p "$out"/tarball + cp "${install}" "$out"/tarball/install.ps1 + cp "${gnutar}/bin/tar.exe" "$out"/tarball/ + for dll in "${gnutar}/bin"/*.dll; do + if [[ $dll != */cygwin1.dll ]]; then + cp "$dll" "$out"/tarball/ + fi + done + cp "${cygwin1}" "$out"/tarball/ + ''; + }); + }; + }; +} diff --git a/nixos/release.nix b/nixos/release.nix index 0fcc22981be53..da1d79ffba2d9 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -456,6 +456,32 @@ rec { ) ); + cygwinTarball = + forMatchingSystems + [ + "x86_64-linux" + "aarch64-linux" + ] + ( + system: + + hydraJob ( + (import lib/eval-config.nix { + system = null; + modules = [ + configuration + versionModule + ./maintainers/scripts/cygwin/system.nix + ./maintainers/scripts/cygwin/tarball.nix + { + nixpkgs.buildPlatform = lib.mkDefault system; + nixpkgs.hostPlatform = lib.mkDefault "x86_64-cygwin"; + } + ]; + }).config.system.cygwin.tarball + ) + ); + # Ensure that all packages used by the minimal NixOS config end up in the channel. dummy = forAllSystems ( system: From e99eb7954707fcee25a840f071cb6cc9d7173e1e Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 4 Jan 2026 20:45:54 -0400 Subject: [PATCH 002/119] WIP: module changes for cygwin compatibility --- nixos/modules/security/pam.nix | 6 +++++- nixos/modules/system/boot/systemd.nix | 6 +++++- nixos/modules/system/boot/systemd/tmpfiles.nix | 2 +- nixos/modules/system/boot/systemd/user.nix | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/nixos/modules/security/pam.nix b/nixos/modules/security/pam.nix index 176a8e4c79eb8..243ee343db823 100644 --- a/nixos/modules/security/pam.nix +++ b/nixos/modules/security/pam.nix @@ -1656,6 +1656,10 @@ in options = { + security.pam.enable = lib.mkEnableOption "enable pam" // { + default = true; + }; + security.pam.package = lib.mkPackageOption pkgs "pam" { }; security.pam.loginLimits = lib.mkOption { @@ -2277,7 +2281,7 @@ in ###### implementation - config = { + config = lib.mkIf config.security.pam.enable { assertions = [ { assertion = config.users.motd == "" || config.users.motdFile == null; diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index 7a606afcdd9db..f76c6860f697a 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -240,6 +240,10 @@ in options.systemd = { + enable = mkEnableOption "enable systemd" // { + default = true; + }; + package = mkPackageOption pkgs "systemd" { }; enableStrictShellChecks = mkEnableOption "" // { @@ -484,7 +488,7 @@ in ###### implementation - config = { + config = mkIf cfg.enable { warnings = let diff --git a/nixos/modules/system/boot/systemd/tmpfiles.nix b/nixos/modules/system/boot/systemd/tmpfiles.nix index 12eca48f945d4..8b34ba7cf28d2 100644 --- a/nixos/modules/system/boot/systemd/tmpfiles.nix +++ b/nixos/modules/system/boot/systemd/tmpfiles.nix @@ -192,7 +192,7 @@ in }; }; - config = { + config = lib.mkIf config.systemd.enable { warnings = let paths = lib.filter (path: path != null && lib.hasPrefix "/etc/tmpfiles.d/" path) ( diff --git a/nixos/modules/system/boot/systemd/user.nix b/nixos/modules/system/boot/systemd/user.nix index d9a9631fba92f..f9f52cc640363 100644 --- a/nixos/modules/system/boot/systemd/user.nix +++ b/nixos/modules/system/boot/systemd/user.nix @@ -191,7 +191,7 @@ in }; }; - config = { + config = lib.mkIf config.systemd.enable { systemd.additionalUpstreamSystemUnits = [ "user.slice" ]; From f7e1862abcd5b074f9f89377cec5e54c94b93722 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Wed, 22 Oct 2025 15:16:08 -0300 Subject: [PATCH 003/119] nixos/modules: move nix options from nix-daemon module to nix This breaks the dependency and allows the nix module to be used without nix-daemon. --- nixos/modules/config/nix.nix | 18 ++++++++++++++++++ nixos/modules/services/system/nix-daemon.nix | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/nixos/modules/config/nix.nix b/nixos/modules/config/nix.nix index 9dfc4a1e664e7..bc30e9c5a2024 100644 --- a/nixos/modules/config/nix.nix +++ b/nixos/modules/config/nix.nix @@ -135,6 +135,24 @@ in options = { nix = { + enable = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Whether to enable Nix. + Disabling Nix makes the system hard to modify and the Nix programs and configuration will not be made available by NixOS itself. + ''; + }; + + package = lib.mkOption { + type = lib.types.package; + default = pkgs.nix; + defaultText = lib.literalExpression "pkgs.nix"; + description = '' + This option specifies the Nix package instance to use throughout the system. + ''; + }; + checkConfig = mkOption { type = types.bool; default = true; diff --git a/nixos/modules/services/system/nix-daemon.nix b/nixos/modules/services/system/nix-daemon.nix index ef740b9ba8d94..ce09d339fb1f7 100644 --- a/nixos/modules/services/system/nix-daemon.nix +++ b/nixos/modules/services/system/nix-daemon.nix @@ -70,24 +70,6 @@ in nix = { - enable = lib.mkOption { - type = lib.types.bool; - default = true; - description = '' - Whether to enable Nix. - Disabling Nix makes the system hard to modify and the Nix programs and configuration will not be made available by NixOS itself. - ''; - }; - - package = lib.mkOption { - type = lib.types.package; - default = pkgs.nix; - defaultText = lib.literalExpression "pkgs.nix"; - description = '' - This option specifies the Nix package instance to use throughout the system. - ''; - }; - daemonCPUSchedPolicy = lib.mkOption { type = lib.types.enum [ "other" From 32513838422d99438ef558180edb192cfae06abb Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sat, 13 Sep 2025 21:01:31 -0300 Subject: [PATCH 004/119] libarchive: fix cygwin build --- .../li/libarchive/fix-cygwin-build.patch | 64 +++++++++++++++++++ pkgs/by-name/li/libarchive/package.nix | 11 +++- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 pkgs/by-name/li/libarchive/fix-cygwin-build.patch diff --git a/pkgs/by-name/li/libarchive/fix-cygwin-build.patch b/pkgs/by-name/li/libarchive/fix-cygwin-build.patch new file mode 100644 index 0000000000000..d7947f62875b8 --- /dev/null +++ b/pkgs/by-name/li/libarchive/fix-cygwin-build.patch @@ -0,0 +1,64 @@ +--- origsrc/libarchive-3.8.1/libarchive/archive_platform.h 2025-03-20 10:48:34.000000000 +0100 ++++ src/libarchive-3.8.1/libarchive/archive_platform.h 2025-03-29 08:56:00.759008500 +0100 +@@ -62,7 +62,7 @@ + #endif + + /* For cygwin, to avoid missing LONG, ULONG, PUCHAR, ... definitions */ +-#ifdef __CYGWIN__ ++#ifdef __BOGUS_CYGWIN__ + #include + #endif + +--- origsrc/libarchive-3.8.1/configure.ac ++++ src/libarchive-3.8.1/configure.ac +@@ -93,13 +93,10 @@ + + dnl Compilation on mingw and Cygwin needs special Makefile rules + inc_windows_files=no +-inc_cygwin_files=no + case "$host_os" in + *mingw* ) inc_windows_files=yes ;; +- *cygwin* | *msys*) inc_cygwin_files=yes ;; + esac + AM_CONDITIONAL([INC_WINDOWS_FILES], [test $inc_windows_files = yes]) +-AM_CONDITIONAL([INC_CYGWIN_FILES], [test $inc_cygwin_files = yes]) + + dnl Defines that are required for specific platforms (e.g. -D_POSIX_SOURCE, etc) + PLATFORMCPPFLAGS= +@@ -256,7 +253,7 @@ + + # Set up defines needed before including any headers + case $host in +- *mingw* | *cygwin* | *msys* ) ++ *msys* ) + AC_PREPROC_IFELSE([AC_LANG_PROGRAM( + [[#include + #ifdef _WIN32_WINNT +@@ -414,7 +411,7 @@ + if test "x$with_bz2lib" != "xno"; then + AC_CHECK_HEADERS([bzlib.h]) + case "$host_os" in +- *mingw* | *cygwin* | *msys*) ++ *mingw* | *msys*) + dnl AC_CHECK_LIB cannot be used on the Windows port of libbz2, therefore + dnl use AC_LINK_IFELSE. + AC_MSG_CHECKING([for BZ2_bzDecompressInit in -lbz2]) +@@ -1293,7 +1290,7 @@ + ]) + + case "$host_os" in +- *mingw* | *cygwin* | *msys*) ++ *mingw* | *msys*) + ;; + *) + CRYPTO_CHECK(MD5, LIBC, md5) +@@ -1390,7 +1387,7 @@ + fi + + case "$host_os" in +- *mingw* | *cygwin* | *msys*) ++ *mingw* | *msys*) + CRYPTO_CHECK_WIN(MD5, CALG_MD5) + CRYPTO_CHECK_WIN(SHA1, CALG_SHA1) + CRYPTO_CHECK_WIN(SHA256, CALG_SHA_256) + diff --git a/pkgs/by-name/li/libarchive/package.nix b/pkgs/by-name/li/libarchive/package.nix index b622460ec1b8c..3ea255beecdca 100644 --- a/pkgs/by-name/li/libarchive/package.nix +++ b/pkgs/by-name/li/libarchive/package.nix @@ -65,6 +65,12 @@ stdenv.mkDerivation (finalAttrs: { # bsdcpio: linkfile: large inode number truncated: Numerical result out of range "cpio/test/test_basic.c" "cpio/test/test_format_newc.c" + ] + ++ lib.optionals stdenv.hostPlatform.isCygwin [ + "libarchive/test/test_write_disk_lookup.c" + "cpio/test/test_owner_parse.c" + "cpio/test/test_option_c.c" + "cpio/test/test_option_L_upper.c" ]; removeTest = testPath: '' substituteInPlace Makefile.am --replace-fail "${testPath}" "" @@ -113,7 +119,10 @@ stdenv.mkDerivation (finalAttrs: { configureFlags = lib.optional (!xarSupport) "--without-xml2"; # https://github.com/libarchive/libarchive/issues/1475 - doCheck = !stdenv.hostPlatform.isMusl; + doCheck = + !stdenv.hostPlatform.isMusl + # TODO: investigate cygwin tests + && !stdenv.hostPlatform.isCygwin; preCheck = '' # Need an UTF-8 locale for test_I test. From 01aea59d921cd5f6e19520f4e35348720b3f5ee6 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 23 Oct 2025 15:02:07 -0300 Subject: [PATCH 005/119] cygwin-dll-link: fix indentation --- .../setup-hooks/cygwin-dll-link.sh | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh index d5724794921dc..8a409a8a488c5 100644 --- a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh +++ b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh @@ -1,6 +1,6 @@ addLinkDLLPaths() { - addToSearchPath "LINK_DLL_FOLDERS" "$1/lib" - addToSearchPath "LINK_DLL_FOLDERS" "$1/bin" + addToSearchPath "LINK_DLL_FOLDERS" "$1/lib" + addToSearchPath "LINK_DLL_FOLDERS" "$1/bin" } addEnvHooks "$targetOffset" addLinkDLLPaths @@ -15,33 +15,33 @@ addOutputDLLPaths() { postInstallHooks+=(addOutputDLLPaths) _dllDeps() { - "$OBJDUMP" -p "$1" \ - | sed -n 's/.*DLL Name: \(.*\)/\1/p' \ - | sort -u + "$OBJDUMP" -p "$1" \ + | sed -n 's/.*DLL Name: \(.*\)/\1/p' \ + | sort -u } _linkDeps() { - local target="$1" dir="$2" check="$3" - echo 'target:' "$target" - local dll - _dllDeps "$target" | while read dll; do - echo ' dll:' "$dll" - if [[ -e "$dir/$dll" ]]; then continue; fi - # Locate the DLL - it should be an *executable* file on $LINK_DLL_FOLDERS. - local dllPath="$(PATH="$(dirname "$target"):$LINK_DLL_FOLDERS" type -P "$dll")" - if [[ -z "$dllPath" ]]; then - if [[ -z "$check" || -n "${allowedImpureDLLsMap[$dll]}" ]]; then - continue - fi - echo unable to find $dll in $LINK_DLL_FOLDERS >&2 - exit 1 - fi - echo ' linking to:' "$dllPath" - CYGWIN+=\ winsymlinks:nativestrict ln -sr "$dllPath" "$dir" - # That DLL might have its own (transitive) dependencies, - # so add also all DLLs from its directory to be sure. - _linkDeps "$dllPath" "$dir" "" - done + local target="$1" dir="$2" check="$3" + echo 'target:' "$target" + local dll + _dllDeps "$target" | while read dll; do + echo ' dll:' "$dll" + if [[ -e "$dir/$dll" ]]; then continue; fi + # Locate the DLL - it should be an *executable* file on $LINK_DLL_FOLDERS. + local dllPath="$(PATH="$(dirname "$target"):$LINK_DLL_FOLDERS" type -P "$dll")" + if [[ -z "$dllPath" ]]; then + if [[ -z "$check" || -n "${allowedImpureDLLsMap[$dll]}" ]]; then + continue + fi + echo unable to find $dll in $LINK_DLL_FOLDERS >&2 + exit 1 + fi + echo ' linking to:' "$dllPath" + CYGWIN+=\ winsymlinks:nativestrict ln -sr "$dllPath" "$dir" + # That DLL might have its own (transitive) dependencies, + # so add also all DLLs from its directory to be sure. + _linkDeps "$dllPath" "$dir" "" + done } linkDLLs() { From 7a637ea30707a3753a169b08e627b2edbed0cd44 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 11 Sep 2025 17:07:40 -0300 Subject: [PATCH 006/119] tzdata: fix cygwin build --- pkgs/by-name/tz/tzdata/fix-cygwin-build.patch | 50 +++++++++++++++++++ pkgs/by-name/tz/tzdata/package.nix | 8 +-- 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 pkgs/by-name/tz/tzdata/fix-cygwin-build.patch diff --git a/pkgs/by-name/tz/tzdata/fix-cygwin-build.patch b/pkgs/by-name/tz/tzdata/fix-cygwin-build.patch new file mode 100644 index 0000000000000..022371afc5739 --- /dev/null +++ b/pkgs/by-name/tz/tzdata/fix-cygwin-build.patch @@ -0,0 +1,50 @@ +diff --git a/Makefile b/Makefile +index 2130582..9a97470 100644 +--- a/Makefile ++++ b/Makefile +@@ -642,7 +642,7 @@ VERSION_DEPS= \ + ziguard.awk zishrink.awk \ + zone.tab zone1970.tab zonenow.tab + +-all: tzselect zic zdump libtz.a $(TABDATA) \ ++all: tzselect zic.exe zdump.exe libtz.a $(TABDATA) \ + vanguard.zi main.zi rearguard.zi + + ALL: all date $(ENCHILADA) +@@ -658,8 +658,8 @@ install: all $(DATA) $(REDO) $(MANS) + -t '$(DESTDIR)$(TZDEFAULT)' + cp -f $(TABDATA) '$(DESTDIR)$(TZDIR)/.' + cp tzselect '$(DESTDIR)$(BINDIR)/.' +- cp zdump '$(DESTDIR)$(ZDUMPDIR)/.' +- cp zic '$(DESTDIR)$(ZICDIR)/.' ++ cp zdump.exe '$(DESTDIR)$(ZDUMPDIR)/.' ++ cp zic.exe '$(DESTDIR)$(ZICDIR)/.' + cp libtz.a '$(DESTDIR)$(LIBDIR)/.' + $(RANLIB) '$(DESTDIR)$(LIBDIR)/libtz.a' + cp -f newctime.3 newtzset.3 '$(DESTDIR)$(MANDIR)/man3/.' +@@ -727,10 +727,10 @@ version.h: version + >$@.out + mv $@.out $@ + +-zdump: $(TZDOBJS) ++zdump.exe: $(TZDOBJS) + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZDOBJS) $(LDLIBS) + +-zic: $(TZCOBJS) ++zic.exe: $(TZCOBJS) + $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(TZCOBJS) $(LDLIBS) + + leapseconds: $(LEAP_DEPS) +diff --git a/private.h b/private.h +index 074da28..6f8b50d 100644 +--- a/private.h ++++ b/private.h +@@ -299,7 +299,7 @@ extern int optind; + #ifndef HAVE_ISSETUGID + # if (defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \ + || (defined __linux__ && !defined __GLIBC__) /* Android, musl, etc. */ \ +- || (defined __APPLE__ && defined __MACH__) || defined __sun) ++ || (defined __APPLE__ && defined __MACH__) || defined __sun || defined __CYGWIN__) + # define HAVE_ISSETUGID 1 + # else + # define HAVE_ISSETUGID 0 diff --git a/pkgs/by-name/tz/tzdata/package.nix b/pkgs/by-name/tz/tzdata/package.nix index 146b46dc230d2..5378cc27d32cb 100644 --- a/pkgs/by-name/tz/tzdata/package.nix +++ b/pkgs/by-name/tz/tzdata/package.nix @@ -23,9 +23,11 @@ stdenv.mkDerivation (finalAttrs: { sourceRoot = "."; - patches = lib.optionals stdenv.hostPlatform.isWindows [ - ./0001-Add-exe-extension-for-MS-Windows-binaries.patch - ]; + patches = + lib.optionals stdenv.hostPlatform.isWindows [ + ./0001-Add-exe-extension-for-MS-Windows-binaries.patch + ] + ++ lib.optional stdenv.hostPlatform.isCygwin ./fix-cygwin-build.patch; outputs = [ "out" From 0703769cfcefb3a6f8ac2a8a06b90b03e46d7990 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 15 Sep 2025 08:54:31 -0300 Subject: [PATCH 007/119] meson: use system=cygwin for cygwin cross --- pkgs/build-support/lib/meson.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/lib/meson.nix b/pkgs/build-support/lib/meson.nix index e6ae12392eecb..535344d177cf8 100644 --- a/pkgs/build-support/lib/meson.nix +++ b/pkgs/build-support/lib/meson.nix @@ -24,7 +24,9 @@ let needs_exe_wrapper = ${boolToString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform)} [host_machine] - system = '${stdenv.targetPlatform.parsed.kernel.name}' + system = '${ + if stdenv.targetPlatform.isCygwin then "cygwin" else stdenv.targetPlatform.parsed.kernel.name + }' cpu_family = '${cpuFamily stdenv.targetPlatform}' cpu = '${stdenv.targetPlatform.parsed.cpu.name}' endian = ${if stdenv.targetPlatform.isLittleEndian then "'little'" else "'big'"} From 333f6c1662a0e29d32fbab74b739599f088f197d Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 15 Sep 2025 11:00:39 -0300 Subject: [PATCH 008/119] nix: fix cygwin build --- .../nix/modular/packaging/components.nix | 9 +- .../nix/modular/packaging/everything.nix | 10 +- .../nix/modular/src/libstore/package.nix | 3 +- .../Disable-MonitorFdHup-test-on-cygwin.patch | 23 ++ .../Fix-leak-in-EvalState-evalFile.patch | 56 +++++ ..._api_store_test.nix_eval_state_looku.patch | 33 +++ ...e_test.nix_eval_state_lookup_path-wh.patch | 34 +++ ...tringPrimOpTest.toString-10-on-cygwi.patch | 30 +++ .../patches/Recreate-symlinks-on-cygwin.patch | 79 +++++++ .../Remove-static-data-from-headers.patch | 203 ++++++++++++++++++ .../Suppress-xattr-errors-on-Cygwin.patch | 32 +++ .../nix/patches/fix-cygwin-build.patch | 35 +++ ...ix-leak-in-nix_api_store_test.nix_ap.patch | 25 +++ ...x-openFileEnsureBeneathNoSymlinks.wo.patch | 32 +++ 14 files changed, 600 insertions(+), 4 deletions(-) create mode 100644 pkgs/tools/package-management/nix/patches/Disable-MonitorFdHup-test-on-cygwin.patch create mode 100644 pkgs/tools/package-management/nix/patches/Fix-leak-in-EvalState-evalFile.patch create mode 100644 pkgs/tools/package-management/nix/patches/Fix-leaks-in-nix_api_store_test.nix_eval_state_looku.patch create mode 100644 pkgs/tools/package-management/nix/patches/Fix-nix_api_store_test.nix_eval_state_lookup_path-wh.patch create mode 100644 pkgs/tools/package-management/nix/patches/Fix-toString-ToStringPrimOpTest.toString-10-on-cygwi.patch create mode 100644 pkgs/tools/package-management/nix/patches/Recreate-symlinks-on-cygwin.patch create mode 100644 pkgs/tools/package-management/nix/patches/Remove-static-data-from-headers.patch create mode 100644 pkgs/tools/package-management/nix/patches/Suppress-xattr-errors-on-Cygwin.patch create mode 100644 pkgs/tools/package-management/nix/patches/fix-cygwin-build.patch create mode 100644 pkgs/tools/package-management/nix/patches/libflake-tests-fix-leak-in-nix_api_store_test.nix_ap.patch create mode 100644 pkgs/tools/package-management/nix/patches/libutil-tests-fix-openFileEnsureBeneathNoSymlinks.wo.patch diff --git a/pkgs/tools/package-management/nix/modular/packaging/components.nix b/pkgs/tools/package-management/nix/modular/packaging/components.nix index 02b927df5a23f..21bf2de14edbe 100644 --- a/pkgs/tools/package-management/nix/modular/packaging/components.nix +++ b/pkgs/tools/package-management/nix/modular/packaging/components.nix @@ -277,7 +277,14 @@ in /** Patches for the whole Nix source. Changes to packaging expressions will be ignored. */ - patches = [ ]; + patches = lib.optionals stdenv.hostPlatform.isCygwin [ + ../../patches/Include-bin-in-builder-PATH-on-cygwin.patch + ../../patches/Suppress-xattr-errors-on-Cygwin.patch + ../../patches/Recreate-symlinks-on-cygwin.patch + ../../patches/libutil-tests-fix-openFileEnsureBeneathNoSymlinks.wo.patch + ../../patches/Fix-leak-in-EvalState-evalFile.patch + ../../patches/libflake-tests-fix-leak-in-nix_api_store_test.nix_ap.patch + ]; /** Fetched and patched source to be used in component derivations. */ diff --git a/pkgs/tools/package-management/nix/modular/packaging/everything.nix b/pkgs/tools/package-management/nix/modular/packaging/everything.nix index 62873710bcf39..b93c0c1a99995 100644 --- a/pkgs/tools/package-management/nix/modular/packaging/everything.nix +++ b/pkgs/tools/package-management/nix/modular/packaging/everything.nix @@ -46,6 +46,8 @@ testers, patchedSrc ? null, + + enableDocumentation ? !stdenv.buildPlatform.isCygwin, }: let @@ -106,6 +108,8 @@ stdenv.mkDerivation (finalAttrs: { outputs = [ "out" "dev" + ] + ++ lib.optionals enableDocumentation [ "doc" "man" ]; @@ -173,6 +177,8 @@ stdenv.mkDerivation (finalAttrs: { for lib in ${lib.escapeShellArgs devPaths}; do lndir $lib $dev done + '' + + lib.optionalString enableDocumentation '' # Forwarded outputs ln -sT ${nix-manual} $doc @@ -231,8 +237,8 @@ stdenv.mkDerivation (finalAttrs: { platforms = nix-cli.meta.platforms; outputsToInstall = [ "out" - "man" - ]; + ] + ++ lib.optional enableDocumentation "man"; pkgConfigModules = [ "nix-cmd" "nix-expr" diff --git a/pkgs/tools/package-management/nix/modular/src/libstore/package.nix b/pkgs/tools/package-management/nix/modular/src/libstore/package.nix index 6c5978bfd7e88..3039120e37dc2 100644 --- a/pkgs/tools/package-management/nix/modular/src/libstore/package.nix +++ b/pkgs/tools/package-management/nix/modular/src/libstore/package.nix @@ -25,7 +25,8 @@ withAWS ? # Default is this way because there have been issues building this dependency - lib.meta.availableOn stdenv.hostPlatform aws-c-common, + # TODO: aws-crt-cpp is broken on cygwin, find a good way to check that here + lib.meta.availableOn stdenv.hostPlatform aws-c-common && !stdenv.hostPlatform.isCygwin, }: mkMesonLibrary (finalAttrs: { diff --git a/pkgs/tools/package-management/nix/patches/Disable-MonitorFdHup-test-on-cygwin.patch b/pkgs/tools/package-management/nix/patches/Disable-MonitorFdHup-test-on-cygwin.patch new file mode 100644 index 0000000000000..f245833c509c6 --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/Disable-MonitorFdHup-test-on-cygwin.patch @@ -0,0 +1,23 @@ +From 48620255d396771e6da6458b77f2a438bf289ee7 Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Sat, 15 Nov 2025 20:12:15 -0400 +Subject: [PATCH] Disable MonitorFdHup test on cygwin + +--- + src/libutil-tests/monitorfdhup.cc | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/libutil-tests/monitorfdhup.cc b/src/libutil-tests/monitorfdhup.cc +index d591b2fed..02cd7e22c 100644 +--- a/src/libutil-tests/monitorfdhup.cc ++++ b/src/libutil-tests/monitorfdhup.cc +@@ -1,4 +1,5 @@ +-#ifndef _WIN32 ++// TODO: investigate why this is hanging on cygwin ++#if !defined(_WIN32) && !defined(__CYGWIN__) + + # include "nix/util/util.hh" + # include "nix/util/monitor-fd.hh" +-- +2.51.0 + diff --git a/pkgs/tools/package-management/nix/patches/Fix-leak-in-EvalState-evalFile.patch b/pkgs/tools/package-management/nix/patches/Fix-leak-in-EvalState-evalFile.patch new file mode 100644 index 0000000000000..04203c365333d --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/Fix-leak-in-EvalState-evalFile.patch @@ -0,0 +1,56 @@ +From 868b29c39a7c2e2dd8722a9e7208f193779a9e05 Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Fri, 9 Jan 2026 15:53:46 -0400 +Subject: [PATCH] Fix leak in EvalState::evalFile + +--- + src/libexpr/eval.cc | 4 ++-- + src/libexpr/include/nix/expr/eval.hh | 4 ++++ + 2 files changed, 6 insertions(+), 2 deletions(-) + +diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc +index 84f14198f..40f0b4b7b 100644 +--- a/src/libexpr/eval.cc ++++ b/src/libexpr/eval.cc +@@ -1129,14 +1129,14 @@ void EvalState::evalFile(const SourcePath & path, Value & v, bool mustBeTrivial) + // https://github.com/NixOS/nix/pull/13930 is merged. That will ensure + // the post-condition that `expr` is unreachable after + // `forceValue()` returns. +- auto expr = new ExprParseFile{*resolvedPath, mustBeTrivial}; ++ auto expr = parseFileExprs.emplace_back(std::make_shared(*resolvedPath, mustBeTrivial)); + + fileEvalCache->try_emplace_and_cvisit( + *resolvedPath, + nullptr, + [&](auto & i) { + vExpr = allocValue(); +- vExpr->mkThunk(&baseEnv, expr); ++ vExpr->mkThunk(&baseEnv, expr.get()); + i.second = vExpr; + }, + [&](auto & i) { vExpr = i.second; }); +diff --git a/src/libexpr/include/nix/expr/eval.hh b/src/libexpr/include/nix/expr/eval.hh +index b70c9db78..ae6e32505 100644 +--- a/src/libexpr/include/nix/expr/eval.hh ++++ b/src/libexpr/include/nix/expr/eval.hh +@@ -366,6 +366,8 @@ private: + Statistics stats; + }; + ++struct ExprParseFile; ++ + class EvalState : public std::enable_shared_from_this + { + public: +@@ -508,6 +510,8 @@ private: + */ + const ref regexCache; + ++ std::vector > parseFileExprs; ++ + public: + + /** +-- +2.52.0 + diff --git a/pkgs/tools/package-management/nix/patches/Fix-leaks-in-nix_api_store_test.nix_eval_state_looku.patch b/pkgs/tools/package-management/nix/patches/Fix-leaks-in-nix_api_store_test.nix_eval_state_looku.patch new file mode 100644 index 0000000000000..25f031351af52 --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/Fix-leaks-in-nix_api_store_test.nix_eval_state_looku.patch @@ -0,0 +1,33 @@ +From eaadc7eb7cf0efb16b388592d598bb5569214b47 Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Sat, 15 Nov 2025 15:35:02 -0400 +Subject: [PATCH] Fix leaks in nix_api_store_test.nix_eval_state_lookup_path + +--- + src/libexpr-tests/nix_api_expr.cc | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/libexpr-tests/nix_api_expr.cc b/src/libexpr-tests/nix_api_expr.cc +index 02f99675e..3e5cd0d43 100644 +--- a/src/libexpr-tests/nix_api_expr.cc ++++ b/src/libexpr-tests/nix_api_expr.cc +@@ -42,12 +42,16 @@ TEST_F(nix_api_expr_test, nix_eval_state_lookup_path) + nix_expr_eval_from_string(ctx, state, "builtins.seq ", ".", value); + assert_ctx_ok(); + ++ nix_state_free(state); ++ + ASSERT_EQ(nix_get_type(ctx, value), NIX_TYPE_PATH); + assert_ctx_ok(); + + auto pathStr = nix_get_path_string(ctx, value); + assert_ctx_ok(); + ASSERT_EQ(0, strcmp(pathStr, nixpkgs.c_str())); ++ ++ nix_gc_decref(nullptr, value); + } + + TEST_F(nix_api_expr_test, nix_expr_eval_from_string) +-- +2.51.0 + diff --git a/pkgs/tools/package-management/nix/patches/Fix-nix_api_store_test.nix_eval_state_lookup_path-wh.patch b/pkgs/tools/package-management/nix/patches/Fix-nix_api_store_test.nix_eval_state_lookup_path-wh.patch new file mode 100644 index 0000000000000..40e5e8cf3bbc3 --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/Fix-nix_api_store_test.nix_eval_state_lookup_path-wh.patch @@ -0,0 +1,34 @@ +From c5f0d294e5c21ef333b4cd1e5d0135acd8398c24 Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Sat, 15 Nov 2025 14:02:35 -0400 +Subject: [PATCH 1/2] Fix nix_api_store_test.nix_eval_state_lookup_path when + run on its own + +Currently, --gtest_filter=nix_api_store_test.nix_eval_state_lookup_path +will result in: + + terminating due to unexpected unrecoverable internal error: Assertion + 'gcInitialised' failed in void nix::assertGCInitialized() at + ../src/libexpr/eval-gc.cc:138 + +Changing the test fixture to _exr_test causes GC to be initialised. +--- + src/libexpr-tests/nix_api_expr.cc | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/libexpr-tests/nix_api_expr.cc b/src/libexpr-tests/nix_api_expr.cc +index de508b4e4..02f99675e 100644 +--- a/src/libexpr-tests/nix_api_expr.cc ++++ b/src/libexpr-tests/nix_api_expr.cc +@@ -14,7 +14,7 @@ + + namespace nixC { + +-TEST_F(nix_api_store_test, nix_eval_state_lookup_path) ++TEST_F(nix_api_expr_test, nix_eval_state_lookup_path) + { + auto tmpDir = nix::createTempDir(); + auto delTmpDir = std::make_unique(tmpDir, true); +-- +2.51.0 + diff --git a/pkgs/tools/package-management/nix/patches/Fix-toString-ToStringPrimOpTest.toString-10-on-cygwi.patch b/pkgs/tools/package-management/nix/patches/Fix-toString-ToStringPrimOpTest.toString-10-on-cygwi.patch new file mode 100644 index 0000000000000..70894c49b3c41 --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/Fix-toString-ToStringPrimOpTest.toString-10-on-cygwi.patch @@ -0,0 +1,30 @@ +From a91a74b3dbbb5cd9e9372b99694e5bdc83c648bd Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Sat, 15 Nov 2025 17:10:21 -0400 +Subject: [PATCH] Fix toString/ToStringPrimOpTest.toString/10 on cygwin + +--- + src/libexpr-tests/primops.cc | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/src/libexpr-tests/primops.cc b/src/libexpr-tests/primops.cc +index f00b4f475..48f9aee72 100644 +--- a/src/libexpr-tests/primops.cc ++++ b/src/libexpr-tests/primops.cc +@@ -662,7 +662,12 @@ INSTANTIATE_TEST_SUITE_P( + CASE(R"({ v = "bar"; __toString = self: self.v; })", "bar"), + CASE(R"({ v = "bar"; __toString = self: self.v; outPath = "foo"; })", "bar"), + CASE(R"({ outPath = "foo"; })", "foo"), +- CASE(R"(./test)", "/test"))); ++ CASE(R"(./test)", ++// canonPath("//./test", false) on cygwin returns //./test ++#ifdef __CYGWIN__ ++ "//." ++#endif ++ "/test"))); + #undef CASE + + TEST_F(PrimOpTest, substring) +-- +2.51.0 + diff --git a/pkgs/tools/package-management/nix/patches/Recreate-symlinks-on-cygwin.patch b/pkgs/tools/package-management/nix/patches/Recreate-symlinks-on-cygwin.patch new file mode 100644 index 0000000000000..93737739b7b2a --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/Recreate-symlinks-on-cygwin.patch @@ -0,0 +1,79 @@ +From 501ecb34ff06f4fedd900e661a46c294c2a90e02 Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Fri, 26 Dec 2025 15:04:26 -0400 +Subject: [PATCH] Recreate symlinks on cygwin + +--- + src/libstore/posix-fs-canonicalise.cc | 28 +++++++++++++++++++++++++-- + 1 file changed, 26 insertions(+), 2 deletions(-) + +diff --git a/src/libstore/posix-fs-canonicalise.cc b/src/libstore/posix-fs-canonicalise.cc +index 7c7a60e87..1a00999a3 100644 +--- a/src/libstore/posix-fs-canonicalise.cc ++++ b/src/libstore/posix-fs-canonicalise.cc +@@ -15,6 +15,18 @@ namespace nix { + + const time_t mtimeStore = 1; /* 1 second into the epoch */ + ++static void makeDirectoryWritable(const Path & path, const struct stat & st) ++{ ++ if (!S_ISDIR(st.st_mode)) ++ return; ++ ++ mode_t mode = st.st_mode | 0220; ++ if (mode != st.st_mode) { ++ if (chmod(path.c_str(), mode) == -1) ++ throw SysError("changing mode of '%1%' to %2$o", path, mode); ++ } ++} ++ + static void canonicaliseTimestampAndPermissions(const Path & path, const struct stat & st) + { + if (!S_ISLNK(st.st_mode)) { +@@ -63,6 +75,14 @@ static void canonicalisePathMetaData_( + + auto st = lstat(path); + ++#if __CYGWIN__ ++ // replace all symlinks to ensure native symlinks can be created ++ if (S_ISLNK(st.st_mode)) { ++ auto target = readLink(path); ++ replaceSymlink(target, path); ++ } ++#endif ++ + /* Really make sure that the path is of a supported type. */ + if (!(S_ISREG(st.st_mode) || S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))) + throw Error("file '%1%' has an unsupported type", path); +@@ -114,8 +134,6 @@ static void canonicalisePathMetaData_( + + inodesSeen.insert(Inode(st.st_dev, st.st_ino)); + +- canonicaliseTimestampAndPermissions(path, st); +- + #ifndef _WIN32 + /* Change ownership to the current uid. If it's a symlink, use + lchown if available, otherwise don't bother. Wrong ownership +@@ -134,6 +152,10 @@ static void canonicalisePathMetaData_( + } + #endif + ++#if __CYGWIN__ ++ makeDirectoryWritable(path, st); ++#endif ++ + if (S_ISDIR(st.st_mode)) { + for (auto & i : DirectoryIterator{path}) { + checkInterrupt(); +@@ -145,6 +167,8 @@ static void canonicalisePathMetaData_( + inodesSeen); + } + } ++ ++ canonicaliseTimestampAndPermissions(path, st); + } + + void canonicalisePathMetaData( +-- +2.51.2 + diff --git a/pkgs/tools/package-management/nix/patches/Remove-static-data-from-headers.patch b/pkgs/tools/package-management/nix/patches/Remove-static-data-from-headers.patch new file mode 100644 index 0000000000000..83f87646ca3b7 --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/Remove-static-data-from-headers.patch @@ -0,0 +1,203 @@ +From 1b5af49fd0e3bc9c047054bd95c1c749d10b8d7c Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Wed, 12 Nov 2025 19:52:29 -0400 +Subject: [PATCH] Remove static data from headers + +We don't want to duplicate any of these across libraries, which is what +happens when the platform doesn't support unique symbols. +--- + src/libcmd/command.cc | 13 +++++++++++++ + src/libcmd/include/nix/cmd/command.hh | 6 +----- + src/libcmd/include/nix/cmd/legacy.hh | 6 +----- + src/libexpr/include/nix/expr/primops.hh | 6 +----- + src/libexpr/include/nix/expr/print-options.hh | 2 +- + src/libexpr/primops.cc | 6 ++++++ + src/libstore/builtins/buildenv.cc | 6 ++++++ + src/libstore/include/nix/store/builtins.hh | 6 +----- + src/libutil/config-global.cc | 6 ++++++ + src/libutil/include/nix/util/config-global.hh | 6 +----- + 10 files changed, 37 insertions(+), 26 deletions(-) + +diff --git a/src/libcmd/command.cc b/src/libcmd/command.cc +index 6b6bbe345..b06d40902 100644 +--- a/src/libcmd/command.cc ++++ b/src/libcmd/command.cc +@@ -2,6 +2,7 @@ + #include + + #include "nix/cmd/command.hh" ++#include "nix/cmd/legacy.hh" + #include "nix/cmd/markdown.hh" + #include "nix/store/store-open.hh" + #include "nix/store/local-fs-store.hh" +@@ -14,6 +15,18 @@ + + namespace nix { + ++RegisterCommand::Commands & RegisterCommand::commands() ++{ ++ static RegisterCommand::Commands commands; ++ return commands; ++} ++ ++RegisterLegacyCommand::Commands & RegisterLegacyCommand::commands() ++{ ++ static RegisterLegacyCommand::Commands commands; ++ return commands; ++} ++ + nix::Commands RegisterCommand::getCommandsFor(const std::vector & prefix) + { + nix::Commands res; +diff --git a/src/libcmd/include/nix/cmd/command.hh b/src/libcmd/include/nix/cmd/command.hh +index 2bff11dc1..2f97b30da 100644 +--- a/src/libcmd/include/nix/cmd/command.hh ++++ b/src/libcmd/include/nix/cmd/command.hh +@@ -286,11 +286,7 @@ struct RegisterCommand + { + typedef std::map, std::function()>> Commands; + +- static Commands & commands() +- { +- static Commands commands; +- return commands; +- } ++ static Commands & commands(); + + RegisterCommand(std::vector && name, std::function()> command) + { +diff --git a/src/libcmd/include/nix/cmd/legacy.hh b/src/libcmd/include/nix/cmd/legacy.hh +index 546057184..d408cde7a 100644 +--- a/src/libcmd/include/nix/cmd/legacy.hh ++++ b/src/libcmd/include/nix/cmd/legacy.hh +@@ -13,11 +13,7 @@ struct RegisterLegacyCommand + { + typedef std::map Commands; + +- static Commands & commands() +- { +- static Commands commands; +- return commands; +- } ++ static Commands & commands(); + + RegisterLegacyCommand(const std::string & name, MainFunction fun) + { +diff --git a/src/libexpr/include/nix/expr/primops.hh b/src/libexpr/include/nix/expr/primops.hh +index 6407ba84e..8854f6b03 100644 +--- a/src/libexpr/include/nix/expr/primops.hh ++++ b/src/libexpr/include/nix/expr/primops.hh +@@ -12,11 +12,7 @@ struct RegisterPrimOp + { + typedef std::vector PrimOps; + +- static PrimOps & primOps() +- { +- static PrimOps primOps; +- return primOps; +- } ++ static PrimOps & primOps(); + + /** + * You can register a constant by passing an arity of 0. fun +diff --git a/src/libexpr/include/nix/expr/print-options.hh b/src/libexpr/include/nix/expr/print-options.hh +index ffb80abc3..600b96ba2 100644 +--- a/src/libexpr/include/nix/expr/print-options.hh ++++ b/src/libexpr/include/nix/expr/print-options.hh +@@ -110,7 +110,7 @@ struct PrintOptions + * `PrintOptions` for unknown and therefore potentially large values in error messages, + * to avoid printing "too much" output. + */ +-static PrintOptions errorPrintOptions = PrintOptions{ ++static constexpr PrintOptions errorPrintOptions = PrintOptions{ + .ansiColors = true, + .maxDepth = 10, + .maxAttrs = 10, +diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc +index 98ed1b450..35f16a68d 100644 +--- a/src/libexpr/primops.cc ++++ b/src/libexpr/primops.cc +@@ -40,6 +40,12 @@ + + namespace nix { + ++RegisterPrimOp::PrimOps & RegisterPrimOp::primOps() ++{ ++ static RegisterPrimOp::PrimOps primOps; ++ return primOps; ++} ++ + /************************************************************* + * Miscellaneous + *************************************************************/ +diff --git a/src/libstore/builtins/buildenv.cc b/src/libstore/builtins/buildenv.cc +index 22ed8d807..4db37d43a 100644 +--- a/src/libstore/builtins/buildenv.cc ++++ b/src/libstore/builtins/buildenv.cc +@@ -10,6 +10,12 @@ + + namespace nix { + ++RegisterBuiltinBuilder::BuiltinBuilders & RegisterBuiltinBuilder::builtinBuilders() ++{ ++ static RegisterBuiltinBuilder::BuiltinBuilders builders; ++ return builders; ++} ++ + namespace { + + struct State +diff --git a/src/libstore/include/nix/store/builtins.hh b/src/libstore/include/nix/store/builtins.hh +index 6925e61c1..7cc9c0911 100644 +--- a/src/libstore/include/nix/store/builtins.hh ++++ b/src/libstore/include/nix/store/builtins.hh +@@ -33,11 +33,7 @@ struct RegisterBuiltinBuilder + { + typedef std::map BuiltinBuilders; + +- static BuiltinBuilders & builtinBuilders() +- { +- static BuiltinBuilders builders; +- return builders; +- } ++ static BuiltinBuilders & builtinBuilders(); + + RegisterBuiltinBuilder(const std::string & name, BuiltinBuilder && fun) + { +diff --git a/src/libutil/config-global.cc b/src/libutil/config-global.cc +index cd461ea48..b63b4aaa1 100644 +--- a/src/libutil/config-global.cc ++++ b/src/libutil/config-global.cc +@@ -4,6 +4,12 @@ + + namespace nix { + ++GlobalConfig::ConfigRegistrations & GlobalConfig::configRegistrations() ++{ ++ static GlobalConfig::ConfigRegistrations configRegistrations; ++ return configRegistrations; ++} ++ + bool GlobalConfig::set(const std::string & name, const std::string & value) + { + for (auto & config : configRegistrations()) +diff --git a/src/libutil/include/nix/util/config-global.hh b/src/libutil/include/nix/util/config-global.hh +index 0e6f43ec4..5074351e0 100644 +--- a/src/libutil/include/nix/util/config-global.hh ++++ b/src/libutil/include/nix/util/config-global.hh +@@ -9,11 +9,7 @@ struct GlobalConfig : public AbstractConfig + { + typedef std::vector ConfigRegistrations; + +- static ConfigRegistrations & configRegistrations() +- { +- static ConfigRegistrations configRegistrations; +- return configRegistrations; +- } ++ static ConfigRegistrations & configRegistrations(); + + bool set(const std::string & name, const std::string & value) override; + +-- +2.51.0 + diff --git a/pkgs/tools/package-management/nix/patches/Suppress-xattr-errors-on-Cygwin.patch b/pkgs/tools/package-management/nix/patches/Suppress-xattr-errors-on-Cygwin.patch new file mode 100644 index 0000000000000..ae26910de1a6d --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/Suppress-xattr-errors-on-Cygwin.patch @@ -0,0 +1,32 @@ +From ac7a7e37992c5fc37cca35abe8d3c17ada2fb810 Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Wed, 3 Dec 2025 14:10:05 -0400 +Subject: [PATCH] Suppress xattr errors on Cygwin + +--- + src/libstore/posix-fs-canonicalise.cc | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +diff --git a/src/libstore/posix-fs-canonicalise.cc b/src/libstore/posix-fs-canonicalise.cc +index a274468c3..7c7a60e87 100644 +--- a/src/libstore/posix-fs-canonicalise.cc ++++ b/src/libstore/posix-fs-canonicalise.cc +@@ -72,8 +72,13 @@ static void canonicalisePathMetaData_( + ssize_t eaSize = llistxattr(path.c_str(), nullptr, 0); + + if (eaSize < 0) { +- if (errno != ENOTSUP && errno != ENODATA) +- throw SysError("querying extended attributes of '%s'", path); ++ if (errno != ENOTSUP && errno != ENODATA ++// Cygwin llistxattr currently returns EPERM for symbolic links ++#ifdef __CYGWIN__ ++ && !(errno == EACCES && S_ISLNK(st.st_mode)) ++#endif ++ ) ++ throw SysError("querying extended attributes of '%s', %i, %i", path, (int)errno, (int)S_ISLNK(st.st_mode)); + } else if (eaSize > 0) { + std::vector eaBuf(eaSize); + +-- +2.51.2 + diff --git a/pkgs/tools/package-management/nix/patches/fix-cygwin-build.patch b/pkgs/tools/package-management/nix/patches/fix-cygwin-build.patch new file mode 100644 index 0000000000000..30e4e4cfc0717 --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/fix-cygwin-build.patch @@ -0,0 +1,35 @@ +diff --git a/src/libutil/unix/signals.cc b/src/libutil/unix/signals.cc +index 8a94cc2..a73715e 100644 +--- a/src/libutil/unix/signals.cc ++++ b/src/libutil/unix/signals.cc +@@ -103,8 +103,8 @@ void unix::setChildSignalMask(sigset_t * sigs) + { + assert(sigs); // C style function, but think of sigs as a reference + +-#if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE) \ +- || (defined(_POSIX_SOURCE) && _POSIX_SOURCE) ++#if ((defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 1) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE) \ ++ || (defined(_POSIX_SOURCE) && _POSIX_SOURCE)) && !defined(__CYGWIN__) + sigemptyset(&savedSignalMask); + // There's no "assign" or "copy" function, so we rely on (math) idempotence + // of the or operator: a or a = a. +diff --git a/src/libstore/posix-fs-canonicalise.cc b/src/libstore/posix-fs-canonicalise.cc +index 2484d51a6..6b759a406 100644 +--- a/src/libstore/posix-fs-canonicalise.cc ++++ b/src/libstore/posix-fs-canonicalise.cc +@@ -72,8 +72,13 @@ static void canonicalisePathMetaData_( + ssize_t eaSize = llistxattr(path.c_str(), nullptr, 0); + + if (eaSize < 0) { +- if (errno != ENOTSUP && errno != ENODATA) +- throw SysError("querying extended attributes of '%s'", path); ++ if (errno != ENOTSUP && errno != ENODATA ++// Cygwin llistxattr currently returns EPERM for symbolic links ++#ifdef __CYGWIN__ ++ && !(errno == EACCES && S_ISLNK(st.st_mode)) ++#endif ++ ) ++ throw SysError("querying extended attributes of '%s', %i, %i", path, (int)errno, (int)S_ISLNK(st.st_mode)); + } else if (eaSize > 0) { + std::vector eaBuf(eaSize); + diff --git a/pkgs/tools/package-management/nix/patches/libflake-tests-fix-leak-in-nix_api_store_test.nix_ap.patch b/pkgs/tools/package-management/nix/patches/libflake-tests-fix-leak-in-nix_api_store_test.nix_ap.patch new file mode 100644 index 0000000000000..cad2737ff8048 --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/libflake-tests-fix-leak-in-nix_api_store_test.nix_ap.patch @@ -0,0 +1,25 @@ +From 7fa550aac32900720af1004187b0a087eec8ce79 Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Fri, 9 Jan 2026 16:27:19 -0400 +Subject: [PATCH] libflake-tests: fix leak in + nix_api_store_test.nix_api_load_flake_with_flags + +--- + src/libflake-tests/nix_api_flake.cc | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/libflake-tests/nix_api_flake.cc b/src/libflake-tests/nix_api_flake.cc +index 45f3d9b29..063dfc4d7 100644 +--- a/src/libflake-tests/nix_api_flake.cc ++++ b/src/libflake-tests/nix_api_flake.cc +@@ -377,6 +377,7 @@ TEST_F(nix_api_store_test, nix_api_load_flake_with_flags) + assert_ctx_ok(); + ASSERT_EQ("Claire", helloStr); + ++ nix_locked_flake_free(lockedFlake); + nix_flake_reference_parse_flags_free(parseFlags); + nix_flake_lock_flags_free(lockFlags); + nix_flake_reference_free(flakeReference); +-- +2.52.0 + diff --git a/pkgs/tools/package-management/nix/patches/libutil-tests-fix-openFileEnsureBeneathNoSymlinks.wo.patch b/pkgs/tools/package-management/nix/patches/libutil-tests-fix-openFileEnsureBeneathNoSymlinks.wo.patch new file mode 100644 index 0000000000000..da391086d4062 --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/libutil-tests-fix-openFileEnsureBeneathNoSymlinks.wo.patch @@ -0,0 +1,32 @@ +From 88b985ab6857625e1f79df64f7b5b8bf6893239d Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Thu, 8 Jan 2026 13:27:55 -0400 +Subject: [PATCH] libutil-tests: fix openFileEnsureBeneathNoSymlinks.works on + cygwin + +--- + src/libutil-tests/file-system.cc | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/libutil-tests/file-system.cc b/src/libutil-tests/file-system.cc +index 1551227cb..3d1670813 100644 +--- a/src/libutil-tests/file-system.cc ++++ b/src/libutil-tests/file-system.cc +@@ -369,9 +369,14 @@ TEST(openFileEnsureBeneathNoSymlinks, works) + EXPECT_THROW(open("a/absolute_symlink/c/d", O_RDONLY), SymlinkNotAllowed); + EXPECT_THROW(open("a/relative_symlink/c", O_RDONLY), SymlinkNotAllowed); + EXPECT_THROW(open("a/b/c/d", O_RDONLY), SymlinkNotAllowed); ++#ifdef __CYGWIN__ ++ // this returns ELOOP on cygwin when O_NOFOLLOW is used ++ EXPECT_THROW(open("a/broken_symlink", O_CREAT | O_WRONLY | O_EXCL, 0666), SymlinkNotAllowed); ++#else + EXPECT_EQ(open("a/broken_symlink", O_CREAT | O_WRONLY | O_EXCL, 0666), INVALID_DESCRIPTOR); + /* Sanity check, no symlink shenanigans and behaves the same as regular openat with O_EXCL | O_CREAT. */ + EXPECT_EQ(errno, EEXIST); ++#endif + EXPECT_THROW(open("a/absolute_symlink/broken_symlink", O_CREAT | O_WRONLY | O_EXCL, 0666), SymlinkNotAllowed); + EXPECT_EQ(open("c/d/regular/a", O_RDONLY), INVALID_DESCRIPTOR); + EXPECT_EQ(open("c/d/regular", O_RDONLY | O_DIRECTORY), INVALID_DESCRIPTOR); +-- +2.52.0 + From 5f8eeab96ea0893da69e65850e0c0c163eafc168 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 21 Sep 2025 00:00:49 -0300 Subject: [PATCH 009/119] rsync: fix cygwin build --- pkgs/applications/networking/sync/rsync/default.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/networking/sync/rsync/default.nix b/pkgs/applications/networking/sync/rsync/default.nix index b98c39cc1baa3..30fdff8b49b64 100644 --- a/pkgs/applications/networking/sync/rsync/default.nix +++ b/pkgs/applications/networking/sync/rsync/default.nix @@ -10,7 +10,7 @@ popt, enableACLs ? lib.meta.availableOn stdenv.hostPlatform acl, acl, - enableLZ4 ? true, + enableLZ4 ? !stdenv.hostPlatform.isCygwin, lz4, enableOpenSSL ? true, openssl, @@ -80,7 +80,8 @@ stdenv.mkDerivation rec { passthru.tests = { inherit (nixosTests) rsyncd; }; - doCheck = true; + # daemon and dir-sgid tests currently fail on cygwin + doCheck = !stdenv.buildPlatform.isCygwin; __darwinAllowLocalNetworking = true; From bcb8f1253a2be2a490734d92fd703860d693d648 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 26 Sep 2025 07:51:17 -0300 Subject: [PATCH 010/119] krb5: mark broken on cygwin --- pkgs/by-name/kr/krb5/package.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/by-name/kr/krb5/package.nix b/pkgs/by-name/kr/krb5/package.nix index 62b21154e65dc..ae158da4bbf7b 100644 --- a/pkgs/by-name/kr/krb5/package.nix +++ b/pkgs/by-name/kr/krb5/package.nix @@ -174,6 +174,9 @@ stdenv.mkDerivation rec { homepage = "http://web.mit.edu/kerberos/"; license = lib.licenses.mit; platforms = lib.platforms.unix ++ lib.platforms.windows; + # configure: error: Shared libraries are not yet supported on this platform. + # cygwin has a large patchset for this package + broken = stdenv.hostPlatform.isCygwin; }; passthru = { From 6c73a7903dce72b02d69f94b3df67df8e147ea98 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 29 Sep 2025 14:42:30 -0300 Subject: [PATCH 011/119] libfido2: fix cygwin build --- pkgs/by-name/li/libfido2/package.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/by-name/li/libfido2/package.nix b/pkgs/by-name/li/libfido2/package.nix index 710960b91fb7a..7bc949e72f323 100644 --- a/pkgs/by-name/li/libfido2/package.nix +++ b/pkgs/by-name/li/libfido2/package.nix @@ -71,6 +71,12 @@ stdenv.mkDerivation rec { # causes possible redefinition of _FORTIFY_SOURCE? hardeningDisable = [ "fortify3" ]; + allowedImpureDLLs = [ + "HID.DLL" + "SETUPAPI.dll" + "USER32.dll" + ]; + meta = { description = '' Provides library functionality for FIDO 2.0, including communication with a device over USB. From 40c03b5cf172729eb23337c4288d6cbff3466270 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 29 Sep 2025 14:42:47 -0300 Subject: [PATCH 012/119] openssh: fix cygwin build --- pkgs/tools/networking/openssh/common.nix | 34 +++++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/pkgs/tools/networking/openssh/common.nix b/pkgs/tools/networking/openssh/common.nix index bafb82fa50909..e145b41730cf5 100644 --- a/pkgs/tools/networking/openssh/common.nix +++ b/pkgs/tools/networking/openssh/common.nix @@ -36,6 +36,7 @@ libfido2, libxcrypt, hostname, + cygwin, nixosTests, withSecurityKey ? !stdenv.hostPlatform.isStatic, withFIDO ? stdenv.hostPlatform.isUnix && !stdenv.hostPlatform.isMusl && withSecurityKey, @@ -109,6 +110,11 @@ stdenv.mkDerivation (finalAttrs: { # and nix store doesn't allow such fancy permission bits anyway. '' substituteInPlace Makefile.in --replace-fail '$(INSTALL) -m 4711' '$(INSTALL) -m 0711' + '' + + lib.optionalString stdenv.hostPlatform.isCygwin '' + substituteInPlace configure.ac --replace-fail \ + '/usr/lib/textreadmode.o' \ + '${lib.getLib cygwin.newlib-cygwin}/lib/textreadmode.o' ''; strictDeps = true; @@ -194,8 +200,11 @@ stdenv.mkDerivation (finalAttrs: { openssl ] ++ lib.optional (!stdenv.hostPlatform.isDarwin) hostname - ++ lib.optional (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isMusl) softhsm; + ++ lib.optional ( + !stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isMusl && !stdenv.hostPlatform.isCygwin + ) softhsm; + # TODO: remove this when doCheck = false? preCheck = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ( '' # construct a dummy HOME @@ -213,7 +222,9 @@ stdenv.mkDerivation (finalAttrs: { # invoked directly and those invoked by the "remote" session cat > ~/.ssh/environment.base < Date: Sun, 21 Sep 2025 00:02:30 -0300 Subject: [PATCH 013/119] cmake: fix eval on native stdenv --- pkgs/by-name/cm/cmake/package.nix | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pkgs/by-name/cm/cmake/package.nix b/pkgs/by-name/cm/cmake/package.nix index 3f099d56c7f9f..c8737086a9c95 100644 --- a/pkgs/by-name/cm/cmake/package.nix +++ b/pkgs/by-name/cm/cmake/package.nix @@ -124,14 +124,17 @@ stdenv.mkDerivation (finalAttrs: { ++ lib.optional cursesUI ncurses ++ lib.optional qt5UI qtbase; - preConfigure = '' - substituteInPlace Modules/Platform/UnixPaths.cmake \ - --subst-var-by libc_bin ${lib.getBin stdenv.cc.libc} \ - --subst-var-by libc_dev ${lib.getDev stdenv.cc.libc} \ - --subst-var-by libc_lib ${lib.getLib stdenv.cc.libc} - # CC_FOR_BUILD and CXX_FOR_BUILD are used to bootstrap cmake - configureFlags="--parallel=''${NIX_BUILD_CORES:-1} CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD $configureFlags $cmakeFlags" - ''; + preConfigure = + lib.optionalString (stdenv.cc.libc != null) '' + substituteInPlace Modules/Platform/UnixPaths.cmake \ + --subst-var-by libc_bin ${lib.getBin stdenv.cc.libc} \ + --subst-var-by libc_dev ${lib.getDev stdenv.cc.libc} \ + --subst-var-by libc_lib ${lib.getLib stdenv.cc.libc} + '' + + '' + # CC_FOR_BUILD and CXX_FOR_BUILD are used to bootstrap cmake + configureFlags="--parallel=''${NIX_BUILD_CORES:-1} CC=$CC_FOR_BUILD CXX=$CXX_FOR_BUILD $configureFlags $cmakeFlags" + ''; # The configuration script is not autoconf-based, although being similar; # triples and other interesting info are passed via CMAKE_* environment From 1d5849f3b452d96f7bb54392312534152108be9d Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sat, 20 Sep 2025 23:48:44 -0300 Subject: [PATCH 014/119] cmake: fix feature flags when bintools.bintools is missing --- pkgs/by-name/cm/cmake/package.nix | 41 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/pkgs/by-name/cm/cmake/package.nix b/pkgs/by-name/cm/cmake/package.nix index c8737086a9c95..fc039fa5e4db4 100644 --- a/pkgs/by-name/cm/cmake/package.nix +++ b/pkgs/by-name/cm/cmake/package.nix @@ -162,23 +162,30 @@ stdenv.mkDerivation (finalAttrs: { "--sphinx-info" "--sphinx-man" ] - ++ [ - "--" - # We should set the proper `CMAKE_SYSTEM_NAME`. - # http://www.cmake.org/Wiki/CMake_Cross_Compiling - # - # Unfortunately cmake seems to expect absolute paths for ar, ranlib, and - # strip. Otherwise they are taken to be relative to the source root of the - # package being built. - (lib.cmakeFeature "CMAKE_CXX_COMPILER" "${stdenv.cc.targetPrefix}c++") - (lib.cmakeFeature "CMAKE_C_COMPILER" "${stdenv.cc.targetPrefix}cc") - (lib.cmakeFeature "CMAKE_AR" "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ar") - (lib.cmakeFeature "CMAKE_RANLIB" "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}ranlib") - (lib.cmakeFeature "CMAKE_STRIP" "${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}strip") - - (lib.cmakeBool "CMAKE_USE_OPENSSL" useOpenSSL) - (lib.cmakeBool "BUILD_CursesDialog" cursesUI) - ]; + ++ ( + let + cc = stdenv.cc; + bintools = lib.getBin (if cc.bintools.bintools != null then cc.bintools.bintools else cc.bintools); + targetPrefix = cc.targetPrefix; + in + [ + "--" + # We should set the proper `CMAKE_SYSTEM_NAME`. + # http://www.cmake.org/Wiki/CMake_Cross_Compiling + # + # Unfortunately cmake seems to expect absolute paths for ar, ranlib, and + # strip. Otherwise they are taken to be relative to the source root of the + # package being built. + (lib.cmakeFeature "CMAKE_CXX_COMPILER" "${targetPrefix}c++") + (lib.cmakeFeature "CMAKE_C_COMPILER" "${targetPrefix}cc") + (lib.cmakeFeature "CMAKE_AR" "${bintools}/bin/${targetPrefix}ar") + (lib.cmakeFeature "CMAKE_RANLIB" "${bintools}/bin/${targetPrefix}ranlib") + (lib.cmakeFeature "CMAKE_STRIP" "${bintools}/bin/${targetPrefix}strip") + + (lib.cmakeBool "CMAKE_USE_OPENSSL" useOpenSSL) + (lib.cmakeBool "BUILD_CursesDialog" cursesUI) + ] + ); # make install attempts to use the just-built cmake preInstall = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' From 3d9035907df90417127ee80dfefe3e994a62a57e Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 21 Sep 2025 00:04:43 -0300 Subject: [PATCH 015/119] stdenv/native: fix eval --- pkgs/stdenv/generic/default.nix | 2 +- pkgs/top-level/all-packages.nix | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index d28af17692cbe..6adc1127e7aee 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -84,7 +84,7 @@ let ../../build-support/setup-hooks/set-source-date-epoch-to-latest.sh ../../build-support/setup-hooks/strip.sh ] - ++ lib.optionals hasCC [ cc ]; + ++ lib.optionals (hasCC && cc != null) [ cc ]; defaultBuildInputs = extraBuildInputs; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6e6dd6fff9b5b..1c42b9fc40035 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -5116,8 +5116,10 @@ with pkgs; callPackage ../build-support/cc-wrapper ( let self = { - nativeTools = stdenv.targetPlatform == stdenv.hostPlatform && stdenv.cc.nativeTools or false; - nativeLibc = stdenv.targetPlatform == stdenv.hostPlatform && stdenv.cc.nativeLibc or false; + nativeTools = + stdenv.targetPlatform == stdenv.hostPlatform && stdenv.cc.nativeTools or false && cc == null; + nativeLibc = + stdenv.targetPlatform == stdenv.hostPlatform && stdenv.cc.nativeLibc or false && libc == null; nativePrefix = stdenv.cc.nativePrefix or ""; noLibc = !self.nativeLibc && (self.libc == null); @@ -5155,8 +5157,10 @@ with pkgs; callPackage ../build-support/bintools-wrapper ( let self = { - nativeTools = stdenv.targetPlatform == stdenv.hostPlatform && stdenv.cc.nativeTools or false; - nativeLibc = stdenv.targetPlatform == stdenv.hostPlatform && stdenv.cc.nativeLibc or false; + nativeTools = + stdenv.targetPlatform == stdenv.hostPlatform && stdenv.cc.nativeTools or false && bintools == null; + nativeLibc = + stdenv.targetPlatform == stdenv.hostPlatform && stdenv.cc.nativeLibc or false && libc == null; nativePrefix = stdenv.cc.nativePrefix or ""; noLibc = (self.libc == null); From 6165e027735e126577f36a9bd8c43024569ba008 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 23 Sep 2025 18:53:21 -0300 Subject: [PATCH 016/119] HACK: add cygwin system --- cygwin-custom.nix | 20 ++++++++++++++++++++ cygwin-system.nix | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 cygwin-custom.nix create mode 100644 cygwin-system.nix diff --git a/cygwin-custom.nix b/cygwin-custom.nix new file mode 100644 index 0000000000000..47a5db76930eb --- /dev/null +++ b/cygwin-custom.nix @@ -0,0 +1,20 @@ +{ + lib, + pkgs, + config, + ... +}: + +{ + imports = [ + ./cygwin-system.nix + ]; + + environment.systemPackages = [ pkgs.rsync ]; + + nix = { + extraOptions = '' + secret-key-files = /var/store-key + ''; + }; +} diff --git a/cygwin-system.nix b/cygwin-system.nix new file mode 100644 index 0000000000000..4af7563b023de --- /dev/null +++ b/cygwin-system.nix @@ -0,0 +1,23 @@ +{ + lib, + pkgs, + config, + ... +}: + +{ + imports = [ + ./nixos/maintainers/scripts/cygwin/system.nix + ./nixos/maintainers/scripts/cygwin/tarball.nix + ]; + + nix = { + settings.experimental-features = [ + "nix-command" + "flakes" + ]; + }; + + nixpkgs.buildPlatform = lib.mkDefault builtins.currentSystem; + nixpkgs.hostPlatform = lib.mkDefault "x86_64-cygwin"; +} From 20ba5582d1483749029dd80c14ac506e0c7eb7fb Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 29 Sep 2025 18:58:39 -0300 Subject: [PATCH 017/119] cygwin-dll-link: skip when $OBJDUMP isn't set --- pkgs/build-support/setup-hooks/cygwin-dll-link.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh index 8a409a8a488c5..575e06f9e1646 100644 --- a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh +++ b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh @@ -15,6 +15,7 @@ addOutputDLLPaths() { postInstallHooks+=(addOutputDLLPaths) _dllDeps() { + [ -z "${OBJDUMP:-}" ] && echo "_dllDeps: '\$OBJDUMP' variable is empty, skipping." 1>&2 && return "$OBJDUMP" -p "$1" \ | sed -n 's/.*DLL Name: \(.*\)/\1/p' \ | sort -u From 3fecfbba707890723915deb8b5287aa9412a654a Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 29 Sep 2025 20:42:13 -0300 Subject: [PATCH 018/119] gcc: fix cygwin build --- .../compilers/gcc/common/configure-flags.nix | 10 +++++++- .../compilers/gcc/common/libgcc.nix | 2 ++ pkgs/development/compilers/gcc/default.nix | 4 ++- .../gcc/patches/cygwin-allow-pic.patch | 25 +++++++++++++++++++ .../cygwin-remove-relative-w32api-paths.patch | 12 +++++++++ .../compilers/gcc/patches/default.nix | 5 ++++ 6 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/compilers/gcc/patches/cygwin-allow-pic.patch create mode 100644 pkgs/development/compilers/gcc/patches/cygwin-remove-relative-w32api-paths.patch diff --git a/pkgs/development/compilers/gcc/common/configure-flags.nix b/pkgs/development/compilers/gcc/common/configure-flags.nix index 98da0be6322e9..15e5b8133cdd0 100644 --- a/pkgs/development/compilers/gcc/common/configure-flags.nix +++ b/pkgs/development/compilers/gcc/common/configure-flags.nix @@ -176,7 +176,15 @@ let # We pick "/" path to effectively avoid sysroot offset and make it work # as a native case. # Darwin requires using the SDK as the sysroot for `SDKROOT` to work correctly. - "--with-build-sysroot=${if targetPlatform.isDarwin then apple-sdk.sdkroot else "/"}" + "--with-build-sysroot=${ + if targetPlatform.isDarwin then + apple-sdk.sdkroot + else if buildPlatform.isCygwin then + # this avoids creating paths that start with //, which is a network path on cygwin + "/./" + else + "/" + }" # Same with the stdlibc++ headers embedded in the gcc output "--with-gxx-include-dir=${placeholder "out"}/include/c++/${version}/" ] diff --git a/pkgs/development/compilers/gcc/common/libgcc.nix b/pkgs/development/compilers/gcc/common/libgcc.nix index c9f6a77933443..7f790d3d19607 100644 --- a/pkgs/development/compilers/gcc/common/libgcc.nix +++ b/pkgs/development/compilers/gcc/common/libgcc.nix @@ -58,6 +58,8 @@ lib.pipe drv && !stdenv.targetPlatform.isPE && !langJit && !stdenv.hostPlatform.isDarwin + # $libgcc logic is currently hardcoded for .so + && !stdenv.hostPlatform.isCygwin && enableShared && !useLibgccFromTargetLibc; diff --git a/pkgs/development/compilers/gcc/default.nix b/pkgs/development/compilers/gcc/default.nix index f7a19a73673b8..8f47dbca85dc7 100644 --- a/pkgs/development/compilers/gcc/default.nix +++ b/pkgs/development/compilers/gcc/default.nix @@ -36,7 +36,9 @@ libucontext ? null, gnat-bootstrap ? null, enableMultilib ? false, - enablePlugin ? (lib.systems.equals stdenv.hostPlatform stdenv.buildPlatform), # Whether to support user-supplied plug-ins + enablePlugin ? ( + lib.systems.equals stdenv.hostPlatform stdenv.buildPlatform && !stdenv.hostPlatform.isPE + ), # Whether to support user-supplied plug-ins name ? "gcc", libcCross ? null, threadsCross ? { }, # for MinGW diff --git a/pkgs/development/compilers/gcc/patches/cygwin-allow-pic.patch b/pkgs/development/compilers/gcc/patches/cygwin-allow-pic.patch new file mode 100644 index 0000000000000..fe5460285b44d --- /dev/null +++ b/pkgs/development/compilers/gcc/patches/cygwin-allow-pic.patch @@ -0,0 +1,25 @@ +diff --git a/libgcc/config/i386/w32-unwind.h b/libgcc/config/i386/w32-unwind.h +index c610c50cbd4..b9a6f336307 100644 +--- a/libgcc/config/i386/w32-unwind.h ++++ b/libgcc/config/i386/w32-unwind.h +@@ -6,6 +6,7 @@ This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free ++ + Software Foundation; either version 3, or (at your option) any later + version. + +diff --git a/libiberty/configure b/libiberty/configure +index 02fbaabe89e..7fe3ed3df1e 100755 +--- a/libiberty/configure ++++ b/libiberty/configure +@@ -5336,8 +5336,6 @@ case "${host}" in + hppa*64*-*-hpux*) + # PIC is the default for 64-bit PA HP-UX. + ;; +- i[34567]86-*-cygwin* | x86_64-*-cygwin*) +- ;; + i[34567]86-*-mingw* | x86_64-*-mingw*) + ;; + i[34567]86-*-interix[3-9]*) diff --git a/pkgs/development/compilers/gcc/patches/cygwin-remove-relative-w32api-paths.patch b/pkgs/development/compilers/gcc/patches/cygwin-remove-relative-w32api-paths.patch new file mode 100644 index 0000000000000..7f9fd7e606935 --- /dev/null +++ b/pkgs/development/compilers/gcc/patches/cygwin-remove-relative-w32api-paths.patch @@ -0,0 +1,12 @@ +diff --git a/gcc/config/i386/cygwin.h b/gcc/config/i386/cygwin.h +index 93b279d0a92..a266eaabb9c 100644 +--- a/gcc/config/i386/cygwin.h ++++ b/gcc/config/i386/cygwin.h +@@ -32,7 +32,6 @@ along with GCC; see the file COPYING3. If not see + #define CPP_SPEC "%(cpp_cpu) %{posix:-D_POSIX_SOURCE} \ + %{pthread:-D_REENTRANT} \ + %{mwin32:-DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ %{!ansi:-DWINNT}} \ +- %{!nostdinc:%{!mno-win32:-idirafter ../include/w32api%s -idirafter ../../include/w32api%s}}\ + " + + #undef STARTFILE_SPEC diff --git a/pkgs/development/compilers/gcc/patches/default.nix b/pkgs/development/compilers/gcc/patches/default.nix index 92369c5d0c609..b0da37f38d01b 100644 --- a/pkgs/development/compilers/gcc/patches/default.nix +++ b/pkgs/development/compilers/gcc/patches/default.nix @@ -248,4 +248,9 @@ optionals noSysDirs ( url = "https://inbox.sourceware.org/gcc-patches/20250922182808.2599390-3-corngood@gmail.com/raw"; hash = "sha256-8I2G4430gkYoWgUued4unqhk8ZCajHf1dcivAeuLZ0E="; }) + ./cygwin-remove-relative-w32api-paths.patch +] + +++ optionals hostPlatform.isCygwin [ + ./cygwin-allow-pic.patch ] From bb3ef66743c9188b8901115bceae5bec54de240c Mon Sep 17 00:00:00 2001 From: David McFarland Date: Wed, 1 Oct 2025 13:38:48 -0300 Subject: [PATCH 019/119] nix: fix builder PATH on cygwin --- ...nclude-bin-in-builder-PATH-on-cygwin.patch | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pkgs/tools/package-management/nix/patches/Include-bin-in-builder-PATH-on-cygwin.patch diff --git a/pkgs/tools/package-management/nix/patches/Include-bin-in-builder-PATH-on-cygwin.patch b/pkgs/tools/package-management/nix/patches/Include-bin-in-builder-PATH-on-cygwin.patch new file mode 100644 index 0000000000000..1b54a1f555ec6 --- /dev/null +++ b/pkgs/tools/package-management/nix/patches/Include-bin-in-builder-PATH-on-cygwin.patch @@ -0,0 +1,32 @@ +From b64bfd3db32542324cc724fc8b2a6e36bf856f47 Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Wed, 1 Oct 2025 13:36:33 -0300 +Subject: [PATCH] Include /bin in builder PATH on cygwin + +--- + src/libstore/unix/build/derivation-builder.cc | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/src/libstore/unix/build/derivation-builder.cc b/src/libstore/unix/build/derivation-builder.cc +index f94bb40cc..d817f954d 100644 +--- a/src/libstore/unix/build/derivation-builder.cc ++++ b/src/libstore/unix/build/derivation-builder.cc +@@ -981,7 +981,14 @@ void DerivationBuilderImpl::initEnv() + /* Most shells initialise PATH to some default (/bin:/usr/bin:...) when + PATH is not set. We don't want this, so we fill it in with some dummy + value. */ +- env["PATH"] = "/path-not-set"; ++ env["PATH"] = ++#ifdef __CYGWIN__ ++ // on cygwin we always need /bin in PATH, so cygwin1.dll can be found ++ "/bin" ++#else ++ "/path-not-set" ++#endif ++ ; + + /* Set HOME to a non-existing path to prevent certain programs from using + /etc/passwd (or NIS, or whatever) to locate the home directory (for +-- +2.51.0 + From 30bb461dd7750703c1c1336820fbb33eb3df257c Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 3 Oct 2025 12:02:39 -0300 Subject: [PATCH 020/119] cygwin: add hook to create executable links without .exe extension --- pkgs/os-specific/cygwin/create-exe-links.sh | 21 +++++++++++++++++++++ pkgs/stdenv/generic/make-derivation.nix | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 pkgs/os-specific/cygwin/create-exe-links.sh diff --git a/pkgs/os-specific/cygwin/create-exe-links.sh b/pkgs/os-specific/cygwin/create-exe-links.sh new file mode 100644 index 0000000000000..22858d6000bc3 --- /dev/null +++ b/pkgs/os-specific/cygwin/create-exe-links.sh @@ -0,0 +1,21 @@ +linkEXEs() { + if [ ! -d "$prefix" ]; then return; fi + ( + set -e + shopt -s globstar nullglob + + cd "$prefix" + + local target + for target in {bin,libexec}/**/*.exe; do + if [[ -f "$target" && ! -e "${target%.exe}" ]]; then + local link + link=$(basename "$target") + echo "linkEXEs: creating link for $target" >&2 + ln -s "$link" "${target%.exe}" + fi + done + ) +} + +fixupOutputHooks+=(linkEXEs) diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index cdfeb34a24116..b1b520c731214 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -475,7 +475,10 @@ let nativeBuildInputs ++ optional separateDebugInfo' ../../build-support/setup-hooks/separate-debug-info.sh ++ optional isWindows ../../build-support/setup-hooks/win-dll-link.sh - ++ optional isCygwin ../../build-support/setup-hooks/cygwin-dll-link.sh + ++ optionals isCygwin [ + ../../build-support/setup-hooks/cygwin-dll-link.sh + ../../os-specific/cygwin/create-exe-links.sh + ] ++ optionals doCheck nativeCheckInputs ++ optionals doInstallCheck nativeInstallCheckInputs; From 37d30157f7ebdf6761d25826378a15770e191be0 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 3 Oct 2025 13:04:59 -0300 Subject: [PATCH 021/119] Revert "cygwin: add hook to create executable links without .exe extension" This reverts commit 81e4c5c1a496d5a570842e33a0eb6b66eba30664. --- pkgs/os-specific/cygwin/create-exe-links.sh | 21 --------------------- pkgs/stdenv/generic/make-derivation.nix | 5 +---- 2 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 pkgs/os-specific/cygwin/create-exe-links.sh diff --git a/pkgs/os-specific/cygwin/create-exe-links.sh b/pkgs/os-specific/cygwin/create-exe-links.sh deleted file mode 100644 index 22858d6000bc3..0000000000000 --- a/pkgs/os-specific/cygwin/create-exe-links.sh +++ /dev/null @@ -1,21 +0,0 @@ -linkEXEs() { - if [ ! -d "$prefix" ]; then return; fi - ( - set -e - shopt -s globstar nullglob - - cd "$prefix" - - local target - for target in {bin,libexec}/**/*.exe; do - if [[ -f "$target" && ! -e "${target%.exe}" ]]; then - local link - link=$(basename "$target") - echo "linkEXEs: creating link for $target" >&2 - ln -s "$link" "${target%.exe}" - fi - done - ) -} - -fixupOutputHooks+=(linkEXEs) diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index b1b520c731214..cdfeb34a24116 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -475,10 +475,7 @@ let nativeBuildInputs ++ optional separateDebugInfo' ../../build-support/setup-hooks/separate-debug-info.sh ++ optional isWindows ../../build-support/setup-hooks/win-dll-link.sh - ++ optionals isCygwin [ - ../../build-support/setup-hooks/cygwin-dll-link.sh - ../../os-specific/cygwin/create-exe-links.sh - ] + ++ optional isCygwin ../../build-support/setup-hooks/cygwin-dll-link.sh ++ optionals doCheck nativeCheckInputs ++ optionals doInstallCheck nativeInstallCheckInputs; From cbfb0a7372646f38e1fdcb41c2cd1958d1590888 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 3 Oct 2025 14:50:12 -0300 Subject: [PATCH 022/119] {cc,bintools}-wrapper: use executable extension when set --- .../bintools-wrapper/default.nix | 13 +++++---- pkgs/build-support/cc-wrapper/default.nix | 29 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 8f5613e9e7bb5..36b121378be4a 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -92,6 +92,7 @@ let # TODO(@Ericson2314) Make unconditional, or optional but always true by # default. targetPrefix = optionalString (targetPlatform != hostPlatform) (targetPlatform.config + "-"); + exeSuffix = stdenvNoCC.hostPlatform.extensions.executable; bintoolsVersion = getVersion bintools; bintoolsName = removePrefix targetPrefix (getName bintools); @@ -257,17 +258,17 @@ stdenvNoCC.mkDerivation { + '' for binary in objdump objcopy size strings as ar nm gprof dwp c++filt addr2line \ ranlib readelf elfedit dlltool dllwrap windmc windres; do - if [ -e $ldPath/${targetPrefix}''${binary} ]; then - ln -s $ldPath/${targetPrefix}''${binary} $out/bin/${targetPrefix}''${binary} + if [ -e $ldPath/${targetPrefix}''${binary}${exeSuffix} ]; then + ln -s $ldPath/${targetPrefix}''${binary}${exeSuffix} $out/bin/${targetPrefix}''${binary}${exeSuffix} fi done - if [ -e ''${ld:-$ldPath/${targetPrefix}ld} ]; then - wrap ${targetPrefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${targetPrefix}ld} + if [ -e ''${ld:-$ldPath/${targetPrefix}ld}${exeSuffix} ]; then + wrap ${targetPrefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${targetPrefix}ld}${exeSuffix} fi - for variant in $ldPath/${targetPrefix}ld.*; do - basename=$(basename "$variant") + for variant in $ldPath/${targetPrefix}ld.*${exeSuffix}; do + basename=$(basename "${if exeSuffix != "" then "\${variant%${exeSuffix}}" else "$variant"}") wrap $basename ${./ld-wrapper.sh} $variant done ''; diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 07efab5e75c1e..9bb07456e8f25 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -118,6 +118,7 @@ let # # TODO(@Ericson2314) Make unconditional, or optional but always true by default. targetPrefix = optionalString (targetPlatform != hostPlatform) (targetPlatform.config + "-"); + exeSuffix = stdenvNoCC.hostPlatform.extensions.executable; ccVersion = getVersion cc; ccName = removePrefix targetPrefix (getName cc); @@ -524,34 +525,34 @@ stdenvNoCC.mkDerivation { export named_cc=${targetPrefix}cc export named_cxx=${targetPrefix}c++ - if [ -e $ccPath/${targetPrefix}gcc ]; then - wrap ${targetPrefix}gcc $wrapper $ccPath/${targetPrefix}gcc + if [ -e $ccPath/${targetPrefix}gcc${exeSuffix} ]; then + wrap ${targetPrefix}gcc $wrapper $ccPath/${targetPrefix}gcc${exeSuffix} ln -s ${targetPrefix}gcc $out/bin/${targetPrefix}cc export named_cc=${targetPrefix}gcc export named_cxx=${targetPrefix}g++ - elif [ -e $ccPath/clang ]; then - wrap ${targetPrefix}clang $wrapper $ccPath/clang + elif [ -e $ccPath/clang${exeSuffix} ]; then + wrap ${targetPrefix}clang $wrapper $ccPath/clang${exeSuffix} ln -s ${targetPrefix}clang $out/bin/${targetPrefix}cc export named_cc=${targetPrefix}clang export named_cxx=${targetPrefix}clang++ - elif [ -e $ccPath/arocc ]; then - wrap ${targetPrefix}arocc $wrapper $ccPath/arocc + elif [ -e $ccPath/arocc${exeSuffix} ]; then + wrap ${targetPrefix}arocc $wrapper $ccPath/arocc${exeSuffix} ln -s ${targetPrefix}arocc $out/bin/${targetPrefix}cc export named_cc=${targetPrefix}arocc fi - if [ -e $ccPath/${targetPrefix}g++ ]; then - wrap ${targetPrefix}g++ $wrapper $ccPath/${targetPrefix}g++ + if [ -e $ccPath/${targetPrefix}g++${exeSuffix} ]; then + wrap ${targetPrefix}g++ $wrapper $ccPath/${targetPrefix}g++${exeSuffix} ln -s ${targetPrefix}g++ $out/bin/${targetPrefix}c++ - elif [ -e $ccPath/clang++ ]; then - wrap ${targetPrefix}clang++ $wrapper $ccPath/clang++ + elif [ -e $ccPath/clang++${exeSuffix} ]; then + wrap ${targetPrefix}clang++ $wrapper $ccPath/clang++${exeSuffix} ln -s ${targetPrefix}clang++ $out/bin/${targetPrefix}c++ fi - if [ -e $ccPath/${targetPrefix}cpp ]; then - wrap ${targetPrefix}cpp $wrapper $ccPath/${targetPrefix}cpp - elif [ -e $ccPath/cpp ]; then - wrap ${targetPrefix}cpp $wrapper $ccPath/cpp + if [ -e $ccPath/${targetPrefix}cpp${exeSuffix} ]; then + wrap ${targetPrefix}cpp $wrapper $ccPath/${targetPrefix}cpp${exeSuffix} + elif [ -e $ccPath/cpp${exeSuffix} ]; then + wrap ${targetPrefix}cpp $wrapper $ccPath/cpp${exeSuffix} fi '' From 8f1ab5f74a0c605893f49dcd9e6101d4dcc8e6e1 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 3 Oct 2025 15:02:36 -0300 Subject: [PATCH 023/119] cpython: fix cygwin build --- .../interpreters/python/cpython/default.nix | 77 ++++++---- .../python/cpython/fix-cygwin-build.patch | 145 ++++++++++++++++++ 2 files changed, 191 insertions(+), 31 deletions(-) create mode 100644 pkgs/development/interpreters/python/cpython/fix-cygwin-build.patch diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 13ede05bf2b72..85a7b65898caf 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -211,7 +211,8 @@ let ++ optionals ( - (!stdenv.hostPlatform.isDarwin && !withMinimalDeps) + # on cygwin this is needed for fix-cygwin-build.patch + (!stdenv.hostPlatform.isDarwin && !withMinimalDeps || stdenv.hostPlatform.isCygwin) || (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isFreeBSD) ) [ @@ -435,7 +436,8 @@ stdenv.mkDerivation (finalAttrs: { "mingw-python3_setenv.patch" "mingw-python3_win-modules.patch" ]) - ); + ) + ++ optionals stdenv.hostPlatform.isCygwin [ ./fix-cygwin-build.patch ]; postPatch = optionalString (!stdenv.hostPlatform.isWindows) '' @@ -728,6 +730,9 @@ stdenv.mkDerivation (finalAttrs: { echo linking DLLs for python’s compiled librairies linkDLLsInfolder $out/lib/python*/lib-dynload/ + '' + + optionalString stdenv.hostPlatform.isCygwin '' + linkDLLsDir="$out"/bin linkDLLs "$out"/lib/python*/lib-dynload/*.cpython-*.dll ''; preFixup = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' @@ -737,34 +742,40 @@ stdenv.mkDerivation (finalAttrs: { # Add CPython specific setup-hook that configures distutils.sysconfig to # always load sysconfigdata from host Python. - postFixup = lib.optionalString (!stdenv.hostPlatform.isDarwin) '' - # https://github.com/python/cpython/blob/e488e300f5c01289c10906c2e53a8e43d6de32d8/configure.ac#L78 - sysconfigdataName="$(make --eval $'print-sysconfigdata-name: - \t@echo _sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) ' print-sysconfigdata-name)" - - # The CPython interpreter contains a _sysconfigdata_ - # module that is imported by the sysconfig and distutils.sysconfig modules. - # The sysconfigdata module is generated at build time and contains settings - # required for building Python extension modules, such as include paths and - # other compiler flags. By default, the sysconfigdata module is loaded from - # the currently running interpreter (ie. the build platform interpreter), but - # when cross-compiling we want to load it from the host platform interpreter. - # This can be done using the _PYTHON_SYSCONFIGDATA_NAME environment variable. - # The _PYTHON_HOST_PLATFORM variable also needs to be set to get the correct - # platform suffix on extension modules. The correct values for these variables - # are not documented, and must be derived from the configure script (see links - # below). - cat <> "$out/nix-support/setup-hook" - sysconfigdataHook() { - if [ "\$1" = '$out' ]; then - export _PYTHON_HOST_PLATFORM='${pythonHostPlatform}' - export _PYTHON_SYSCONFIGDATA_NAME='$sysconfigdataName' - fi - } - - addEnvHooks "\$hostOffset" sysconfigdataHook - EOF - ''; + postFixup = + lib.optionalString (!stdenv.hostPlatform.isDarwin) '' + # https://github.com/python/cpython/blob/e488e300f5c01289c10906c2e53a8e43d6de32d8/configure.ac#L78 + sysconfigdataName="$(make --eval $'print-sysconfigdata-name: + \t@echo _sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) ' print-sysconfigdata-name)" + + # The CPython interpreter contains a _sysconfigdata_ + # module that is imported by the sysconfig and distutils.sysconfig modules. + # The sysconfigdata module is generated at build time and contains settings + # required for building Python extension modules, such as include paths and + # other compiler flags. By default, the sysconfigdata module is loaded from + # the currently running interpreter (ie. the build platform interpreter), but + # when cross-compiling we want to load it from the host platform interpreter. + # This can be done using the _PYTHON_SYSCONFIGDATA_NAME environment variable. + # The _PYTHON_HOST_PLATFORM variable also needs to be set to get the correct + # platform suffix on extension modules. The correct values for these variables + # are not documented, and must be derived from the configure script (see links + # below). + cat <> "$out/nix-support/setup-hook" + sysconfigdataHook() { + if [ "\$1" = '$out' ]; then + export _PYTHON_HOST_PLATFORM='${pythonHostPlatform}' + export _PYTHON_SYSCONFIGDATA_NAME='$sysconfigdataName' + fi + } + + addEnvHooks "\$hostOffset" sysconfigdataHook + EOF + '' + # borrowed from cygwin python39.cygport + # this is needed for the flags in python3.pc to work + + optionalString stdenv.hostPlatform.isCygwin '' + cp libpython*.dll.a "$out"/lib + ''; # Enforce that we don't have references to the OpenSSL -dev package, which we # explicitly specify in our configure flags above. @@ -852,7 +863,11 @@ stdenv.mkDerivation (finalAttrs: { license = lib.licenses.psfl; pkgConfigModules = [ "python3" ]; platforms = - lib.platforms.linux ++ lib.platforms.darwin ++ lib.platforms.windows ++ lib.platforms.freebsd; + lib.platforms.linux + ++ lib.platforms.darwin + ++ lib.platforms.windows + ++ lib.platforms.cygwin + ++ lib.platforms.freebsd; mainProgram = executable; teams = [ lib.teams.python ]; # static build on x86_64-darwin/aarch64-darwin breaks with: diff --git a/pkgs/development/interpreters/python/cpython/fix-cygwin-build.patch b/pkgs/development/interpreters/python/cpython/fix-cygwin-build.patch new file mode 100644 index 0000000000000..117b6807a33e6 --- /dev/null +++ b/pkgs/development/interpreters/python/cpython/fix-cygwin-build.patch @@ -0,0 +1,145 @@ +diff --git a/Makefile.pre.in b/Makefile.pre.in +index a7dc9709d62..c37f735b676 100644 +--- a/Makefile.pre.in ++++ b/Makefile.pre.in +@@ -43,6 +43,7 @@ SOABI= @SOABI@ + ABIFLAGS= @ABIFLAGS@ + ABI_THREAD= @ABI_THREAD@ + LDVERSION= @LDVERSION@ ++BLIBPYTHON=@BLIBPYTHON@ + LIBPYTHON=@LIBPYTHON@ + GITVERSION= @GITVERSION@ + GITTAG= @GITTAG@ +diff --git a/Misc/python.pc.in b/Misc/python.pc.in +index 027dba38585..6414141e15e 100644 +--- a/Misc/python.pc.in ++++ b/Misc/python.pc.in +@@ -9,5 +9,5 @@ Description: Build a C extension for Python + Requires: + Version: @VERSION@ + Libs.private: @LIBS@ +-Libs: -L${libdir} @LIBPYTHON@ ++Libs: @LIBPYTHON@ + Cflags: -I${includedir}/python@VERSION@@ABIFLAGS@ +diff --git a/Modules/makesetup b/Modules/makesetup +index 8bb971b152a..cedc9ce6471 100755 +--- a/Modules/makesetup ++++ b/Modules/makesetup +@@ -274,7 +274,7 @@ sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' | + ;; + esac + rule="$file: $objs" +- rule="$rule; \$(BLDSHARED) $objs $libs \$(LIBPYTHON) -o $file" ++ rule="$rule; \$(BLDSHARED) $objs $libs \$(BLIBPYTHON) -o $file" + echo "$rule" >>$rulesf + done + done +diff --git a/Modules/timemodule.c b/Modules/timemodule.c +index 49626d32fd3..fd741628894 100644 +--- a/Modules/timemodule.c ++++ b/Modules/timemodule.c +@@ -187,7 +187,7 @@ time_clockid_converter(PyObject *obj, clockid_t *p) + { + #ifdef _AIX + long long clk_id = PyLong_AsLongLong(obj); +-#elif defined(__DragonFly__) ++#elif defined(__DragonFly__) || defined(__CYGWIN__) + long clk_id = PyLong_AsLong(obj); + #else + int clk_id = PyLong_AsInt(obj); +diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c +index 5a37a83805b..3b6dec254ed 100644 +--- a/Python/dynload_shlib.c ++++ b/Python/dynload_shlib.c +@@ -36,6 +36,10 @@ + + const char *_PyImport_DynLoadFiletab[] = { + #ifdef __CYGWIN__ ++ "." SOABI ".dll", ++#ifdef ALT_SOABI ++ "." ALT_SOABI ".dll", ++#endif + ".dll", + #else /* !__CYGWIN__ */ + "." SOABI ".so", +diff --git a/configure.ac b/configure.ac +index 597a44b331a..e271a9bfdf0 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -325,7 +325,7 @@ then + ac_sys_system=Linux + ;; + *-*-cygwin*) +- ac_sys_system=Cygwin ++ ac_sys_system=CYGWIN + ;; + *-apple-ios*) + ac_sys_system=iOS +@@ -3540,8 +3540,8 @@ then + dnl not implemented yet + ]);; + CYGWIN*) +- LDSHARED="gcc -shared -Wl,--enable-auto-image-base" +- LDCXXSHARED="g++ -shared -Wl,--enable-auto-image-base";; ++ LDSHARED='$(CC) -shared -Wl,--enable-auto-image-base' ++ LDCXXSHARED='$(CXX) -shared -Wl,--enable-auto-image-base';; + *) LDSHARED="ld";; + esac + fi +@@ -6307,26 +6307,6 @@ AC_MSG_CHECKING([LDVERSION]) + LDVERSION='$(VERSION)$(ABIFLAGS)' + AC_MSG_RESULT([$LDVERSION]) + +-# Configure the flags and dependencies used when compiling shared modules. +-# Do not rename LIBPYTHON - it's accessed via sysconfig by package build +-# systems (e.g. Meson) to decide whether to link extension modules against +-# libpython. +-AC_SUBST([MODULE_DEPS_SHARED]) +-AC_SUBST([LIBPYTHON]) +-MODULE_DEPS_SHARED='$(MODULE_DEPS_STATIC) $(EXPORTSYMS)' +-LIBPYTHON='' +- +-# On Android and Cygwin the shared libraries must be linked with libpython. +-if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then +- MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)" +- LIBPYTHON="\$(BLDLIBRARY)" +-fi +- +-# On iOS the shared libraries must be linked with the Python framework +-if test "$ac_sys_system" = "iOS"; then +- MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(PYTHONFRAMEWORKDIR)/\$(PYTHONFRAMEWORK)" +-fi +- + + AC_SUBST([BINLIBDEST]) + BINLIBDEST='$(LIBDIR)/python$(VERSION)$(ABI_THREAD)' +@@ -6368,6 +6348,29 @@ else + fi + AC_SUBST([LIBPL]) + ++# Configure the flags and dependencies used when compiling shared modules. ++# Do not rename LIBPYTHON - it's accessed via sysconfig by package build ++# systems (e.g. Meson) to decide whether to link extension modules against ++# libpython. ++AC_SUBST([MODULE_DEPS_SHARED]) ++AC_SUBST([BLIBPYTHON]) ++AC_SUBST([LIBPYTHON]) ++MODULE_DEPS_SHARED='$(MODULE_DEPS_STATIC) $(EXPORTSYMS)' ++BLIBPYTHON='' ++LIBPYTHON='' ++ ++# On Android and Cygwin the shared libraries must be linked with libpython. ++if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then ++MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(LDLIBRARY)" ++BLIBPYTHON="\$(BLDLIBRARY)" ++LIBPYTHON="-L\"$prefix\"/${PLATLIBDIR}/python${VERSION}${ABI_THREAD}/config-${VERSION}${ABIFLAGS}${PLATFORM_TRIPLET+-$PLATFORM_TRIPLET} -lpython${VERSION}${ABIFLAGS}" ++fi ++ ++# On iOS the shared libraries must be linked with the Python framework ++if test "$ac_sys_system" = "iOS"; then ++ MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(PYTHONFRAMEWORKDIR)/\$(PYTHONFRAMEWORK)" ++fi ++ + # Check for --with-wheel-pkg-dir=PATH + AC_SUBST([WHEEL_PKG_DIR]) + WHEEL_PKG_DIR="" From 3e842336f7b53364285593b664b7f259e3b87fa0 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 3 Oct 2025 19:06:10 -0300 Subject: [PATCH 024/119] perl: fix cygwin build --- ...-fix-several-silly-terrible-C-errors.patch | 179 ++++++++++++++++++ .../interpreters/perl/fix-cygwin-cross.patch | 27 +++ .../interpreters/perl/interpreter.nix | 54 +++++- 3 files changed, 255 insertions(+), 5 deletions(-) create mode 100644 pkgs/development/interpreters/perl/cygwin.c-fix-several-silly-terrible-C-errors.patch create mode 100644 pkgs/development/interpreters/perl/fix-cygwin-cross.patch diff --git a/pkgs/development/interpreters/perl/cygwin.c-fix-several-silly-terrible-C-errors.patch b/pkgs/development/interpreters/perl/cygwin.c-fix-several-silly-terrible-C-errors.patch new file mode 100644 index 0000000000000..e31b4f6c58e6e --- /dev/null +++ b/pkgs/development/interpreters/perl/cygwin.c-fix-several-silly-terrible-C-errors.patch @@ -0,0 +1,179 @@ +From b872e74120c4245132e2c906399bff9fc18e032d Mon Sep 17 00:00:00 2001 +From: Lukas Mai +Date: Wed, 6 Nov 2024 22:58:05 +0100 +Subject: [PATCH] cygwin.c: fix several silly/terrible C errors + +Errors fixed: + +Not detected by the compiler, but the preprocessor version checks only +looked at `CYGWIN_VERSION_API_MINOR`, ignoring +`CYGWIN_VERSION_API_MAJOR`. + + cygwin.c: In function 'utf8_to_wide_extra_len': + cygwin.c:187:18: warning: initialization of 'size_t' {aka 'long unsigned int'} from 'size_t *' {aka 'long unsigned int *'} makes integer from pointer without a cast [-Wint-conversion] + 187 | Size_t len = strlen(buf) + extra_len + 1; + | ^~~~~~ + +`extra_len` was declared as a pointer, but used as an integer. I don't +see how this could have ever worked. + + cygwin.c: In function 'S_convert_path_common': + cygwin.c:339:38: warning: 'realloc' called on unallocated object 'wconverted' [-Wfree-nonheap-object] + 339 | wconverted = (wchar_t *) realloc(&wconverted, newlen); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ + cygwin.c:357:39: warning: 'realloc' called on unallocated object 'converted_path' [-Wfree-nonheap-object] + 357 | converted_path = (char *) realloc(&converted_path, newlen); + | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Again, I don't see how this could have ever worked. We're passing the +address of a local (stack) variable to `realloc` (instead of the value +of the variable). + + cygwin.c: In function 'wide_to_utf8': + cygwin.c:173:32: warning: pointer targets in passing argument 3 of 'Perl_utf16_to_utf8_base' differ in signedness [-Wpointer-sign] + 173 | utf16_to_utf8((U8 *) wsrc, buf, wlen, &blen); + | ^~~ + | | + | char * + +The argument is declared as `U8 *`, so this is mostly harmless, but a +cast silences the warning anyway. + + cygwin.c: In function 'utf8_to_wide_extra_len': + cygwin.c:194:19: warning: passing argument 2 of 'Perl_utf8_to_utf16_base' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] + 194 | utf8_to_utf16(buf, (U8 *) wsrc, len, &wlen); + | ^~~ + +This is arguably a bug in `utf8_to_utf16`, which doesn't declare its +input argument as pointer-to-const. But it's also a `char *` vs `U8 *` +type mismatch, so a cast silences both issues. + + cygwin.c: In function 'S_convert_path_common': + cygwin.c:292:22: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] + 292 | char *name = (direction == to_posix) + | ^ + +This is a missing `const` in the declaration of a variable that points +to string literals. +--- + cygwin/cygwin.c | 29 +++++++++++++++-------------- + 1 file changed, 15 insertions(+), 14 deletions(-) + +diff --git a/cygwin/cygwin.c b/cygwin/cygwin.c +index 7c3d5dc48c..625777366c 100644 +--- a/cygwin/cygwin.c ++++ b/cygwin/cygwin.c +@@ -15,7 +15,10 @@ + #include + #include + #include +-#if (CYGWIN_VERSION_API_MINOR >= 181) ++#define HAVE_CYGWIN_VERSION(MAJOR, MINOR) \ ++ (CYGWIN_VERSION_API_MAJOR > (MAJOR) || \ ++ (CYGWIN_VERSION_API_MAJOR == (MAJOR) && CYGWIN_VERSION_API_MINOR >= (MINOR))) ++#if HAVE_CYGWIN_VERSION(0, 181) + #include + #endif + +@@ -158,7 +161,7 @@ leave: + return result; + } + +-#if (CYGWIN_VERSION_API_MINOR >= 181) ++#if HAVE_CYGWIN_VERSION(0, 181) + char* + wide_to_utf8(const wchar_t *wsrc) + { +@@ -170,13 +173,13 @@ wide_to_utf8(const wchar_t *wsrc) + + char *buf = (char *) safemalloc(blen); + +- utf16_to_utf8((U8 *) wsrc, buf, wlen, &blen); ++ utf16_to_utf8((U8 *) wsrc, (U8 *) buf, wlen, &blen); + + return buf; + } + + wchar_t* +-utf8_to_wide_extra_len(const char *buf, Size_t *extra_len) ++utf8_to_wide_extra_len(const char *buf, Size_t extra_len) + { + /* Return the conversion to UTF-16 of the UTF-8 string 'buf' + * (terminated by a NUL), making sure to have space for at least *extra_len +@@ -191,7 +194,7 @@ utf8_to_wide_extra_len(const char *buf, Size_t *extra_len) + + wchar_t* wsrc = (wchar_t *) safemalloc(wlen); + +- utf8_to_utf16(buf, (U8 *) wsrc, len, &wlen); ++ utf8_to_utf16((U8 *) buf, (U8 *) wsrc, len, &wlen); + + return wsrc; + } +@@ -199,9 +202,7 @@ utf8_to_wide_extra_len(const char *buf, Size_t *extra_len) + wchar_t* + utf8_to_wide(const char *buf) + { +- Size_t extra_len = 0; +- +- return utf8_to_wide_extra_len(buf, &extra_len); ++ return utf8_to_wide_extra_len(buf, 0); + } + + #endif /* cygwin 1.7 */ +@@ -255,7 +256,7 @@ XS(XS_Cygwin_winpid_to_pid) + + pid = (pid_t)SvIV(ST(0)); + +-#if (CYGWIN_VERSION_API_MINOR >= 181) ++#if HAVE_CYGWIN_VERSION(0, 181) + RETVAL = cygwin_winpid_to_pid(pid); + #else + RETVAL = cygwin32_winpid_to_pid(pid); +@@ -289,7 +290,7 @@ S_convert_path_common(pTHX_ const direction_t direction) + int isutf8 = 0; + + if (items < 1 || items > 2) { +- char *name = (direction == to_posix) ++ const char *name = (direction == to_posix) + ? "win::win_to_posix_path" + : "posix_to_win_path"; + Perl_croak(aTHX_ "Usage: Cygwin::%s(pathname, [absolute])", name); +@@ -303,7 +304,7 @@ S_convert_path_common(pTHX_ const direction_t direction) + Perl_croak(aTHX_ "can't convert empty path"); + isutf8 = SvUTF8(ST(0)); + +-#if (CYGWIN_VERSION_API_MINOR >= 181) ++#if HAVE_CYGWIN_VERSION(0, 181) + /* Check utf8 flag and use wide api then. + Size calculation: On overflow let cygwin_conv_path calculate the final size. + */ +@@ -322,7 +323,7 @@ S_convert_path_common(pTHX_ const direction_t direction) + + if (LIKELY(! IN_BYTES)) { /* Normal case, convert UTF-8 to UTF-16 */ + wlen = PATH_LEN_GUESS; +- wsrc = utf8_to_wide_extra_len(src_path, &wlen); ++ wsrc = utf8_to_wide_extra_len(src_path, wlen); + which_src = wsrc; + } + else { /* use bytes; assume already UTF-16 encoded bytestream */ +@@ -336,7 +337,7 @@ S_convert_path_common(pTHX_ const direction_t direction) + + if (err == ENOSPC) { /* our space assumption was wrong, not enough space */ + int newlen = cygwin_conv_path(what, which_src, wconverted, 0); +- wconverted = (wchar_t *) realloc(&wconverted, newlen); ++ wconverted = (wchar_t *) realloc(wconverted, newlen); + err = cygwin_conv_path(what, which_src, wconverted, newlen); + } + +@@ -354,7 +355,7 @@ S_convert_path_common(pTHX_ const direction_t direction) + err = cygwin_conv_path(what, src_path, converted_path, len + PATH_LEN_GUESS); + if (err == ENOSPC) { /* our space assumption was wrong, not enough space */ + int newlen = cygwin_conv_path(what, src_path, converted_path, 0); +- converted_path = (char *) realloc(&converted_path, newlen); ++ converted_path = (char *) realloc(converted_path, newlen); + err = cygwin_conv_path(what, src_path, converted_path, newlen); + } + } +-- +2.50.1 + diff --git a/pkgs/development/interpreters/perl/fix-cygwin-cross.patch b/pkgs/development/interpreters/perl/fix-cygwin-cross.patch new file mode 100644 index 0000000000000..fb8cb78b3b3cb --- /dev/null +++ b/pkgs/development/interpreters/perl/fix-cygwin-cross.patch @@ -0,0 +1,27 @@ +diff --git a/cnf/configure_tool.sh b/cnf/configure_tool.sh +index 2f5492e..85c9715 100644 +--- a/cnf/configure_tool.sh ++++ b/cnf/configure_tool.sh +@@ -246,6 +246,10 @@ if not hinted 'osname'; then + define osname "MSWin32" + result "MSWin32" + ;; ++ *-cygwin) ++ define osname "cygwin" ++ result "Cygwin" ++ ;; + *-android|*-androideabi) + define osname "android" + result "Android" +diff --git a/cnf/configure_func.sh b/cnf/configure_func.sh +index b24fe03..00a217f 100644 +--- a/cnf/configure_func.sh ++++ b/cnf/configure_func.sh +@@ -191,6 +191,7 @@ checkfunc d_msgrcv 'msgrcv' '0,NULL,0,0,0' 'sys/msg.h' + checkfunc d_msgsnd 'msgsnd' '0,NULL,0,0' 'sys/msg.h' + checkfunc d_msync 'msync' 'NULL,0,0' 'sys/mman.h' + checkfunc d_munmap 'munmap' 'NULL,0' 'sys/mman.h' ++checkfunc d_nanosleep 'nanosleep' 'NULL,NULL' 'time.h' + checkfunc d_newlocale 'newlocale' '0,NULL,0' 'locale.h' + checkfunc d_nice 'nice' '0' 'unistd.h' + checkfunc d_nl_langinfo 'nl_langinfo' '0' 'langinfo.h' diff --git a/pkgs/development/interpreters/perl/interpreter.nix b/pkgs/development/interpreters/perl/interpreter.nix index a501b99967253..88e9c54fec54d 100644 --- a/pkgs/development/interpreters/perl/interpreter.nix +++ b/pkgs/development/interpreters/perl/interpreter.nix @@ -77,7 +77,8 @@ let # binary as early. # # Some more details: https://arsv.github.io/perl-cross/modules.html - ++ lib.optional crossCompiling ./cross.patch; + ++ lib.optional crossCompiling ./cross.patch + ++ lib.optional (crossCompiling && stdenv.hostPlatform.isCygwin) ./fix-cygwin-cross.patch; libc = if stdenv.cc.libc or null != null then stdenv.cc.libc else "/usr"; libcInc = lib.getDev libc; @@ -137,10 +138,18 @@ stdenv.mkDerivation ( '' ) + - # Perl's build system uses the src variable, and its value may end up in - # the output in some cases (when cross-compiling) - '' - unset src + # Perl's build system uses the src variable, and its value may end up in + # the output in some cases (when cross-compiling) + '' + unset src + '' + + lib.optionalString stdenv.buildPlatform.isCygwin '' + substituteInPlace hints/cygwin.sh \ + --replace-fail "PATH='.:/usr/bin/'" "" + substituteInPlace cpan/Win32/Makefile.PL haiku/Haiku/Makefile.PL \ + --replace-fail '/lib/w32api' '${lib.getLib stdenv.cc.libc.w32api}${ + stdenv.cc.libc.w32api.libdir or "/lib/w32api" + }' ''; # Build a thread-safe Perl with a dynamic libperl.so. We need the @@ -158,6 +167,24 @@ stdenv.mkDerivation ( # https://github.com/arsv/perl-cross/issues/158 "-Dd_gnulibc=define" ] + # these currently can't be configured automatically on non-elf systems + # other archs will need verification + ++ lib.optional (stdenv.hostPlatform.isCygwin && stdenv.hostPlatform.isx86_64) [ + "-Dcharsize=1" + "-Dshortsize=2" + "-Dintsize=4" + "-Dlongsize=8" + "-Ddoublesize=8" + "-Dptrsize=8" + "-Dlongdblsize=16" + "-Dlonglongsize=8" + "-Dsizesize=8" + "-Dfpossize=8" + "-Dlseeksize=8" + "-Duidsize=4" + "-Dgidsize=4" + "-Dtimesize=8" + ] else ( [ @@ -267,6 +294,18 @@ stdenv.mkDerivation ( # Default perl does not support --host= & co. configurePlatforms = [ ]; + allowedImpureDLLs = [ + "ADVAPI32.dll" + "NETAPI32.dll" + "SHELL32.dll" + "USER32.dll" + "USERENV.dll" + "VERSION.dll" + "WINHTTP.dll" + "ntdll.dll" + "ole32.dll" + ]; + setupHook = ./setup-hook.sh; env = { @@ -401,4 +440,9 @@ stdenv.mkDerivation ( # TODO merge setup hooks setupHook = ./setup-hook-cross.sh; } + // lib.optionalAttrs (stdenv.hostPlatform.isCygwin) { + # in cygwin we need PATH and LINK_DLL_FOLDERS set up for these dependencies + buildInputs = [ zlib ]; + nativeBuildInputs = lib.optional (!crossCompiling && enableCrypt) libxcrypt; + } ) From 5ce9b5b8169cb8779d1301db48484bacc8776ee6 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 5 Oct 2025 15:06:36 -0300 Subject: [PATCH 025/119] WIP: pcre2: fix cygwin build --- pkgs/development/libraries/pcre2/default.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkgs/development/libraries/pcre2/default.nix b/pkgs/development/libraries/pcre2/default.nix index 2c56ea3a7cc4f..3e00b4b353f8a 100644 --- a/pkgs/development/libraries/pcre2/default.nix +++ b/pkgs/development/libraries/pcre2/default.nix @@ -2,6 +2,7 @@ lib, stdenv, fetchurl, + fetchpatch2, updateAutotoolsGnuConfigScriptsHook, # Causes consistent segfaults on ELFv1 PPC64 when trying to use Perl regex in gnugrep # https://github.com/PCRE2Project/pcre2/issues/762 @@ -17,6 +18,14 @@ stdenv.mkDerivation rec { hash = "sha256-FfvFq6a+7gsXrssEYCrjlDI5OroevY45t8q/fbiDKZ8="; }; + ${if stdenv.hostPlatform.isCygwin then "patches" else null} = + lib.optional stdenv.hostPlatform.isCygwin + (fetchpatch2 { + url = "https://cygwin.com/cgit/cygwin-packages/pcre2/plain/pcre2-10.46-cygwin-jit.patch?id=45f4a0514d89311078f4a6d0bc4d12bcc2c3d4c6"; + hash = "sha256-9fDAzjDgrM016IR8gCzEHn0ZrXhvwTdcjbzSlAV59Zg="; + stripLen = 1; + }); + nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ]; configureFlags = [ From 5766af5c1950e52f910f9e35743d2242502b1696 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 5 Oct 2025 19:32:56 -0300 Subject: [PATCH 026/119] cygwin.w32api: remove trailing slashes from {inc,lib}dir --- pkgs/os-specific/cygwin/w32api/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/cygwin/w32api/default.nix b/pkgs/os-specific/cygwin/w32api/default.nix index bee2690076631..b99f84e67365a 100644 --- a/pkgs/os-specific/cygwin/w32api/default.nix +++ b/pkgs/os-specific/cygwin/w32api/default.nix @@ -27,8 +27,8 @@ enableParallelBuilding = true; passthru = { - incdir = "/include/w32api/"; - libdir = "/lib/w32api/"; + incdir = "/include/w32api"; + libdir = "/lib/w32api"; }; meta = { From 2ea561f667b61c0d1d90ec064e6b1e1166acfce2 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 5 Oct 2025 22:15:37 -0300 Subject: [PATCH 027/119] HACK: libxcrypt: disable tests on cygwin --- pkgs/development/libraries/libxcrypt/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/libxcrypt/default.nix b/pkgs/development/libraries/libxcrypt/default.nix index 4387d24a61e46..ec08231655e0a 100644 --- a/pkgs/development/libraries/libxcrypt/default.nix +++ b/pkgs/development/libraries/libxcrypt/default.nix @@ -64,7 +64,7 @@ stdenv.mkDerivation (finalAttrs: { enableParallelBuilding = true; - doCheck = true; + doCheck = !stdenv.hostPlatform.isCygwin; passthru = { tests = { From e0d4b8ee9780ff5a321060c8fc129dd00beea732 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 7 Oct 2025 09:29:01 -0300 Subject: [PATCH 028/119] bison: disable doInstallCheck on cygwin 133: Output file name: @@ FAILED (output.at:338) 134: Output file name: @{ FAILED (output.at:339) 135: Output file name: @} FAILED (output.at:340) --- pkgs/by-name/bi/bison/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/bi/bison/package.nix b/pkgs/by-name/bi/bison/package.nix index e5c6eef040ae4..88f8e5a19e2dd 100644 --- a/pkgs/by-name/bi/bison/package.nix +++ b/pkgs/by-name/bi/bison/package.nix @@ -48,7 +48,7 @@ stdenv.mkDerivation rec { doCheck = false; # Tests were disabled on LLVM/Darwin due to https://github.com/NixOS/nixpkgs/issues/463659 # TODO: enable doInstallCheck unconditionally when fixed upstream. - doInstallCheck = !stdenv.cc.isClang; + doInstallCheck = !stdenv.cc.isClang && !stdenv.buildPlatform.isCygwin; meta = { homepage = "https://www.gnu.org/software/bison/"; From 693089bc7a14325a4ae006d3335d168a4c9ec58a Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 7 Oct 2025 09:31:22 -0300 Subject: [PATCH 029/119] cygwin.newlib-cygwin: add symlink patch --- ...native-symlinks-when-they-preserve-t.patch | 52 +++++++++++++++++++ .../cygwin/newlib-cygwin/default.nix | 1 + 2 files changed, 53 insertions(+) create mode 100644 pkgs/os-specific/cygwin/newlib-cygwin/Cygwin-only-use-native-symlinks-when-they-preserve-t.patch diff --git a/pkgs/os-specific/cygwin/newlib-cygwin/Cygwin-only-use-native-symlinks-when-they-preserve-t.patch b/pkgs/os-specific/cygwin/newlib-cygwin/Cygwin-only-use-native-symlinks-when-they-preserve-t.patch new file mode 100644 index 0000000000000..a19cdf05c18e9 --- /dev/null +++ b/pkgs/os-specific/cygwin/newlib-cygwin/Cygwin-only-use-native-symlinks-when-they-preserve-t.patch @@ -0,0 +1,52 @@ +From cc2ba5ca9926d696f3a4e1a431a67357e378eba7 Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Mon, 6 Oct 2025 19:53:32 -0300 +Subject: [PATCH] Cygwin: only use native symlinks when they preserve the + target + +We want readlink() to return the original target string as much as +possible. Currently it'll be changed in some common cases: + +x/ -> x +x/../x -> x + +This doesn't normally break the links, but it means the link will change +when archived. With Nix, this can change the hash of a NAR packed tree. +--- + winsup/cygwin/path.cc | 20 ++++++++++++++++++++ + 1 file changed, 20 insertions(+) + +diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc +index 310876b5a..9af599572 100644 +--- a/winsup/cygwin/path.cc ++++ b/winsup/cygwin/path.cc +@@ -1937,6 +1937,26 @@ symlink_native (const char *oldpath, path_conv &win32_newpath) + flags = win32_oldpath.isdir () ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0; + if (wincap.has_unprivileged_createsymlink ()) + flags |= SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE; ++ ++ { ++ char nfpath[SYMLINK_MAX + 1]; ++ symlink_info sym; ++ int res = sys_wcstombs (nfpath, SYMLINK_MAX, final_oldpath->Buffer); ++ if (res > SYMLINK_MAX) ++ { ++ SetLastError (ERROR_FILE_NOT_FOUND); ++ final_newpath->Buffer[1] = L'?'; ++ return -1; ++ } ++ res = sym.posixify (nfpath); ++ if (strcmp (sym.content (), oldpath)) ++ { ++ SetLastError (ERROR_FILE_NOT_FOUND); ++ final_newpath->Buffer[1] = L'?'; ++ return -1; ++ } ++ } ++ + if (!CreateSymbolicLinkW (final_newpath->Buffer, final_oldpath->Buffer, + flags)) + { +-- +2.50.1 + diff --git a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix index 9869493c3be80..f9fef7af0e5a3 100644 --- a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix +++ b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix @@ -46,6 +46,7 @@ # This is required for boost coroutines to work. After we get to the point # where nix runs on cygwin, we can attempt to upstream this again. ./store-tls-pointer-in-win32-tls.patch + ./Cygwin-only-use-native-symlinks-when-they-preserve-t.patch ] # After cygwin hosted builds are working, we should upstream this ++ lib.optional ( From ec18de14ac85fae1b1aeb0d6cb8c758937bea86a Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 7 Oct 2025 10:33:46 -0300 Subject: [PATCH 030/119] libidn2: fix no-bootstrap-reference.nix on cygwin --- .../libidn2/no-bootstrap-reference.nix | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/pkgs/development/libraries/libidn2/no-bootstrap-reference.nix b/pkgs/development/libraries/libidn2/no-bootstrap-reference.nix index 7c01fddb75bd8..c322213522f2d 100644 --- a/pkgs/development/libraries/libidn2/no-bootstrap-reference.nix +++ b/pkgs/development/libraries/libidn2/no-bootstrap-reference.nix @@ -20,26 +20,32 @@ runCommandLocal "${libidn2.pname}-${libidn2.version}" }; inherit (libidn2) meta; } - '' - cp -r '${libidn2.bin}' "$bin" - chmod +w "$bin"/bin/* - patchelf \ - --set-interpreter '${stdenv.cc.bintools.dynamicLinker}' \ - --set-rpath '${ - lib.concatMapStringsSep ":" (p: lib.getLib p + "/lib") [ - stdenv.cc.libc - libunistring - libidn2 - ] - }' \ - "$bin"/bin/* + ( + '' + cp -r '${libidn2.bin}' "$bin" + chmod +w "$bin"/bin/* + '' + + lib.optionalString stdenv.hostPlatform.isElf '' + patchelf \ + --set-interpreter '${stdenv.cc.bintools.dynamicLinker}' \ + --set-rpath '${ + lib.concatMapStringsSep ":" (p: lib.getLib p + "/lib") [ + stdenv.cc.libc + libunistring + libidn2 + ] + }' \ + "$bin"/bin/* + '' + + '' - cp -r '${libidn2.dev}' "$dev" - chmod +w "$dev"/nix-support/propagated-build-inputs - substituteInPlace "$dev"/nix-support/propagated-build-inputs \ - --replace '${libidn2.bin}' "$bin" - substituteInPlace "$dev"/lib/pkgconfig/libidn2.pc \ - --replace '${libidn2.dev}' "$dev" + cp -r '${libidn2.dev}' "$dev" + chmod +w "$dev"/nix-support/propagated-build-inputs + substituteInPlace "$dev"/nix-support/propagated-build-inputs \ + --replace '${libidn2.bin}' "$bin" + substituteInPlace "$dev"/lib/pkgconfig/libidn2.pc \ + --replace '${libidn2.dev}' "$dev" - ln -s '${libidn2.out}' "$out" # it's hard to be without any $out - '' + ln -s '${libidn2.out}' "$out" # it's hard to be without any $out + '' + ) From b60f1f14daf54fb0f29ae3bd8b00d9e4f0fab2a7 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 7 Oct 2025 10:39:56 -0300 Subject: [PATCH 031/119] ed: disable doCheck on cygwin --- pkgs/by-name/ed/ed/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/ed/ed/package.nix b/pkgs/by-name/ed/ed/package.nix index 8e23c84e54fa0..b00ad47d7b114 100644 --- a/pkgs/by-name/ed/ed/package.nix +++ b/pkgs/by-name/ed/ed/package.nix @@ -31,7 +31,7 @@ stdenv.mkDerivation (finalAttrs: { strictDeps = true; - doCheck = true; + doCheck = !stdenv.hostPlatform.isCygwin; passthru = { tests.version = testers.testVersion { From c25e61a311339ecdaa8e83952a0f04c2ea38b4e9 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 7 Oct 2025 19:16:32 -0300 Subject: [PATCH 032/119] unzip: fix cygwin build --- pkgs/by-name/un/unzip/fix-cygwin-build.patch | 26 ++++++++++++++++++++ pkgs/by-name/un/unzip/package.nix | 6 +++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 pkgs/by-name/un/unzip/fix-cygwin-build.patch diff --git a/pkgs/by-name/un/unzip/fix-cygwin-build.patch b/pkgs/by-name/un/unzip/fix-cygwin-build.patch new file mode 100644 index 0000000000000..e53ba19428239 --- /dev/null +++ b/pkgs/by-name/un/unzip/fix-cygwin-build.patch @@ -0,0 +1,26 @@ +diff --git a/unix/unxcfg.h b/unix/unxcfg.h +index bcdfe16..0e00744 100644 +--- a/unix/unxcfg.h ++++ b/unix/unxcfg.h +@@ -107,6 +107,8 @@ typedef struct stat z_stat; + # ifndef timezone + # define timezone _timezone + # endif ++# include ++# define GOT_UTIMBUF + #endif + + #ifdef BSD +diff --git a/unix/Makefile b/unix/Makefile +index a0a6270..51f243d 100644 +--- a/unix/Makefile ++++ b/unix/Makefile +@@ -125,7 +125,7 @@ prefix = /usr/local + BINDIR = $(prefix)/bin# where to install executables + MANDIR = $(prefix)/man/man$(manext)# where to install man pages + INSTALLEDBIN = $(BINDIR)/funzip$E $(BINDIR)/unzip$E $(BINDIR)/unzipsfx$E \ +- $(BINDIR)/zipgrep$E $(BINDIR)/zipinfo$E ++ $(BINDIR)/zipgrep $(BINDIR)/zipinfo$E + INSTALLEDMAN = $(MANDIR)/funzip.$(manext) $(MANDIR)/unzip.$(manext) \ + $(MANDIR)/unzipsfx.$(manext) $(MANDIR)/zipgrep.$(manext) \ + $(MANDIR)/zipinfo.$(manext) diff --git a/pkgs/by-name/un/unzip/package.nix b/pkgs/by-name/un/unzip/package.nix index efe3226d6cdd0..c6fd0b33ee42e 100644 --- a/pkgs/by-name/un/unzip/package.nix +++ b/pkgs/by-name/un/unzip/package.nix @@ -67,7 +67,8 @@ stdenv.mkDerivation rec { url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/app-arch/unzip/files/unzip-6.0-natspec.patch?id=56bd759df1d0c750a065b8c845e93d5dfa6b549d"; name = "unzip-6.0-natspec.patch"; sha256 = "67ab260ae6adf8e7c5eda2d1d7846929b43562943ec4aff629bd7018954058b1"; - }); + }) + ++ lib.optional stdenv.hostPlatform.isCygwin ./fix-cygwin-build.patch; # gcc-15 uses c23 standard, which removed non-prototype function declarations. postPatch = '' @@ -96,7 +97,8 @@ stdenv.mkDerivation rec { installFlags = [ "prefix=${placeholder "out"}" - ]; + ] + ++ lib.optional stdenv.hostPlatform.isCygwin "E=.exe"; setupHook = ./setup-hook.sh; From 7f27736630606345309bc9b224a03c1526ba4724 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 7 Oct 2025 22:29:51 -0300 Subject: [PATCH 033/119] tcl: fix cygwin build --- .../interpreters/tcl/fix-cygwin-build.patch | 619 ++++++++++++++++++ pkgs/development/interpreters/tcl/generic.nix | 234 +++---- 2 files changed, 743 insertions(+), 110 deletions(-) create mode 100644 pkgs/development/interpreters/tcl/fix-cygwin-build.patch diff --git a/pkgs/development/interpreters/tcl/fix-cygwin-build.patch b/pkgs/development/interpreters/tcl/fix-cygwin-build.patch new file mode 100644 index 0000000000000..2cee46424207a --- /dev/null +++ b/pkgs/development/interpreters/tcl/fix-cygwin-build.patch @@ -0,0 +1,619 @@ +From 3b266a8b33a4b1090a7d87662b6d1e23187c96d3 Mon Sep 17 00:00:00 2001 +From: David McFarland +Date: Wed, 8 Oct 2025 15:37:12 -0300 +Subject: [PATCH] fix cygwin build + +--- + generic/tcl.h | 2 +- + generic/tclCmdAH.c | 2 +- + generic/tclDecls.h | 2 +- + generic/tclFCmd.c | 2 +- + generic/tclIOSock.c | 2 +- + generic/tclIntPlatDecls.h | 12 ++++++------ + generic/tclPanic.c | 8 ++++---- + generic/tclPlatDecls.h | 8 ++++---- + generic/tclStubInit.c | 10 +++++----- + tools/genStubs.tcl | 9 --------- + unix/Makefile.in | 5 +---- + unix/tcl.m4 | 15 ++++++++++++++- + unix/tclUnixFCmd.c | 37 +++++-------------------------------- + unix/tclUnixFile.c | 4 ++-- + unix/tclUnixInit.c | 6 +++--- + unix/tclUnixNotfy.c | 22 +++++++++++----------- + unix/tclUnixPort.h | 2 +- + 17 files changed, 61 insertions(+), 87 deletions(-) + +diff --git a/generic/tcl.h b/generic/tcl.h +index fc772d5b3c..539f7ce300 100644 +--- a/generic/tcl.h ++++ b/generic/tcl.h +@@ -462,7 +462,7 @@ typedef unsigned TCL_WIDE_INT_TYPE Tcl_WideUInt; + # else + typedef struct _stat32i64 Tcl_StatBuf; + # endif /* _MSC_VER < 1400 */ +-#elif defined(__CYGWIN__) ++#elif 0 + typedef struct { + unsigned st_dev; + unsigned short st_ino; +diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c +index adbe9a699d..f0933d12a2 100644 +--- a/generic/tclCmdAH.c ++++ b/generic/tclCmdAH.c +@@ -1788,7 +1788,7 @@ FileAttrIsOwnedCmd( + int objc, + Tcl_Obj *const objv[]) + { +-#ifdef __CYGWIN__ ++#if 0 + #define geteuid() (short)(geteuid)() + #endif + #if !defined(_WIN32) +diff --git a/generic/tclDecls.h b/generic/tclDecls.h +index 27b4edc4cd..925050ddf1 100644 +--- a/generic/tclDecls.h ++++ b/generic/tclDecls.h +@@ -4055,7 +4055,7 @@ extern const TclStubs *tclStubsPtr; + *(t) = _t.now; \ + } while (0) + # endif +-# if defined(__CYGWIN__) && defined(TCL_WIDE_INT_IS_LONG) ++# if 0 + /* On Cygwin64, long is 64-bit while on Win64 long is 32-bit. Therefore + * we have to make sure that all stub entries on Cygwin64 follow the + * Win64 signature. Cygwin64 stubbed extensions cannot use those stub +diff --git a/generic/tclFCmd.c b/generic/tclFCmd.c +index e55088209c..c6b9e1881c 100644 +--- a/generic/tclFCmd.c ++++ b/generic/tclFCmd.c +@@ -523,7 +523,7 @@ CopyRenameOneFile( + * 16 bits and we get collisions. See bug #2015723. + */ + +-#if !defined(_WIN32) && !defined(__CYGWIN__) ++#if !defined(_WIN32) + if ((sourceStatBuf.st_ino != 0) && (targetStatBuf.st_ino != 0)) { + if ((sourceStatBuf.st_ino == targetStatBuf.st_ino) && + (sourceStatBuf.st_dev == targetStatBuf.st_dev)) { +diff --git a/generic/tclIOSock.c b/generic/tclIOSock.c +index 64139609a5..b75fc18158 100644 +--- a/generic/tclIOSock.c ++++ b/generic/tclIOSock.c +@@ -104,7 +104,7 @@ TclSockGetPort( + *---------------------------------------------------------------------- + */ + +-#if !defined(_WIN32) && !defined(__CYGWIN__) ++#if !defined(_WIN32) + # define SOCKET int + #endif + +diff --git a/generic/tclIntPlatDecls.h b/generic/tclIntPlatDecls.h +index 5bd4828441..5d8c43dce3 100644 +--- a/generic/tclIntPlatDecls.h ++++ b/generic/tclIntPlatDecls.h +@@ -40,7 +40,7 @@ extern "C" { + * Exported function declarations: + */ + +-#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(MAC_OSX_TCL) /* UNIX */ ++#if !defined(_WIN32) && !defined(MAC_OSX_TCL) /* UNIX */ + /* 0 */ + EXTERN void TclGetAndDetachPids(Tcl_Interp *interp, + Tcl_Channel chan); +@@ -116,7 +116,7 @@ EXTERN int TclUnixOpenTemporaryFile(Tcl_Obj *dirObj, + Tcl_Obj *basenameObj, Tcl_Obj *extensionObj, + Tcl_Obj *resultingNameObj); + #endif /* UNIX */ +-#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ ++#if defined(_WIN32) /* WIN */ + /* 0 */ + EXTERN void TclWinConvertError(DWORD errCode); + /* 1 */ +@@ -272,7 +272,7 @@ typedef struct TclIntPlatStubs { + int magic; + void *hooks; + +-#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(MAC_OSX_TCL) /* UNIX */ ++#if !defined(_WIN32) && !defined(MAC_OSX_TCL) /* UNIX */ + void (*tclGetAndDetachPids) (Tcl_Interp *interp, Tcl_Channel chan); /* 0 */ + int (*tclpCloseFile) (TclFile file); /* 1 */ + Tcl_Channel (*tclpCreateCommandChannel) (TclFile readFile, TclFile writeFile, TclFile errorFile, int numPids, Tcl_Pid *pidPtr); /* 2 */ +@@ -305,7 +305,7 @@ typedef struct TclIntPlatStubs { + int (*tclWinCPUID) (unsigned int index, unsigned int *regs); /* 29 */ + int (*tclUnixOpenTemporaryFile) (Tcl_Obj *dirObj, Tcl_Obj *basenameObj, Tcl_Obj *extensionObj, Tcl_Obj *resultingNameObj); /* 30 */ + #endif /* UNIX */ +-#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ ++#if defined(_WIN32) /* WIN */ + void (*tclWinConvertError) (DWORD errCode); /* 0 */ + void (*tclWinConvertWSAError) (DWORD errCode); /* 1 */ + struct servent * (*tclWinGetServByName) (const char *nm, const char *proto); /* 2 */ +@@ -385,7 +385,7 @@ extern const TclIntPlatStubs *tclIntPlatStubsPtr; + * Inline function declarations: + */ + +-#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(MAC_OSX_TCL) /* UNIX */ ++#if !defined(_WIN32) && !defined(MAC_OSX_TCL) /* UNIX */ + #define TclGetAndDetachPids \ + (tclIntPlatStubsPtr->tclGetAndDetachPids) /* 0 */ + #define TclpCloseFile \ +@@ -441,7 +441,7 @@ extern const TclIntPlatStubs *tclIntPlatStubsPtr; + #define TclUnixOpenTemporaryFile \ + (tclIntPlatStubsPtr->tclUnixOpenTemporaryFile) /* 30 */ + #endif /* UNIX */ +-#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ ++#if defined(_WIN32) /* WIN */ + #define TclWinConvertError \ + (tclIntPlatStubsPtr->tclWinConvertError) /* 0 */ + #define TclWinConvertWSAError \ +diff --git a/generic/tclPanic.c b/generic/tclPanic.c +index 56c8fbcbae..aea7121cad 100644 +--- a/generic/tclPanic.c ++++ b/generic/tclPanic.c +@@ -14,7 +14,7 @@ + */ + + #include "tclInt.h" +-#if defined(_WIN32) || defined(__CYGWIN__) ++#if defined(_WIN32) + MODULE_SCOPE TCL_NORETURN void tclWinDebugPanic(const char *format, ...); + #endif + +@@ -23,7 +23,7 @@ + * procedure. + */ + +-#if defined(__CYGWIN__) ++#if 0 + static Tcl_PanicProc *panicProc = tclWinDebugPanic; + #else + static Tcl_PanicProc *panicProc = NULL; +@@ -52,7 +52,7 @@ Tcl_SetPanicProc( + #if defined(_WIN32) + /* tclWinDebugPanic only installs if there is no panicProc yet. */ + if ((proc != tclWinDebugPanic) || (panicProc == NULL)) +-#elif defined(__CYGWIN__) ++#elif 0 + if (proc == NULL) + panicProc = tclWinDebugPanic; + else +@@ -107,7 +107,7 @@ Tcl_PanicVA( + fprintf(stderr, "\n"); + fflush(stderr); + } +-#if defined(_WIN32) || defined(__CYGWIN__) ++#if defined(_WIN32) + #if defined(__GNUC__) + __builtin_trap(); + #elif defined(_WIN64) +diff --git a/generic/tclPlatDecls.h b/generic/tclPlatDecls.h +index 46181a1d61..b11e851dbf 100644 +--- a/generic/tclPlatDecls.h ++++ b/generic/tclPlatDecls.h +@@ -31,7 +31,7 @@ + * TCHAR is needed here for win32, so if it is not defined yet do it here. + * This way, we don't need to include just for one define. + */ +-#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(_TCHAR_DEFINED) ++#if defined(_WIN32) && !defined(_TCHAR_DEFINED) + # if defined(_UNICODE) + typedef wchar_t TCHAR; + # else +@@ -50,7 +50,7 @@ extern "C" { + * Exported function declarations: + */ + +-#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ ++#if defined(_WIN32) /* WIN */ + /* 0 */ + EXTERN TCHAR * Tcl_WinUtfToTChar(const char *str, int len, + Tcl_DString *dsPtr); +@@ -81,7 +81,7 @@ typedef struct TclPlatStubs { + int magic; + void *hooks; + +-#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ ++#if defined(_WIN32) /* WIN */ + TCHAR * (*tcl_WinUtfToTChar) (const char *str, int len, Tcl_DString *dsPtr); /* 0 */ + char * (*tcl_WinTCharToUtf) (const TCHAR *str, int len, Tcl_DString *dsPtr); /* 1 */ + void (*reserved2)(void); +@@ -106,7 +106,7 @@ extern const TclPlatStubs *tclPlatStubsPtr; + * Inline function declarations: + */ + +-#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ ++#if defined(_WIN32) /* WIN */ + #define Tcl_WinUtfToTChar \ + (tclPlatStubsPtr->tcl_WinUtfToTChar) /* 0 */ + #define Tcl_WinTCharToUtf \ +diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c +index cd6d46b2dd..f0966d9b7f 100644 +--- a/generic/tclStubInit.c ++++ b/generic/tclStubInit.c +@@ -139,7 +139,7 @@ static const char *TclGetStartupScriptFileName(void) + return Tcl_GetString(path); + } + +-#if defined(_WIN32) || defined(__CYGWIN__) ++#if defined(_WIN32) + #undef TclWinNToHS + #define TclWinNToHS winNToHS + static unsigned short TclWinNToHS(unsigned short ns) { +@@ -169,7 +169,7 @@ TclWinConvertError_(unsigned errCode) { + # define TclUnixOpenTemporaryFile 0 + # define TclpReaddir 0 + # define TclpIsAtty 0 +-#elif defined(__CYGWIN__) ++#elif 0 + # define TclpIsAtty isatty + # define TclWinSetInterfaces (void (*) (int))(void *)doNothing + # define TclWinAddProcess (void (*) (void *, unsigned int))(void *)doNothing +@@ -764,7 +764,7 @@ static const TclIntStubs tclIntStubs = { + static const TclIntPlatStubs tclIntPlatStubs = { + TCL_STUB_MAGIC, + 0, +-#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(MAC_OSX_TCL) /* UNIX */ ++#if !defined(_WIN32) && !defined(MAC_OSX_TCL) /* UNIX */ + TclGetAndDetachPids, /* 0 */ + TclpCloseFile, /* 1 */ + TclpCreateCommandChannel, /* 2 */ +@@ -797,7 +797,7 @@ static const TclIntPlatStubs tclIntPlatStubs = { + TclWinCPUID, /* 29 */ + TclUnixOpenTemporaryFile, /* 30 */ + #endif /* UNIX */ +-#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ ++#if defined(_WIN32) /* WIN */ + TclWinConvertError, /* 0 */ + TclWinConvertWSAError, /* 1 */ + TclWinGetServByName, /* 2 */ +@@ -868,7 +868,7 @@ static const TclIntPlatStubs tclIntPlatStubs = { + static const TclPlatStubs tclPlatStubs = { + TCL_STUB_MAGIC, + 0, +-#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */ ++#if defined(_WIN32) /* WIN */ + Tcl_WinUtfToTChar, /* 0 */ + Tcl_WinTCharToUtf, /* 1 */ + 0, /* 2 */ +diff --git a/tools/genStubs.tcl b/tools/genStubs.tcl +index 3c9964556f..416a89e14a 100644 +--- a/tools/genStubs.tcl ++++ b/tools/genStubs.tcl +@@ -299,9 +299,6 @@ proc genStubs::addPlatformGuard {plat iftxt {eltxt {}} {withCygwin 0}} { + switch $plat { + win { + append text "#if defined(_WIN32)" +- if {$withCygwin} { +- append text " || defined(__CYGWIN__)" +- } + append text " /* WIN */\n${iftxt}" + if {$eltxt ne ""} { + append text "#else /* WIN */\n${eltxt}" +@@ -310,9 +307,6 @@ proc genStubs::addPlatformGuard {plat iftxt {eltxt {}} {withCygwin 0}} { + } + unix { + append text "#if !defined(_WIN32)" +- if {$withCygwin} { +- append text " && !defined(__CYGWIN__)" +- } + append text " && !defined(MAC_OSX_TCL)\ + /* UNIX */\n${iftxt}" + if {$eltxt ne ""} { +@@ -336,9 +330,6 @@ proc genStubs::addPlatformGuard {plat iftxt {eltxt {}} {withCygwin 0}} { + } + x11 { + append text "#if !(defined(_WIN32)" +- if {$withCygwin} { +- append text " || defined(__CYGWIN__)" +- } + append text " || defined(MAC_OSX_TK))\ + /* X11 */\n${iftxt}" + if {$eltxt ne ""} { +diff --git a/unix/Makefile.in b/unix/Makefile.in +index bc743b3892..dc80d61c2f 100644 +--- a/unix/Makefile.in ++++ b/unix/Makefile.in +@@ -358,7 +358,7 @@ NOTIFY_OBJS = tclUnixNotfy.o + + MAC_OSX_OBJS = tclMacOSXBundle.o tclMacOSXFCmd.o tclMacOSXNotify.o + +-CYGWIN_OBJS = tclWinError.o ++CYGWIN_OBJS = + + DTRACE_OBJ = tclDTrace.o + +@@ -637,9 +637,6 @@ ${LIB_FILE}: ${STUB_LIB_FILE} ${OBJS} + @MAKE_LIB@ + + ${STUB_LIB_FILE}: ${STUB_LIB_OBJS} +- @if test "x${LIB_FILE}" = "xlibtcl${MAJOR_VERSION}.${MINOR_VERSION}.dll"; then \ +- (cd ${TOP_DIR}/win; ${MAKE} winextensions); \ +- fi + rm -f $@ + @MAKE_STUB_LIB@ + +diff --git a/unix/tcl.m4 b/unix/tcl.m4 +index 7f5464e651..febae32214 100644 +--- a/unix/tcl.m4 ++++ b/unix/tcl.m4 +@@ -1183,7 +1183,20 @@ AC_DEFUN([SC_CONFIG_CFLAGS], [ + CC_SEARCH_FLAGS="" + LD_SEARCH_FLAGS="" + ;; +- CYGWIN_*|MINGW32_*|MSYS_*) ++ CYGWIN_*) ++ SHLIB_CFLAGS="" ++ SHLIB_LD='${CC} -shared' ++ SHLIB_SUFFIX=".dll" ++ DL_OBJS="tclLoadDl.o" ++ DL_LIBS="-ldl" ++ CC_SEARCH_FLAGS="" ++ LD_SEARCH_FLAGS="" ++ TCL_NEEDS_EXP_FILE=1 ++ TCL_EXPORT_FILE_SUFFIX='${VERSION}\$\{DBGX\}.dll.a' ++ SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\$[@].a" ++ do64bit_ok=yes ++ ;; ++ MINGW32_*|MSYS_*) + SHLIB_CFLAGS="-fno-common" + SHLIB_LD='${CC} -shared' + SHLIB_SUFFIX=".dll" +diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c +index 3d44124e8b..40e3a8a666 100644 +--- a/unix/tclUnixFCmd.c ++++ b/unix/tclUnixFCmd.c +@@ -91,7 +91,7 @@ static int SetPermissionsAttribute(Tcl_Interp *interp, + Tcl_Obj *attributePtr); + static int GetModeFromPermString(Tcl_Interp *interp, + const char *modeStringPtr, mode_t *modePtr); +-#if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) || defined(__CYGWIN__) ++#if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) + static int GetUnixFileAttributes(Tcl_Interp *interp, int objIndex, + Tcl_Obj *fileName, Tcl_Obj **attributePtrPtr); + static int SetUnixFileAttributes(Tcl_Interp *interp, int objIndex, +@@ -124,20 +124,11 @@ extern const char *const tclpFileAttrStrings[]; + + #else /* !DJGPP */ + enum { +-#if defined(__CYGWIN__) +- UNIX_ARCHIVE_ATTRIBUTE, +-#endif + UNIX_GROUP_ATTRIBUTE, +-#if defined(__CYGWIN__) +- UNIX_HIDDEN_ATTRIBUTE, +-#endif + UNIX_OWNER_ATTRIBUTE, UNIX_PERMISSIONS_ATTRIBUTE, +-#if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) || defined(__CYGWIN__) ++#if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) + UNIX_READONLY_ATTRIBUTE, + #endif +-#if defined(__CYGWIN__) +- UNIX_SYSTEM_ATTRIBUTE, +-#endif + #ifdef MAC_OSX_TCL + MACOSX_CREATOR_ATTRIBUTE, MACOSX_TYPE_ATTRIBUTE, MACOSX_HIDDEN_ATTRIBUTE, + MACOSX_RSRCLENGTH_ATTRIBUTE, +@@ -147,20 +138,11 @@ enum { + + MODULE_SCOPE const char *const tclpFileAttrStrings[]; + const char *const tclpFileAttrStrings[] = { +-#if defined(__CYGWIN__) +- "-archive", +-#endif + "-group", +-#if defined(__CYGWIN__) +- "-hidden", +-#endif + "-owner", "-permissions", +-#if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) || defined(__CYGWIN__) ++#if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) + "-readonly", + #endif +-#if defined(__CYGWIN__) +- "-system", +-#endif + #ifdef MAC_OSX_TCL + "-creator", "-type", "-hidden", "-rsrclength", + #endif +@@ -169,19 +151,10 @@ const char *const tclpFileAttrStrings[] = { + + MODULE_SCOPE const TclFileAttrProcs tclpFileAttrProcs[]; + const TclFileAttrProcs tclpFileAttrProcs[] = { +-#if defined(__CYGWIN__) +- {GetUnixFileAttributes, SetUnixFileAttributes}, +-#endif + {GetGroupAttribute, SetGroupAttribute}, +-#if defined(__CYGWIN__) +- {GetUnixFileAttributes, SetUnixFileAttributes}, +-#endif + {GetOwnerAttribute, SetOwnerAttribute}, + {GetPermissionsAttribute, SetPermissionsAttribute}, +-#if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) || defined(__CYGWIN__) +- {GetUnixFileAttributes, SetUnixFileAttributes}, +-#endif +-#if defined(__CYGWIN__) ++#if defined(HAVE_CHFLAGS) && defined(UF_IMMUTABLE) + {GetUnixFileAttributes, SetUnixFileAttributes}, + #endif + #ifdef MAC_OSX_TCL +@@ -2273,7 +2246,7 @@ DefaultTempDir(void) + return TCL_TEMPORARY_FILE_DIRECTORY; + } + +-#if defined(__CYGWIN__) ++#if 0 + + static void + StatError( +diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c +index 9769b1338f..530b40a556 100644 +--- a/unix/tclUnixFile.c ++++ b/unix/tclUnixFile.c +@@ -39,7 +39,7 @@ TclpFindExecutable( + const char *argv0) /* The value of the application's argv[0] + * (native). */ + { +-#ifdef __CYGWIN__ ++#if 0 + int length; + wchar_t buf[PATH_MAX] = L""; + char name[PATH_MAX * 3 + 1]; +@@ -1179,7 +1179,7 @@ TclpUtime( + return utime((const char *)Tcl_FSGetNativePath(pathPtr), tval); + } + +-#ifdef __CYGWIN__ ++#if 0 + + int + TclOSstat( +diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c +index c7b2efe811..ecd94fe7e0 100644 +--- a/unix/tclUnixInit.c ++++ b/unix/tclUnixInit.c +@@ -32,7 +32,7 @@ + # endif + #endif + +-#ifdef __CYGWIN__ ++#if 0 + #ifdef __cplusplus + extern "C" { + #endif +@@ -786,7 +786,7 @@ void + TclpSetVariables( + Tcl_Interp *interp) + { +-#ifdef __CYGWIN__ ++#if 0 + SYSTEM_INFO sysInfo; + static OSVERSIONINFOW osInfo; + static int osInfoInitialized = 0; +@@ -873,7 +873,7 @@ TclpSetVariables( + #endif + + unameOK = 0; +-#ifdef __CYGWIN__ ++#if 0 + unameOK = 1; + if (!osInfoInitialized) { + void *handle = GetModuleHandleW(L"NTDLL"); +diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c +index 0bee2f1cfa..087e58b0c5 100644 +--- a/unix/tclUnixNotfy.c ++++ b/unix/tclUnixNotfy.c +@@ -93,7 +93,7 @@ typedef struct ThreadSpecificData { + * from these pointers. You must hold the + * notifierMutex lock before accessing these + * fields. */ +-#ifdef __CYGWIN__ ++#if 0 + void *event; /* Any other thread alerts a notifier that an + * event is ready to be processed by sending + * this event. */ +@@ -211,7 +211,7 @@ static int FileHandlerEventProc(Tcl_Event *evPtr, int flags); + * Import of Windows API when building threaded with Cygwin. + */ + +-#if defined(TCL_THREADS) && defined(__CYGWIN__) ++#if 0 + typedef struct { + void *hwnd; /* Messaging window. */ + unsigned int *message; /* Message payload. */ +@@ -339,7 +339,7 @@ Tcl_InitNotifier(void) + * Initialize thread specific condition variable for this thread. + */ + if (tsdPtr->waitCVinitialized == 0) { +-#ifdef __CYGWIN__ ++#if 0 + WNDCLASSW clazz; + + clazz.style = 0; +@@ -453,7 +453,7 @@ Tcl_FinalizeNotifier( + * Clean up any synchronization objects in the thread local storage. + */ + +-#ifdef __CYGWIN__ ++#if 0 + DestroyWindow(tsdPtr->hwnd); + CloseHandle(tsdPtr->event); + #else /* __CYGWIN__ */ +@@ -499,7 +499,7 @@ Tcl_AlertNotifier( + pthread_mutex_lock(¬ifierMutex); + tsdPtr->eventReady = 1; + +-# ifdef __CYGWIN__ ++# if 0 + PostMessageW(tsdPtr->hwnd, 1024, 0, 0); + # else + pthread_cond_broadcast(&tsdPtr->waitCV); +@@ -812,7 +812,7 @@ FileHandlerEventProc( + return 1; + } + +-#if defined(TCL_THREADS) && defined(__CYGWIN__) ++#if 0 + + static unsigned int __stdcall + NotifierProc( +@@ -868,7 +868,7 @@ Tcl_WaitForEvent( + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + #ifdef TCL_THREADS + int waitForFiles; +-# ifdef __CYGWIN__ ++# if 0 + MSG msg; + # endif /* __CYGWIN__ */ + #else /* !TCL_THREADS */ +@@ -983,7 +983,7 @@ Tcl_WaitForEvent( + FD_ZERO(&tsdPtr->readyMasks.exception); + + if (!tsdPtr->eventReady) { +-#ifdef __CYGWIN__ ++#if 0 + if (!PeekMessageW(&msg, NULL, 0, 0, 0)) { + unsigned int timeout; + +@@ -1014,7 +1014,7 @@ Tcl_WaitForEvent( + } + tsdPtr->eventReady = 0; + +-#ifdef __CYGWIN__ ++#if 0 + while (PeekMessageW(&msg, NULL, 0, 0, 0)) { + /* + * Retrieve and dispatch the message. +@@ -1304,7 +1304,7 @@ NotifierThreadProc( + tsdPtr->onList = 0; + tsdPtr->pollState = 0; + } +-#ifdef __CYGWIN__ ++#if 0 + PostMessageW(tsdPtr->hwnd, 1024, 0, 0); + #else /* __CYGWIN__ */ + pthread_cond_broadcast(&tsdPtr->waitCV); +@@ -1454,7 +1454,7 @@ AtForkChild(void) + * The tsdPtr from before the fork is copied as well. But since + * we are paranoiac, we don't trust its condvar and reset it. + */ +-#ifdef __CYGWIN__ ++#if 0 + DestroyWindow(tsdPtr->hwnd); + tsdPtr->hwnd = CreateWindowExW(NULL, NotfyClassName, + NotfyClassName, 0, 0, 0, 0, 0, NULL, NULL, +diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h +index 486fa23e38..63d8c51383 100644 +--- a/unix/tclUnixPort.h ++++ b/unix/tclUnixPort.h +@@ -85,7 +85,7 @@ typedef off_t Tcl_SeekOffset; + # define TclOSopen open + #endif + +-#ifdef __CYGWIN__ ++#if 0 + #ifdef __cplusplus + extern "C" { + #endif +-- +2.50.1 + diff --git a/pkgs/development/interpreters/tcl/generic.nix b/pkgs/development/interpreters/tcl/generic.nix index 7ecc8250b9c24..260011227393e 100644 --- a/pkgs/development/interpreters/tcl/generic.nix +++ b/pkgs/development/interpreters/tcl/generic.nix @@ -7,6 +7,7 @@ tzdata, zip, zlib, + fetchurl, # Version specific stuff release, @@ -17,127 +18,140 @@ }: let - baseInterp = stdenv.mkDerivation rec { - pname = "tcl"; - inherit version src; + baseInterp = stdenv.mkDerivation ( + rec { + pname = "tcl"; + inherit version src; - outputs = [ - "out" - "man" - ]; + outputs = [ + "out" + "man" + ]; - setOutputFlags = false; + setOutputFlags = false; - postPatch = '' - substituteInPlace library/clock.tcl \ - --replace "/usr/share/zoneinfo" "${tzdata}/share/zoneinfo" \ - --replace "/usr/share/lib/zoneinfo" "" \ - --replace "/usr/lib/zoneinfo" "" \ - --replace "/usr/local/etc/zoneinfo" "" - '' - + extraPatch; + postPatch = '' + substituteInPlace library/clock.tcl \ + --replace "/usr/share/zoneinfo" "${tzdata}/share/zoneinfo" \ + --replace "/usr/share/lib/zoneinfo" "" \ + --replace "/usr/lib/zoneinfo" "" \ + --replace "/usr/local/etc/zoneinfo" "" + '' + + extraPatch; - nativeBuildInputs = lib.optionals (lib.versionAtLeast version "9.0") [ - # Only used to detect the presence of zlib. Could be replaced with a stub. - zip - ]; + nativeBuildInputs = lib.optionals (lib.versionAtLeast version "9.0") [ + # Only used to detect the presence of zlib. Could be replaced with a stub. + zip + ]; - buildInputs = lib.optionals (lib.versionAtLeast version "9.0") [ - zlib - ]; + buildInputs = lib.optionals (lib.versionAtLeast version "9.0") [ + zlib + ]; - preConfigure = '' - cd unix - ''; + preConfigure = '' + cd unix + ''; - # Note: pre-9.0 flags are temporarily interspersed to avoid a mass rebuild. - configureFlags = - lib.optionals (lib.versionOlder version "9.0") [ - "--enable-threads" - ] - ++ [ - # Note: using $out instead of $man to prevent a runtime dependency on $man. - "--mandir=${placeholder "out"}/share/man" - ] - ++ lib.optionals (lib.versionOlder version "9.0") [ - "--enable-man-symlinks" - # Don't install tzdata because NixOS already has a more up-to-date copy. - "--with-tzdata=no" - ] - ++ lib.optionals (lib.versionOlder version "8.6") [ - # configure check broke due to GCC 14 - "ac_cv_header_stdc=yes" - ] - ++ lib.optionals (lib.versionAtLeast version "9.0") [ - # By default, tcl libraries get zipped and embedded into libtcl*.so, - # which gets `zipfs mount`ed at runtime. This is fragile (for example - # stripping the .so removes the zip trailer), so we install them as - # traditional files. - # This might make tcl slower to start from slower storage on cold cache, - # however according to my benchmarks on fast storage and warm cache - # tcl built with --disable-zipfs actually starts in half the time. - "--disable-zipfs" - ] - ++ [ - # During cross compilation, the tcl build system assumes that libc - # functions are broken if it cannot test if they are broken or not and - # then causes a link error on static platforms due to symbol conflict. - # These functions are *checks notes* strtoul and strstr. These are - # never broken on modern platforms! - "tcl_cv_strtod_unbroken=ok" - "tcl_cv_strtoul_unbroken=ok" - "tcl_cv_strstr_unbroken=ok" - ] - ++ lib.optional stdenv.hostPlatform.is64bit "--enable-64bit"; + # Note: pre-9.0 flags are temporarily interspersed to avoid a mass rebuild. + configureFlags = + lib.optionals (lib.versionOlder version "9.0") [ + "--enable-threads" + ] + ++ [ + # Note: using $out instead of $man to prevent a runtime dependency on $man. + "--mandir=${placeholder "out"}/share/man" + ] + ++ lib.optionals (lib.versionOlder version "9.0") [ + "--enable-man-symlinks" + # Don't install tzdata because NixOS already has a more up-to-date copy. + "--with-tzdata=no" + ] + ++ lib.optionals (lib.versionOlder version "8.6") [ + # configure check broke due to GCC 14 + "ac_cv_header_stdc=yes" + ] + ++ lib.optionals (lib.versionAtLeast version "9.0") [ + # By default, tcl libraries get zipped and embedded into libtcl*.so, + # which gets `zipfs mount`ed at runtime. This is fragile (for example + # stripping the .so removes the zip trailer), so we install them as + # traditional files. + # This might make tcl slower to start from slower storage on cold cache, + # however according to my benchmarks on fast storage and warm cache + # tcl built with --disable-zipfs actually starts in half the time. + "--disable-zipfs" + ] + ++ [ + # During cross compilation, the tcl build system assumes that libc + # functions are broken if it cannot test if they are broken or not and + # then causes a link error on static platforms due to symbol conflict. + # These functions are *checks notes* strtoul and strstr. These are + # never broken on modern platforms! + "tcl_cv_strtod_unbroken=ok" + "tcl_cv_strtoul_unbroken=ok" + "tcl_cv_strstr_unbroken=ok" + ] + ++ lib.optional stdenv.hostPlatform.is64bit "--enable-64bit"; - enableParallelBuilding = true; + enableParallelBuilding = true; - postInstall = - let - dllExtension = stdenv.hostPlatform.extensions.sharedLibrary; - staticExtension = stdenv.hostPlatform.extensions.staticLibrary; - in - '' - make install-private-headers - ln -s $out/bin/tclsh${release} $out/bin/tclsh - if [[ -e $out/lib/libtcl${release}${staticExtension} ]]; then - ln -s $out/lib/libtcl${release}${staticExtension} $out/lib/libtcl${staticExtension} - fi - ${lib.optionalString (!stdenv.hostPlatform.isStatic) '' - ln -s $out/lib/libtcl${release}${dllExtension} $out/lib/libtcl${dllExtension} - ''} - ''; + postInstall = + let + dllExtension = stdenv.hostPlatform.extensions.sharedLibrary; + dllDir = if stdenv.hostPlatform.isCygwin then "bin" else "lib"; + staticExtension = stdenv.hostPlatform.extensions.staticLibrary; + in + '' + make install-private-headers + ln -s $out/bin/tclsh${release} $out/bin/tclsh + if [[ -e $out/lib/libtcl${release}${staticExtension} ]]; then + ln -s $out/lib/libtcl${release}${staticExtension} $out/lib/libtcl${staticExtension} + fi + ${ + lib.optionalString (!stdenv.hostPlatform.isStatic) '' + ln -s $out/${dllDir}/libtcl${release}${dllExtension} $out/${dllDir}/libtcl${dllExtension} + '' + + lib.optionalString stdenv.hostPlatform.isCygwin '' + ln -s $out/${dllDir}/libtcl${release}${dllExtension} $out/lib/ + '' + } + ''; - meta = { - description = "Tcl scripting language"; - homepage = "https://www.tcl.tk/"; - license = lib.licenses.tcltk; - platforms = lib.platforms.all; - maintainers = with lib.maintainers; [ agbrooks ]; - }; + meta = { + description = "Tcl scripting language"; + homepage = "https://www.tcl.tk/"; + license = lib.licenses.tcltk; + platforms = lib.platforms.all; + maintainers = with lib.maintainers; [ agbrooks ]; + }; - passthru = rec { - inherit release version; - libPrefix = "tcl${release}"; - libdir = "lib/${libPrefix}"; - tclPackageHook = callPackage ( - { buildPackages }: - makeSetupHook { - name = "tcl-package-hook"; - propagatedBuildInputs = [ buildPackages.makeBinaryWrapper ]; - meta = { - inherit (meta) maintainers platforms; - }; - } ./tcl-package-hook.sh - ) { }; - # verify that Tcl's clock library can access tzdata - tests.tzdata = runCommand "${pname}-test-tzdata" { } '' - ${baseInterp}/bin/tclsh <(echo "set t [clock scan {2004-10-30 05:00:00} \ - -format {%Y-%m-%d %H:%M:%S} \ - -timezone :America/New_York]") > $out - ''; - }; - }; + passthru = rec { + inherit release version; + libPrefix = "tcl${release}"; + libdir = "lib/${libPrefix}"; + tclPackageHook = callPackage ( + { buildPackages }: + makeSetupHook { + name = "tcl-package-hook"; + propagatedBuildInputs = [ buildPackages.makeBinaryWrapper ]; + meta = { + inherit (meta) maintainers platforms; + }; + } ./tcl-package-hook.sh + ) { }; + # verify that Tcl's clock library can access tzdata + tests.tzdata = runCommand "${pname}-test-tzdata" { } '' + ${baseInterp}/bin/tclsh <(echo "set t [clock scan {2004-10-30 05:00:00} \ + -format {%Y-%m-%d %H:%M:%S} \ + -timezone :America/New_York]") > $out + ''; + }; + } + // lib.optionalAttrs stdenv.hostPlatform.isCygwin { + patches = [ + ./fix-cygwin-build.patch + ]; + } + ); mkTclDerivation = callPackage ./mk-tcl-derivation.nix { tcl = baseInterp; }; From 6c8a73c60a643b8af28798c800037785a8490c56 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 9 Oct 2025 10:53:06 -0300 Subject: [PATCH 034/119] gdbm: fix cygwin build --- pkgs/by-name/gd/gdbm/package.nix | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/gd/gdbm/package.nix b/pkgs/by-name/gd/gdbm/package.nix index a31390c4ea3b9..7604b22696d62 100644 --- a/pkgs/by-name/gd/gdbm/package.nix +++ b/pkgs/by-name/gd/gdbm/package.nix @@ -4,6 +4,7 @@ stdenv, testers, updateAutotoolsGnuConfigScriptsHook, + autoconf, }: stdenv.mkDerivation (finalAttrs: { @@ -15,12 +16,18 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-aiRQShTeSnRBA9y5Nr6Xbfb76IzP8mBl5UwcR5RvSl4="; }; - nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ]; + nativeBuildInputs = [ + updateAutotoolsGnuConfigScriptsHook + ] + # needed for testsuite.at patch below + ++ lib.optional stdenv.buildPlatform.isCygwin autoconf; hardeningDisable = [ "strictflexarrays3" ]; configureFlags = [ (lib.enableFeature true "libgdbm-compat") ]; + buildFlags = lib.optionalString stdenv.hostPlatform.isCygwin "LDFLAGS=-no-undefined"; + outputs = [ "out" "dev" @@ -42,7 +49,7 @@ stdenv.mkDerivation (finalAttrs: { substituteInPlace tests/Makefile.in \ --replace-fail '_LDADD = ../src/libgdbm.la ../compat/libgdbm_compat.la' \ '_LDADD = ../compat/libgdbm_compat.la ../src/libgdbm.la' - substituteInPlace tests/testsuite.at + substituteInPlace tests/testsuite.at \ --replace-fail 'm4_include([dbmfetch03.at])' "" ''; From 599cbf03c88716d6cdfd864e8ad403d834c0ab95 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 29 Sep 2025 16:23:27 -0300 Subject: [PATCH 035/119] treewide: undo changes causing rebuilds --- pkgs/by-name/gd/gdbm/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/gd/gdbm/package.nix b/pkgs/by-name/gd/gdbm/package.nix index 7604b22696d62..90de4bd8b9b05 100644 --- a/pkgs/by-name/gd/gdbm/package.nix +++ b/pkgs/by-name/gd/gdbm/package.nix @@ -26,7 +26,7 @@ stdenv.mkDerivation (finalAttrs: { configureFlags = [ (lib.enableFeature true "libgdbm-compat") ]; - buildFlags = lib.optionalString stdenv.hostPlatform.isCygwin "LDFLAGS=-no-undefined"; + buildFlags = if stdenv.hostPlatform.isCygwin then "LDFLAGS=-no-undefined" else null; outputs = [ "out" From 8994cb1f8dac3c1b7ae8b803d33b2cd10a0947dd Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 10 Oct 2025 13:17:27 -0300 Subject: [PATCH 036/119] cygwin-dll-link: use link for cygwin1.dll --- pkgs/build-support/setup-hooks/cygwin-dll-link.sh | 6 +++++- pkgs/stdenv/generic/make-derivation.nix | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh index 575e06f9e1646..2daf6cd8dd39e 100644 --- a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh +++ b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh @@ -27,7 +27,11 @@ _linkDeps() { local dll _dllDeps "$target" | while read dll; do echo ' dll:' "$dll" - if [[ -e "$dir/$dll" ]]; then continue; fi + if [[ -L "$dir/$dll" || -e "$dir/$dll" ]]; then continue; fi + if [[ $dll = cygwin1.dll ]]; then + CYGWIN+=\ winsymlinks:nativestrict ln -sr /bin/cygwin1.dll "$dir" + continue + fi # Locate the DLL - it should be an *executable* file on $LINK_DLL_FOLDERS. local dllPath="$(PATH="$(dirname "$target"):$LINK_DLL_FOLDERS" type -P "$dll")" if [[ -z "$dllPath" ]]; then diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index cdfeb34a24116..0a46f9b11c534 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -705,7 +705,6 @@ let allowedImpureDLLs ++ lib.optionals isCygwin [ "KERNEL32.dll" - "cygwin1.dll" ]; } // ( From 423952a84af0cafbf588a03fb24e992b6ce07e64 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 14 Oct 2025 20:43:51 -0300 Subject: [PATCH 037/119] cc-wrapper: fix missing cygstdc++ on cygwin non-cross --- pkgs/build-support/cc-wrapper/default.nix | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 9bb07456e8f25..72b468c31ed71 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -602,13 +602,19 @@ stdenvNoCC.mkDerivation { dontUnpack = true; installPhase = if targetPlatform.isCygwin then - '' - echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_bin}/lib" >> $out - # Work around build failure caused by the gnulib workaround for - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870. remove after - # gnulib is updated in core packages (e.g. iconv, gnupatch, gnugrep) - echo appendToVar configureFlags gl_cv_clean_version_stddef=yes >> $out - '' + ( + '' + echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_bin}/lib" >> $out + # Work around build failure caused by the gnulib workaround for + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870. remove after + # gnulib is updated in core packages (e.g. iconv, gnupatch, gnugrep) + echo appendToVar configureFlags gl_cv_clean_version_stddef=yes >> $out + '' + # in a cross-toolchain, cygstdc++-6.dll is in /lib, but otherwise it's in /bin + + lib.optionalString (targetPlatform == hostPlatform) '' + echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_bin}/bin" >> $out + '' + ) else '' echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_solib}/lib" > $out From fffbce27429b665d3eb632a838edf0efd9718388 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Wed, 15 Oct 2025 11:30:09 -0300 Subject: [PATCH 038/119] pkg-config-unwrapped: fix cygwin build --- pkgs/by-name/pk/pkg-config-unwrapped/package.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkgs/by-name/pk/pkg-config-unwrapped/package.nix b/pkgs/by-name/pk/pkg-config-unwrapped/package.nix index eace0aeab4447..26b6b7a757f1d 100644 --- a/pkgs/by-name/pk/pkg-config-unwrapped/package.nix +++ b/pkgs/by-name/pk/pkg-config-unwrapped/package.nix @@ -3,6 +3,7 @@ stdenv, fetchurl, libiconv, + autoreconfHook, vanilla ? false, }: @@ -29,6 +30,7 @@ stdenv.mkDerivation rec { ./gcc-15.patch ] ++ lib.optional (!vanilla) ./requires-private.patch + # this is done upstream in recent glib versions using meson ++ lib.optional stdenv.hostPlatform.isCygwin ./2.36.3-not-win32.patch; # These three tests fail due to a (desired) behavior change from our ./requires-private.patch @@ -42,6 +44,12 @@ stdenv.mkDerivation rec { rm -f check/check-requires-private check/check-gtk check/missing ''; + autoreconfFlags = lib.optional stdenv.hostPlatform.isCygwin "glib"; + + nativeBuildInputs = + # required for cygwin patch + lib.optional stdenv.hostPlatform.isCygwin autoreconfHook; + buildInputs = [ libiconv ]; configureFlags = [ From 9245d967e86da14091817e5e8fb7137fed4c4769 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 29 Sep 2025 16:23:27 -0300 Subject: [PATCH 039/119] treewide: undo changes causing rebuilds --- pkgs/by-name/pk/pkg-config-unwrapped/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/pk/pkg-config-unwrapped/package.nix b/pkgs/by-name/pk/pkg-config-unwrapped/package.nix index 26b6b7a757f1d..7a5ad31463f9d 100644 --- a/pkgs/by-name/pk/pkg-config-unwrapped/package.nix +++ b/pkgs/by-name/pk/pkg-config-unwrapped/package.nix @@ -44,7 +44,7 @@ stdenv.mkDerivation rec { rm -f check/check-requires-private check/check-gtk check/missing ''; - autoreconfFlags = lib.optional stdenv.hostPlatform.isCygwin "glib"; + autoreconfFlags = if stdenv.hostPlatform.isCygwin then "glib" else null; nativeBuildInputs = # required for cygwin patch From d27222112c6b7af2fce7cf69f98cb43419d7f8c3 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Wed, 15 Oct 2025 15:44:35 -0300 Subject: [PATCH 040/119] help2man: fix cygwin build --- pkgs/by-name/he/help2man/1.40.4-cygwin-nls.patch | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/he/help2man/1.40.4-cygwin-nls.patch b/pkgs/by-name/he/help2man/1.40.4-cygwin-nls.patch index 82f8cf1cb37bf..87591181983a7 100644 --- a/pkgs/by-name/he/help2man/1.40.4-cygwin-nls.patch +++ b/pkgs/by-name/he/help2man/1.40.4-cygwin-nls.patch @@ -11,16 +11,17 @@ that we're trying to help2man). --- help2man-1.46.5/Makefile.in 2014-10-09 13:03:01.000000000 +0200 +++ help2man-1.46.5/Makefile.in 2015-05-12 14:46:52.995521900 +0200 -@@ -76,7 +76,8 @@ - fi +@@ -76,8 +76,9 @@ + fi - install_preload: install_dirs preload + install_preload: preload + $(MKINSTALLDIRS) $(DESTDIR)$(pkglibdir) - $(INSTALL_PROGRAM) $(preload).so $(DESTDIR)$(pkglibdir) + $(INSTALL_PROGRAM) lib/cygintl-9.dll $(DESTDIR)$(pkglibdir) + ln -sf cygintl-9.dll $(DESTDIR)$(pkglibdir)/$(preload).so - install_l10n: install_dirs msg_l10n man_l10n info_l10n - set -e; \ + install_l10n: msg_l10n man_l10n info_l10n + set -e; \ @@ -144,7 +146,9 @@ preload: $(preload).so From e846b2b78ba99324f7264bb682f55c6a35855717 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Wed, 15 Oct 2025 15:55:04 -0300 Subject: [PATCH 041/119] flex: fix cygwin build --- pkgs/development/tools/parsing/flex/default.nix | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkgs/development/tools/parsing/flex/default.nix b/pkgs/development/tools/parsing/flex/default.nix index fb1b9a601ac36..6f1c69680ce7f 100644 --- a/pkgs/development/tools/parsing/flex/default.nix +++ b/pkgs/development/tools/parsing/flex/default.nix @@ -7,6 +7,7 @@ m4, autoreconfHook, help2man, + gettext, }: # Avoid 'fetchpatch' to allow 'flex' to be used as a possible 'gcc' @@ -51,7 +52,11 @@ stdenv.mkDerivation rec { autoreconfHook help2man ]; - buildInputs = [ bison ]; + # TODO: instead of adding gettext, maybe just enable strictDeps? + # gettext on cygwin includes libintl, which is found through + # nativeBuildInputs, but if it's not in buildInputs it's unable to find + # cygintl-8.dll. + buildInputs = [ bison ] ++ lib.optional stdenv.hostPlatform.isCygwin gettext; propagatedBuildInputs = [ m4 ]; preConfigure = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' @@ -59,7 +64,11 @@ stdenv.mkDerivation rec { export ac_cv_func_realloc_0_nonnull=yes ''; - postConfigure = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isCygwin) '' + configureFlags = + # from flex.cygport + lib.optional stdenv.hostPlatform.isCygwin "--disable-shared"; + + postConfigure = lib.optionalString (stdenv.hostPlatform.isDarwin) '' sed -i Makefile -e 's/-no-undefined//;' ''; From c4e05431d7f82ff939493f5c0db32a08100a1786 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 29 Sep 2025 16:23:27 -0300 Subject: [PATCH 042/119] treewide: undo changes causing rebuilds --- pkgs/development/tools/parsing/flex/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/tools/parsing/flex/default.nix b/pkgs/development/tools/parsing/flex/default.nix index 6f1c69680ce7f..e6e50149c3859 100644 --- a/pkgs/development/tools/parsing/flex/default.nix +++ b/pkgs/development/tools/parsing/flex/default.nix @@ -64,7 +64,7 @@ stdenv.mkDerivation rec { export ac_cv_func_realloc_0_nonnull=yes ''; - configureFlags = + ${if stdenv.hostPlatform.isCygwin then "configureFlags" else null} = # from flex.cygport lib.optional stdenv.hostPlatform.isCygwin "--disable-shared"; From dd75a323f53e209268e29201970c3e695043a076 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 16 Oct 2025 13:17:09 -0300 Subject: [PATCH 043/119] cmake: fix cygwin build --- pkgs/by-name/cm/cmake/package.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/by-name/cm/cmake/package.nix b/pkgs/by-name/cm/cmake/package.nix index fc039fa5e4db4..2663187c76db6 100644 --- a/pkgs/by-name/cm/cmake/package.nix +++ b/pkgs/by-name/cm/cmake/package.nix @@ -185,6 +185,7 @@ stdenv.mkDerivation (finalAttrs: { (lib.cmakeBool "CMAKE_USE_OPENSSL" useOpenSSL) (lib.cmakeBool "BUILD_CursesDialog" cursesUI) ] + ++ lib.optional stdenv.hostPlatform.isCygwin (lib.cmakeFeature "CMAKE_C_FLAGS" "-D_GNU_SOURCE") ); # make install attempts to use the just-built cmake From 9e8923dbd37fc9900c99ab1e541c8e449f609a2c Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 17 Oct 2025 15:14:48 -0300 Subject: [PATCH 044/119] groff: fix cygwin build --- pkgs/by-name/gr/groff/fix-cygwin-build.patch | 159 +++++++++++++++++++ pkgs/by-name/gr/groff/package.nix | 3 +- 2 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 pkgs/by-name/gr/groff/fix-cygwin-build.patch diff --git a/pkgs/by-name/gr/groff/fix-cygwin-build.patch b/pkgs/by-name/gr/groff/fix-cygwin-build.patch new file mode 100644 index 0000000000000..ff63cd98e3c0d --- /dev/null +++ b/pkgs/by-name/gr/groff/fix-cygwin-build.patch @@ -0,0 +1,159 @@ +diff --git a/Makefile.am b/Makefile.am +index f7ab410..2b26b93 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -564,9 +564,9 @@ endif + + # Path to binaries and flags used by contribs and doc to generated doc. + # These may be overridden if cross-compiling. +-GROFFBIN = $(abs_top_builddir)/groff ++GROFFBIN = $(abs_top_builddir)/groff$(EXEEXT) + GROFF_BIN_PATH = $(abs_top_builddir) +-PDFMOMBIN = $(abs_top_builddir)/pdfmom ++PDFMOMBIN = $(abs_top_builddir)/pdfmom$(EXEEXT) + # Search for macro files and device/font description directories in + # source _and_ build trees; some of each are generated. + FFLAG=-F$(abs_top_builddir)/font -F$(abs_top_srcdir)/font +diff --git a/contrib/hdtbl/hdtbl.am b/contrib/hdtbl/hdtbl.am +index 3dd60cf..e0dfa0c 100644 +--- a/contrib/hdtbl/hdtbl.am ++++ b/contrib/hdtbl/hdtbl.am +@@ -119,8 +119,8 @@ SUFFIXES += .roff .in .ps + -e "s|[@]EGREP[@]|$(EGREP)|" $< >$@ + + +-$(HDTBLPROCESSEDEXAMPLEFILES): $(DOC_GNU_EPS) groff troff eqn pic tbl \ +- grops font/devps/stamp contrib/hdtbl/examples/common.roff ++$(HDTBLPROCESSEDEXAMPLEFILES): $(DOC_GNU_EPS) groff$(EXEEXT) troff$(EXEEXT) eqn$(EXEEXT) pic$(EXEEXT) tbl$(EXEEXT) \ ++ grops$(EXEEXT) font/devps/stamp contrib/hdtbl/examples/common.roff + + uninstall_groffdirs: uninstall-hdtbl-hook + uninstall-hdtbl-hook: +diff --git a/contrib/mom/mom.am b/contrib/mom/mom.am +index 3bbbc9a..7813699 100644 +--- a/contrib/mom/mom.am ++++ b/contrib/mom/mom.am +@@ -145,7 +145,7 @@ SUFFIXES += .mom .pdf + && LC_ALL=C $(MOMPDFMOM) $< >$@ + + $(MOMPROCESSEDEXAMPLEFILES): $(MOMNORMALFILES) \ +- groff troff gropdf pdfmom penguin.ps penguin.pdf font/devpdf/stamp ++ groff$(EXEEXT) troff$(EXEEXT) gropdf$(EXEEXT) pdfmom$(EXEEXT) penguin.ps penguin.pdf font/devpdf/stamp + + penguin.ps: + $(AM_V_at)cp $(mom_srcdir)/examples/penguin.ps $@ +diff --git a/contrib/pdfmark/pdfmark.am b/contrib/pdfmark/pdfmark.am +index 15eec8c..2135450 100644 +--- a/contrib/pdfmark/pdfmark.am ++++ b/contrib/pdfmark/pdfmark.am +@@ -68,7 +68,7 @@ contrib/pdfmark/pdfmark.pdf: contrib/pdfmark/pdfmark.ms + $(top_srcdir)/contrib/pdfmark/pdfmark.ms >$@ + + # The pdf files use the local script to generate. +-$(PDFDOCFILES): pdfroff groff troff gropdf ++$(PDFDOCFILES): pdfroff$(EXEEXT) groff$(EXEEXT) troff$(EXEEXT) gropdf$(EXEEXT) + $(PDFDOCFILES): $(dist_devpsfont_DATA) $(nodist_devpsfont_DATA) \ + $(DOC_GNU_EPS) + +diff --git a/contrib/sboxes/sboxes.am b/contrib/sboxes/sboxes.am +index 7786337..b2b93bb 100644 +--- a/contrib/sboxes/sboxes.am ++++ b/contrib/sboxes/sboxes.am +@@ -54,7 +54,7 @@ $(sboxes_builddir)/msboxes.ms: $(SBOXES_EXAMPLEFILES) $(sboxesnotquine) + $(AM_V_GEN)mv $@.tmp $@ + + $(sboxes_builddir)/msboxes.pdf: $(sboxes_builddir)/msboxes.ms \ +- $(dist_sboxestmac_DATA) groff troff gropdf font/devpdf/stamp ++ $(dist_sboxestmac_DATA) groff$(EXEEXT) troff$(EXEEXT) gropdf$(EXEEXT) font/devpdf/stamp + $(GROFF_V)$(DOC_GROFF) -M$(sboxes_srcdir) -ms -msboxes -Tpdf \ + $(sboxes_builddir)/msboxes.ms > $@ + +diff --git a/doc/doc.am b/doc/doc.am +index cddc519..a42622a 100644 +--- a/doc/doc.am ++++ b/doc/doc.am +@@ -81,11 +81,11 @@ PROCESSEDDOCFILES = \ + $(PROCESSEDDOCFILES_TXT) + + # Declare minimal dependencies for documents by output driver. +-PROCESSEDFILES_DEPS_HTML = pre-grohtml groff troff post-grohtml \ ++PROCESSEDFILES_DEPS_HTML = pre-grohtml$(EXEEXT) groff$(EXEEXT) troff$(EXEEXT) post-grohtml$(EXEEXT) \ + font/devhtml/stamp font/devps/stamp +-PROCESSEDFILES_DEPS_PS = groff troff grops font/devps/stamp +-PROCESSEDFILES_DEPS_PDF = groff troff gropdf font/devpdf/stamp +-PROCESSEDFILES_DEPS_TXT = groff troff grotty font/devutf8/stamp ++PROCESSEDFILES_DEPS_PS = groff$(EXEEXT) troff$(EXEEXT) grops$(EXEEXT) font/devps/stamp ++PROCESSEDFILES_DEPS_PDF = groff$(EXEEXT) troff$(EXEEXT) gropdf$(EXEEXT) font/devpdf/stamp ++PROCESSEDFILES_DEPS_TXT = groff$(EXEEXT) troff$(EXEEXT) grotty$(EXEEXT) font/devutf8/stamp + + if USE_GROHTML + $(PROCESSEDDOCFILES_HTML): $(PROCESSEDFILES_DEPS_HTML) +@@ -254,7 +254,7 @@ man-clean: + # We embed the fonts (-P-e) to (1) honor the current PDF standard, (2) + # ensure consistent rendering of the document, and (3) exercise this + # feature of gropdf. +-doc/groff-man-pages.pdf: $(GROFF_MAN_PAGES_ALL) eqn pic tbl \ ++doc/groff-man-pages.pdf: $(GROFF_MAN_PAGES_ALL) eqn$(EXEEXT) pic$(EXEEXT) tbl$(EXEEXT) \ + $(TMAC_PACKAGE_MAN) $(TMAC_PACKAGE_MDOC) font/devps/freeeuro.pfa + $(GROFF_V)$(DOC_GROFF) -pet -mandoc -dHF=HB -rC1 \ + -rCHECKSTYLE=3 -Tpdf -P-e \ +@@ -262,7 +262,7 @@ doc/groff-man-pages.pdf: $(GROFF_MAN_PAGES_ALL) eqn pic tbl \ + $(tmac_srcdir)/sv.tmac $(GROFF_MAN_PAGES2) \ + $(tmac_srcdir)/en.tmac $(GROFF_MAN_PAGES3) > $@ + +-doc/groff-man-pages.utf8.txt: $(GROFF_MAN_PAGES_ALL) eqn pic tbl \ ++doc/groff-man-pages.utf8.txt: $(GROFF_MAN_PAGES_ALL) eqn$(EXEEXT) pic$(EXEEXT) tbl$(EXEEXT) \ + $(TMAC_PACKAGE_MAN) $(TMAC_PACKAGE_MDOC) + $(GROFF_V)$(DOC_GROFF) -pet -Tutf8 -mandoc \ + -rCHECKSTYLE=3 $(GROFF_MAN_PAGES1) \ +@@ -270,7 +270,7 @@ doc/groff-man-pages.utf8.txt: $(GROFF_MAN_PAGES_ALL) eqn pic tbl \ + $(tmac_srcdir)/en.tmac $(GROFF_MAN_PAGES3) > $@ + + doc/grnexmpl.ps: $(doc_srcdir)/grnexmpl.me $(doc_srcdir)/grnexmpl.g \ +- grn eqn ++ grn$(EXEEXT) eqn$(EXEEXT) + $(GROFF_V)$(MKDIR_P) `dirname $@` \ + && $(DOC_GROFF) -Tps -ge -me $(doc_srcdir)/grnexmpl.me >$@ + +@@ -334,19 +334,19 @@ SUFFIXES += .me.in .me + + # Use '-K utf8', not '-k', in case 'configure' didn't find uchardet. + # The French translation uses tbl; its English counterpart does not. +-doc/meintro_fr.ps: doc/meintro_fr.me preconv ++doc/meintro_fr.ps: doc/meintro_fr.me preconv$(EXEEXT) + $(GROFF_V)$(MKDIR_P) `dirname $@` \ + && $(DOC_GROFF) -K utf8 -t -Tps -me -mfr $< >$@ + +-doc/ms.ps: $(doc_srcdir)/ms.ms eqn tbl ++doc/ms.ps: $(doc_srcdir)/ms.ms eqn$(EXEEXT) tbl$(EXEEXT) + $(GROFF_V)$(MKDIR_P) `dirname $@` \ + && $(DOC_GROFF) -et -Tps -ms $(doc_srcdir)/ms.ms >$@ + +-doc/pic.ps: $(doc_srcdir)/pic.ms eqn pic tbl ++doc/pic.ps: $(doc_srcdir)/pic.ms eqn$(EXEEXT) pic$(EXEEXT) tbl$(EXEEXT) + $(GROFF_V)$(MKDIR_P) `dirname $@` \ + && $(DOC_GROFF) -pet -Tps -ms $(doc_srcdir)/pic.ms >$@ + +-doc/webpage.ps: $(DOC_GNU_EPS) tmac/www.tmac tbl ++doc/webpage.ps: $(DOC_GNU_EPS) tmac/www.tmac tbl$(EXEEXT) + doc/webpage.ps: $(doc_srcdir)/webpage.ms + $(GROFF_V)$(MKDIR_P) `dirname $@` \ + && $(DOC_GROFF) -I $(doc_srcdir) -I $(doc_builddir) -t -Tps \ +@@ -357,7 +357,7 @@ doc/webpage.ps: $(doc_srcdir)/webpage.ms + # $(GROFF_V)$(MKDIR_P) `dirname $@` \ + # && $(DOC_GROFF) -Tps -ms $< >$@ + +-doc/pic.html: eqn pic tbl ++doc/pic.html: eqn$(EXEEXT) pic$(EXEEXT) tbl$(EXEEXT) + doc/pic.html: tmac/www.tmac + doc/pic.html: $(doc_srcdir)/pic.ms + $(GROFF_V)$(MKDIR_P) $(doc_builddir) \ +@@ -365,7 +365,7 @@ doc/pic.html: $(doc_srcdir)/pic.ms + && $(DOC_GROFF) -pet -P-Ipic -P-Dimg -P-jpic -Thtml -ms \ + $(doc_srcdir)/pic.ms > pic.html + +-doc/webpage.html: tbl ++doc/webpage.html: tbl$(EXEEXT) + doc/webpage.html: tmac/www.tmac + doc/webpage.html: $(DOC_GNU_EPS) + doc/webpage.html: $(doc_srcdir)/groff.css diff --git a/pkgs/by-name/gr/groff/package.nix b/pkgs/by-name/gr/groff/package.nix index ec203ed3902fd..8e6913dbf8bb7 100644 --- a/pkgs/by-name/gr/groff/package.nix +++ b/pkgs/by-name/gr/groff/package.nix @@ -38,7 +38,8 @@ stdenv.mkDerivation rec { # Backport e49b934 "Fix underspecified `getenv()` prototype." for non-glibc systems with C23 # This can be dropped in the next release, when the local getopt implementation in libgroff is removed ./fix-underspecified-getenv-prototype.patch - ]; + ] + ++ lib.optional stdenv.hostPlatform.isCygwin ./fix-cygwin-build.patch; outputs = [ "out" From a61e24c5a8bc24b4de3634b2058c2d0b7a316b8c Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sat, 18 Oct 2025 11:01:01 -0300 Subject: [PATCH 045/119] popt: fix cygwin build --- pkgs/by-name/po/popt/1.16-cygwin.patch | 11 -------- pkgs/by-name/po/popt/1.16-vpath.patch | 34 ---------------------- pkgs/by-name/po/popt/package.nix | 39 +++++++++++--------------- 3 files changed, 17 insertions(+), 67 deletions(-) delete mode 100644 pkgs/by-name/po/popt/1.16-cygwin.patch delete mode 100644 pkgs/by-name/po/popt/1.16-vpath.patch diff --git a/pkgs/by-name/po/popt/1.16-cygwin.patch b/pkgs/by-name/po/popt/1.16-cygwin.patch deleted file mode 100644 index 9c084f0b8eaac..0000000000000 --- a/pkgs/by-name/po/popt/1.16-cygwin.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- origsrc/poptconfig.c 2009-05-20 08:18:07.000000000 -0500 -+++ src/poptconfig.c 2012-03-29 18:13:46.869286100 -0500 -@@ -42,7 +42,7 @@ extern int glob_pattern_p (const char *_ - /*@=declundef =exportheader =incondefs =protoparammatch =redecl =type @*/ - #endif /* __LCLINT__ */ - --#if !defined(__GLIBC__) -+#if !defined(__GLIBC__) && !defined(__CYGWIN__) - /* Return nonzero if PATTERN contains any metacharacters. - Metacharacters can be quoted with backslashes if QUOTE is nonzero. */ - static int diff --git a/pkgs/by-name/po/popt/1.16-vpath.patch b/pkgs/by-name/po/popt/1.16-vpath.patch deleted file mode 100644 index 4cfa1c8fb4db3..0000000000000 --- a/pkgs/by-name/po/popt/1.16-vpath.patch +++ /dev/null @@ -1,34 +0,0 @@ ---- origsrc/Doxyfile.in 2008-04-26 16:57:32.000000000 -0500 -+++ src/Doxyfile.in 2012-03-29 18:15:56.649709100 -0500 -@@ -460,14 +460,14 @@ WARN_LOGFILE = - # with spaces. - - INPUT = \ -- ./popt.c \ -- ./popt.h \ -- ./poptconfig.c \ -- ./popthelp.c \ -- ./poptint.c \ -- ./poptint.h \ -- ./poptparse.c \ -- ./system.h -+ @srcdir@/popt.c \ -+ @srcdir@/popt.h \ -+ @srcdir@/poptconfig.c \ -+ @srcdir@/popthelp.c \ -+ @srcdir@/poptint.c \ -+ @srcdir@/poptint.h \ -+ @srcdir@/poptparse.c \ -+ @srcdir@/system.h - - # If the value of the INPUT tag contains directories, you can use the - # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp -@@ -658,7 +658,7 @@ HTML_HEADER = - # each generated HTML page. If it is left blank doxygen will generate a - # standard footer. - --HTML_FOOTER = footer_no_timestamp.html -+HTML_FOOTER = @srcdir@/footer_no_timestamp.html - - # The HTML_STYLESHEET tag can be used to specify a user-defined cascading - # style sheet that is used by each HTML page. It can be used to diff --git a/pkgs/by-name/po/popt/package.nix b/pkgs/by-name/po/popt/package.nix index dffe05a33b420..fdb3d2fcc714e 100644 --- a/pkgs/by-name/po/popt/package.nix +++ b/pkgs/by-name/po/popt/package.nix @@ -17,29 +17,24 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ]; - patches = - lib.optionals stdenv.hostPlatform.isCygwin [ - ./1.16-cygwin.patch - ./1.16-vpath.patch - ] - ++ lib.optionals stdenv.hostPlatform.isMinGW [ - # Do not require - (fetchpatch2 { - url = "https://aur.archlinux.org/cgit/aur.git/plain/get-w32-console-maxcols.mingw32.patch?h=mingw-w64-popt&id=63f2cdb0de116362c49681cef20f7a8b4355e85a"; - sha256 = "zv43l1RBqNzT/JG+jQaMVFaFv+ZYPuIiAtKUDzJJBbc="; - stripLen = 1; - extraPrefix = "src/"; - }) + patches = lib.optionals stdenv.hostPlatform.isMinGW [ + # Do not require + (fetchpatch2 { + url = "https://aur.archlinux.org/cgit/aur.git/plain/get-w32-console-maxcols.mingw32.patch?h=mingw-w64-popt&id=63f2cdb0de116362c49681cef20f7a8b4355e85a"; + sha256 = "zv43l1RBqNzT/JG+jQaMVFaFv+ZYPuIiAtKUDzJJBbc="; + stripLen = 1; + extraPrefix = "src/"; + }) - # Do not try to detect setuid, it is not a thing. - (fetchpatch2 { - url = "https://github.com/rpm-software-management/popt/commit/905544c5d9767894edaf71a1e3ce5126944c5695.patch"; - sha256 = "3PmcxeiEZ/Hof0zoVFSytEXvQ8gE8Sp5UdagExPVICU="; - stripLen = 1; - extraPrefix = "src/"; - revert = true; - }) - ]; + # Do not try to detect setuid, it is not a thing. + (fetchpatch2 { + url = "https://github.com/rpm-software-management/popt/commit/905544c5d9767894edaf71a1e3ce5126944c5695.patch"; + sha256 = "3PmcxeiEZ/Hof0zoVFSytEXvQ8gE8Sp5UdagExPVICU="; + stripLen = 1; + extraPrefix = "src/"; + revert = true; + }) + ]; doCheck = false; # fails From 3e0fba414d25d1427a78456ebe98af68042f5041 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 19 Oct 2025 12:57:05 -0300 Subject: [PATCH 046/119] perlPackages.XMLParser: fix cygwin build --- .../perl-modules/cygwin-checklib-fix.patch | 13 +++++++++++++ pkgs/top-level/perl-packages.nix | 16 ++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 pkgs/development/perl-modules/cygwin-checklib-fix.patch diff --git a/pkgs/development/perl-modules/cygwin-checklib-fix.patch b/pkgs/development/perl-modules/cygwin-checklib-fix.patch new file mode 100644 index 0000000000000..a14d2f33a519c --- /dev/null +++ b/pkgs/development/perl-modules/cygwin-checklib-fix.patch @@ -0,0 +1,13 @@ +diff --git a/inc/Devel/CheckLib.pm b/inc/Devel/CheckLib.pm +index 36a451a..a7554dc 100644 +--- a/inc/Devel/CheckLib.pm ++++ b/inc/Devel/CheckLib.pm +@@ -379,7 +379,7 @@ sub _findcc { + my @cc = split( /\s+/, $Config{cc} ); + return ( [ @cc, @ccflags ], \@ldflags ) if -x $cc[0]; + foreach my $path (@paths) { +- my $compiler = File::Spec->catfile( $path, $cc[0] ) . $Config{_exe}; ++ my $compiler = File::Spec->catfile( $path, $cc[0] ); + return ( [ $compiler, @cc[ 1 .. $#cc ], @ccflags ], \@ldflags ) + if -x $compiler; + } diff --git a/pkgs/top-level/perl-packages.nix b/pkgs/top-level/perl-packages.nix index 0110bcdeb1b19..14a176e0eb0f5 100644 --- a/pkgs/top-level/perl-packages.nix +++ b/pkgs/top-level/perl-packages.nix @@ -38666,18 +38666,18 @@ with self; url = "mirror://cpan/authors/id/T/TO/TODDR/XML-Parser-2.46.tar.gz"; hash = "sha256-0zEzJJHFHMz7TLlP/ET5zXM3jmGEmNSjffngQ2YcUV0="; }; - patches = [ ../development/perl-modules/xml-parser-0001-HACK-Assumes-Expat-paths-are-good.patch ]; - postPatch = - lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' - substituteInPlace Expat/Makefile.PL --replace 'use English;' '#' - '' - + lib.optionalString stdenv.hostPlatform.isCygwin '' - sed -i -e "s@my \$compiler = File::Spec->catfile(\$path, \$cc\[0\]) \. \$Config{_exe};@my \$compiler = File::Spec->catfile(\$path, \$cc\[0\]) \. (\$^O eq 'cygwin' ? \"\" : \$Config{_exe});@" inc/Devel/CheckLib.pm - ''; + patches = [ + ../development/perl-modules/xml-parser-0001-HACK-Assumes-Expat-paths-are-good.patch + ] + ++ lib.optional stdenv.buildPlatform.isCygwin ../development/perl-modules/cygwin-checklib-fix.patch; + postPatch = lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + substituteInPlace Expat/Makefile.PL --replace 'use English;' '#' + ''; makeMakerFlags = [ "EXPATLIBPATH=${pkgs.expat.out}/lib" "EXPATINCPATH=${pkgs.expat.dev}/include" ]; + buildInputs = lib.optional stdenv.hostPlatform.isCygwin pkgs.expat; propagatedBuildInputs = [ LWP ]; meta = { description = "Perl module for parsing XML documents"; From ef7751db24dd3938b04debfb7bea92860b63a37d Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 19 Oct 2025 13:38:29 -0300 Subject: [PATCH 047/119] jq: fix cygwin build --- pkgs/by-name/jq/jq/package.nix | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/jq/jq/package.nix b/pkgs/by-name/jq/jq/package.nix index b2a0941a79fe4..9983234accb15 100644 --- a/pkgs/by-name/jq/jq/package.nix +++ b/pkgs/by-name/jq/jq/package.nix @@ -79,7 +79,14 @@ stdenv.mkDerivation (finalAttrs: { ] ++ lib.optional (!onigurumaSupport) "--with-oniguruma=no" # jq is linked to libjq: - ++ lib.optional (!stdenv.hostPlatform.isDarwin) "LDFLAGS=-Wl,-rpath,\\\${libdir}"; + ++ lib.optional (!stdenv.hostPlatform.isDarwin) "LDFLAGS=-Wl,-rpath,\\\${libdir}" + ++ lib.optionals stdenv.hostPlatform.isCygwin [ + # these are both in -lm, but not in the headers, which confuses AC + "ac_cv_lib_m_scalb=no" + "ac_cv_lib_m_significand=no" + ]; + + makeFlags = lib.optional stdenv.hostPlatform.isCygwin "libjq_la_LDFLAGS=-no-undefined"; # jq binary includes the whole `configureFlags` in: # https://github.com/jqlang/jq/commit/583e4a27188a2db097dd043dd203b9c106bba100 @@ -93,7 +100,9 @@ stdenv.mkDerivation (finalAttrs: { "$bin/bin/jq" ''; - doInstallCheck = true; + doInstallCheck = + # shtest aborts: https://github.com/jqlang/jq/issues/3129 + !stdenv.hostPlatform.isCygwin; installCheckTarget = "check"; preInstallCheck = '' From f5ab04a22a7c34c477f002919b33281630a7032b Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 29 Sep 2025 16:23:27 -0300 Subject: [PATCH 048/119] treewide: undo changes causing rebuilds --- pkgs/by-name/jq/jq/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/jq/jq/package.nix b/pkgs/by-name/jq/jq/package.nix index 9983234accb15..da568989ed917 100644 --- a/pkgs/by-name/jq/jq/package.nix +++ b/pkgs/by-name/jq/jq/package.nix @@ -86,7 +86,7 @@ stdenv.mkDerivation (finalAttrs: { "ac_cv_lib_m_significand=no" ]; - makeFlags = lib.optional stdenv.hostPlatform.isCygwin "libjq_la_LDFLAGS=-no-undefined"; + makeFlags = if stdenv.hostPlatform.isCygwin then "libjq_la_LDFLAGS=-no-undefined" else null; # jq binary includes the whole `configureFlags` in: # https://github.com/jqlang/jq/commit/583e4a27188a2db097dd043dd203b9c106bba100 From 8ecc1463aa817963812e7ea661dca0e0ad02bf7a Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 19 Oct 2025 15:21:24 -0300 Subject: [PATCH 049/119] expect: fix cygwin build --- .../by-name/ex/expect/fix-cygwin-build.patch | 15 +++++++++++++++ .../tcl-modules/by-name/ex/expect/package.nix | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/tcl-modules/by-name/ex/expect/fix-cygwin-build.patch diff --git a/pkgs/development/tcl-modules/by-name/ex/expect/fix-cygwin-build.patch b/pkgs/development/tcl-modules/by-name/ex/expect/fix-cygwin-build.patch new file mode 100644 index 0000000000000..018d22cef9895 --- /dev/null +++ b/pkgs/development/tcl-modules/by-name/ex/expect/fix-cygwin-build.patch @@ -0,0 +1,15 @@ +diff --git a/exp_win.c b/exp_win.c +index 9ffad9f..b46d024 100644 +--- a/exp_win.c ++++ b/exp_win.c +@@ -39,8 +39,8 @@ conflicts with sys/ioctl.h + /* Sigh. On AIX 2.3, termios.h exists but does not define TIOCGWINSZ */ + /* Instead, it has to come from ioctl.h. However, As I said above, this */ + /* can't be cavalierly included on all machines, even when it exists. */ +-/* Darwin also has termios.h, but it requires ioctl.h for `ioctl`. */ +-#if defined(HAVE_TERMIOS) && (defined(__APPLE__) || !defined(HAVE_TIOCGWINSZ_IN_TERMIOS_H)) ++/* Darwin and Cygwin also have termios.h, but require ioctl.h for `ioctl`. */ ++#if defined(HAVE_TERMIOS) && (defined(__APPLE__) || defined(__CYGWIN__) || !defined(HAVE_TIOCGWINSZ_IN_TERMIOS_H)) + # include + #endif + diff --git a/pkgs/development/tcl-modules/by-name/ex/expect/package.nix b/pkgs/development/tcl-modules/by-name/ex/expect/package.nix index a30305b890b75..6e614b0dc8411 100644 --- a/pkgs/development/tcl-modules/by-name/ex/expect/package.nix +++ b/pkgs/development/tcl-modules/by-name/ex/expect/package.nix @@ -38,7 +38,8 @@ tcl.mkTclDerivation rec { ./fix-darwin-bsd-clang16.patch # Remove some code which causes it to link against a file that does not exist at build time on native FreeBSD ./freebsd-unversioned.patch - ]; + ] + ++ lib.optional stdenv.hostPlatform.isCygwin ./fix-cygwin-build.patch; postPatch = '' sed -i "s,/bin/stty,$(type -p stty),g" configure.in From 2b5402ee3d25bc5af19ad9261317f1a53207babb Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 19 Oct 2025 22:08:45 -0300 Subject: [PATCH 050/119] man-db: fix cygwin build --- pkgs/by-name/ma/man-db/package.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/ma/man-db/package.nix b/pkgs/by-name/ma/man-db/package.nix index 0b173b013f7bf..48eea3fbfdefb 100644 --- a/pkgs/by-name/ma/man-db/package.nix +++ b/pkgs/by-name/ma/man-db/package.nix @@ -91,7 +91,12 @@ stdenv.mkDerivation rec { configureFlagsArray+=("--with-sections=1 n l 8 3 0 2 5 4 9 6 7") ''; - postInstall = '' + ${if stdenv.hostPlatform.isCygwin then "postInstall" else null} = '' + mv "$out"/lib/bin/* "$out"/bin/ + rmdir "$out"/lib/bin + ''; + + ${if stdenv.hostPlatform.isCygwin then "postFixup" else "postInstall"} = '' # apropos/whatis uses program name to decide whether to act like apropos or whatis # (multi-call binary). `apropos` is actually just a symlink to whatis. So we need to # make sure that we don't wrap symlinks (since that changes argv[0] to the -wrapped name) From fd08fab697400b9a7cbdea751f952871222ad9ab Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 20 Oct 2025 09:41:53 -0300 Subject: [PATCH 051/119] w3m: fix cygwin build --- pkgs/by-name/w3/w3m/fix-cygwin-build.patch | 34 ++++++++++++++++++++++ pkgs/by-name/w3/w3m/package.nix | 9 +++++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 pkgs/by-name/w3/w3m/fix-cygwin-build.patch diff --git a/pkgs/by-name/w3/w3m/fix-cygwin-build.patch b/pkgs/by-name/w3/w3m/fix-cygwin-build.patch new file mode 100644 index 0000000000000..39aa7d6d0fdd4 --- /dev/null +++ b/pkgs/by-name/w3/w3m/fix-cygwin-build.patch @@ -0,0 +1,34 @@ +diff --git a/config.h.in b/config.h.in +index 623b5f9..26376fe 100644 +--- a/config.h.in ++++ b/config.h.in +@@ -198,7 +198,6 @@ + + #if defined( __CYGWIN__ ) + #define SUPPORT_NETBIOS_SHARE 1 +-#define SUPPORT_WIN9X_CONSOLE_MBCS 1 + #endif + + #if defined(__CYGWIN__) && defined(__x86_64__) +diff --git a/terms.c b/terms.c +index c77b87a..56b9306 100644 +--- a/terms.c ++++ b/terms.c +@@ -2112,17 +2112,6 @@ term_title(const char *s) + * TERM=cygwin special handle announced deprecation and + * no one complains + */ +-#ifdef __CYGWIN__ +- if (isLocalConsole && title_str == CYGWIN_TITLE) { +- Str buff; +- buff = Sprintf(title_str, s); +- if (buff->length > 1024) { +- Strtruncate(buff, 1024); +- } +- SetConsoleTitle(buff->ptr); +- } +- else if (isLocalConsole || !isWinConsole) +-#endif + fprintf(ttyf, title_str, s); + } + } diff --git a/pkgs/by-name/w3/w3m/package.nix b/pkgs/by-name/w3/w3m/package.nix index 73e82859bf633..fdc99ce10fc63 100644 --- a/pkgs/by-name/w3/w3m/package.nix +++ b/pkgs/by-name/w3/w3m/package.nix @@ -66,7 +66,8 @@ stdenv.mkDerivation (finalAttrs: { patches = [ ./RAND_egd.libressl.patch ./https.patch - ]; + ] + ++ lib.optional stdenv.hostPlatform.isCygwin ./fix-cygwin-build.patch; postPatch = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' ln -s ${mktable}/bin/mktable mktable @@ -117,6 +118,12 @@ stdenv.mkDerivation (finalAttrs: { enableParallelBuilding = false; + allowedImpureDLLs = [ + "USER32.dll" + "GDI32.dll" + "gdiplus.dll" + ]; + passthru.tests.version = testers.testVersion { inherit (finalAttrs) version; package = w3m; From c84e6fd9b1b49caac1ba2e3bebefb145ddbfed28 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 21 Oct 2025 13:55:40 -0300 Subject: [PATCH 052/119] cygwin-dll-link: fix shellcheck warnings --- pkgs/build-support/setup-hooks/cygwin-dll-link.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh index 2daf6cd8dd39e..221f71a62809c 100644 --- a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh +++ b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh @@ -1,8 +1,11 @@ +# shellcheck shell=bash + addLinkDLLPaths() { addToSearchPath "LINK_DLL_FOLDERS" "$1/lib" addToSearchPath "LINK_DLL_FOLDERS" "$1/bin" } +# shellcheck disable=SC2154 addEnvHooks "$targetOffset" addLinkDLLPaths addOutputDLLPaths() { @@ -23,9 +26,10 @@ _dllDeps() { _linkDeps() { local target="$1" dir="$2" check="$3" + [[ ! -x "$target" ]] && echo "_linkDeps: $target is not executable, skipping." 1>&2 && return echo 'target:' "$target" local dll - _dllDeps "$target" | while read dll; do + _dllDeps "$target" | while read -r dll; do echo ' dll:' "$dll" if [[ -L "$dir/$dll" || -e "$dir/$dll" ]]; then continue; fi if [[ $dll = cygwin1.dll ]]; then @@ -33,12 +37,12 @@ _linkDeps() { continue fi # Locate the DLL - it should be an *executable* file on $LINK_DLL_FOLDERS. - local dllPath="$(PATH="$(dirname "$target"):$LINK_DLL_FOLDERS" type -P "$dll")" - if [[ -z "$dllPath" ]]; then + local dllPath + if ! dllPath="$(PATH="$(dirname "$target"):$LINK_DLL_FOLDERS" type -P "$dll")"; then if [[ -z "$check" || -n "${allowedImpureDLLsMap[$dll]}" ]]; then continue fi - echo unable to find $dll in $LINK_DLL_FOLDERS >&2 + echo unable to find "$dll" in "$LINK_DLL_FOLDERS" >&2 exit 1 fi echo ' linking to:' "$dllPath" @@ -50,6 +54,7 @@ _linkDeps() { } linkDLLs() { + # shellcheck disable=SC2154 if [ ! -d "$prefix" ]; then return; fi ( set -e From 6cb420140d0880c0074882d4532520e890904c38 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 21 Oct 2025 14:15:44 -0300 Subject: [PATCH 053/119] cygwin-dll-link: link DLLs in /lib/ by default --- pkgs/build-support/setup-hooks/cygwin-dll-link.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh index 221f71a62809c..447d79461cdb3 100644 --- a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh +++ b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh @@ -73,7 +73,7 @@ linkDLLs() { # Iterate over any DLL that we depend on. local target - for target in {bin,libexec}/**/*.{exe,dll}; do + for target in {bin,lib,libexec}/**/*.{exe,dll}; do [[ ! -f "$target" || ! -x "$target" ]] || _linkDeps "$target" "$(dirname "$target")" "1" done From baac2c6a9d4c177d113ba87cbd76eb6f3792ca17 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 21 Oct 2025 20:59:52 -0300 Subject: [PATCH 054/119] cygwin-dll-link: move DLLs to $lib/bin by default --- pkgs/build-support/cc-wrapper/default.nix | 4 ++-- .../setup-hooks/cygwin-dll-link.sh | 21 +++++++++---------- .../interpreters/perl/interpreter.nix | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 72b468c31ed71..99e40e5fa4ae0 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -604,7 +604,7 @@ stdenvNoCC.mkDerivation { if targetPlatform.isCygwin then ( '' - echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_bin}/lib" >> $out + echo addToSearchPath "HOST_PATH" "${cc_bin}/lib" >> $out # Work around build failure caused by the gnulib workaround for # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870. remove after # gnulib is updated in core packages (e.g. iconv, gnupatch, gnugrep) @@ -612,7 +612,7 @@ stdenvNoCC.mkDerivation { '' # in a cross-toolchain, cygstdc++-6.dll is in /lib, but otherwise it's in /bin + lib.optionalString (targetPlatform == hostPlatform) '' - echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_bin}/bin" >> $out + echo addToSearchPath "HOST_PATH" "${cc_bin}/bin" >> $out '' ) else diff --git a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh index 447d79461cdb3..136157853216a 100644 --- a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh +++ b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh @@ -1,21 +1,20 @@ # shellcheck shell=bash -addLinkDLLPaths() { - addToSearchPath "LINK_DLL_FOLDERS" "$1/lib" - addToSearchPath "LINK_DLL_FOLDERS" "$1/bin" +_moveDLLsToLib() { + if [[ "${dontMoveDLLsToLib-}" ]]; then return; fi + # shellcheck disable=SC2154 + moveToOutput "bin/*.dll" "${!outputLib}" } -# shellcheck disable=SC2154 -addEnvHooks "$targetOffset" addLinkDLLPaths +preFixupHooks+=(_moveDLLsToLib) addOutputDLLPaths() { for output in $(getAllOutputNames); do - addToSearchPath "LINK_DLL_FOLDERS" "${!output}/lib" - addToSearchPath "LINK_DLL_FOLDERS" "${!output}/bin" + addToSearchPath "HOST_PATH" "${!output}/bin" done } -postInstallHooks+=(addOutputDLLPaths) +preFixupHooks+=(addOutputDLLPaths) _dllDeps() { [ -z "${OBJDUMP:-}" ] && echo "_dllDeps: '\$OBJDUMP' variable is empty, skipping." 1>&2 && return @@ -36,13 +35,13 @@ _linkDeps() { CYGWIN+=\ winsymlinks:nativestrict ln -sr /bin/cygwin1.dll "$dir" continue fi - # Locate the DLL - it should be an *executable* file on $LINK_DLL_FOLDERS. + # Locate the DLL - it should be an *executable* file on $HOST_PATH. local dllPath - if ! dllPath="$(PATH="$(dirname "$target"):$LINK_DLL_FOLDERS" type -P "$dll")"; then + if ! dllPath="$(PATH="$(dirname "$target"):$HOST_PATH" type -P "$dll")"; then if [[ -z "$check" || -n "${allowedImpureDLLsMap[$dll]}" ]]; then continue fi - echo unable to find "$dll" in "$LINK_DLL_FOLDERS" >&2 + echo unable to find "$dll" in "$HOST_PATH" >&2 exit 1 fi echo ' linking to:' "$dllPath" diff --git a/pkgs/development/interpreters/perl/interpreter.nix b/pkgs/development/interpreters/perl/interpreter.nix index 88e9c54fec54d..3839acfd6bcbb 100644 --- a/pkgs/development/interpreters/perl/interpreter.nix +++ b/pkgs/development/interpreters/perl/interpreter.nix @@ -441,7 +441,7 @@ stdenv.mkDerivation ( setupHook = ./setup-hook-cross.sh; } // lib.optionalAttrs (stdenv.hostPlatform.isCygwin) { - # in cygwin we need PATH and LINK_DLL_FOLDERS set up for these dependencies + # in cygwin we need PATH and HOST_PATH set up for these dependencies buildInputs = [ zlib ]; nativeBuildInputs = lib.optional (!crossCompiling && enableCrypt) libxcrypt; } From ab1e2895c4ce57f8b32fcd49a6b2562c5a9458fd Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 21 Oct 2025 14:15:21 -0300 Subject: [PATCH 055/119] cygwin-dll-link: make linkDLLs work on individual dirs/files --- pkgs/build-support/cc-wrapper/default.nix | 20 ++-- .../setup-hooks/cygwin-dll-link.sh | 110 +++++++++++++----- .../compilers/gcc/common/builder.nix | 7 ++ 3 files changed, 93 insertions(+), 44 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 99e40e5fa4ae0..89cc7c4ce4fd5 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -602,19 +602,13 @@ stdenvNoCC.mkDerivation { dontUnpack = true; installPhase = if targetPlatform.isCygwin then - ( - '' - echo addToSearchPath "HOST_PATH" "${cc_bin}/lib" >> $out - # Work around build failure caused by the gnulib workaround for - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870. remove after - # gnulib is updated in core packages (e.g. iconv, gnupatch, gnugrep) - echo appendToVar configureFlags gl_cv_clean_version_stddef=yes >> $out - '' - # in a cross-toolchain, cygstdc++-6.dll is in /lib, but otherwise it's in /bin - + lib.optionalString (targetPlatform == hostPlatform) '' - echo addToSearchPath "HOST_PATH" "${cc_bin}/bin" >> $out - '' - ) + '' + echo addToSearchPath "HOST_PATH" "${cc_solib}/bin" >> $out + # Work around build failure caused by the gnulib workaround for + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870. remove after + # gnulib is updated in core packages (e.g. iconv, gnupatch, gnugrep) + echo appendToVar configureFlags gl_cv_clean_version_stddef=yes >> $out + '' else '' echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_solib}/lib" > $out diff --git a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh index 136157853216a..ccf9d9e617f83 100644 --- a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh +++ b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh @@ -8,53 +8,90 @@ _moveDLLsToLib() { preFixupHooks+=(_moveDLLsToLib) -addOutputDLLPaths() { +_addOutputDLLPaths() { for output in $(getAllOutputNames); do addToSearchPath "HOST_PATH" "${!output}/bin" done } -preFixupHooks+=(addOutputDLLPaths) +preFixupHooks+=(_addOutputDLLPaths) _dllDeps() { - [ -z "${OBJDUMP:-}" ] && echo "_dllDeps: '\$OBJDUMP' variable is empty, skipping." 1>&2 && return + if [[ -z "${OBJDUMP:-}" ]]; then + echo "_dllDeps: '\$OBJDUMP' variable is empty, skipping." 1>&2 + return + fi "$OBJDUMP" -p "$1" \ | sed -n 's/.*DLL Name: \(.*\)/\1/p' \ | sort -u } +declare -Ag _linkDeps_visited + _linkDeps() { - local target="$1" dir="$2" check="$3" - [[ ! -x "$target" ]] && echo "_linkDeps: $target is not executable, skipping." 1>&2 && return + local target="$1" dir="$2" + if [[ -v _linkDeps_visited[$target] ]]; then + echo "_linkDeps: $target was already linked." 1>&2 + return + fi + if [[ ! -f "$target" || ! -x "$target" ]]; then + echo "_linkDeps: $target is not an executable file, skipping." 1>&2 + return + fi + + local realTarget output inOutput + realTarget="$(readlink -f "$target")" + for output in $outputs ; do + if [[ $realTarget == "${!output}"* ]]; then + echo "_linkDeps: $target ($realTarget) is in $output (${!output})." 1>&2 + inOutput=1 + break + fi + done + echo 'target:' "$target" local dll - _dllDeps "$target" | while read -r dll; do + while read -r dll; do echo ' dll:' "$dll" - if [[ -L "$dir/$dll" || -e "$dir/$dll" ]]; then continue; fi - if [[ $dll = cygwin1.dll ]]; then - CYGWIN+=\ winsymlinks:nativestrict ln -sr /bin/cygwin1.dll "$dir" + if [[ -v _linkDeps_visited[$dir/$dll] ]]; then + echo "_linkDeps: $dll was already linked into $dir." 1>&2 continue fi - # Locate the DLL - it should be an *executable* file on $HOST_PATH. - local dllPath - if ! dllPath="$(PATH="$(dirname "$target"):$HOST_PATH" type -P "$dll")"; then - if [[ -z "$check" || -n "${allowedImpureDLLsMap[$dll]}" ]]; then - continue + if [[ -L "$dir/$dll" || -e "$dir/$dll" ]]; then + echo ' already exists' + _linkDeps "$dir/$dll" "$dir" + else + local dllPath + if [[ $dll = cygwin1.dll ]]; then + dllPath=/bin/cygwin1.dll + else + # Locate the DLL - it should be an *executable* file on $HOST_PATH. + # This intentionally doesn't use $dir because we want to prefer dependencies + # that are already linked next to the target. + if ! dllPath="$(PATH="$(dirname "$target"):$HOST_PATH" type -P "$dll")"; then + if [[ -z "$inOutput" || -n "${allowedImpureDLLsMap[$dll]}" ]]; then + continue + fi + echo unable to find "$dll" in "$HOST_PATH" >&2 + exit 1 + fi fi - echo unable to find "$dll" in "$HOST_PATH" >&2 - exit 1 + echo ' linking to:' "$dllPath" + CYGWIN+=\ winsymlinks:nativestrict ln -sr "$dllPath" "$dir" + _linkDeps "$dllPath" "$dir" fi - echo ' linking to:' "$dllPath" - CYGWIN+=\ winsymlinks:nativestrict ln -sr "$dllPath" "$dir" - # That DLL might have its own (transitive) dependencies, - # so add also all DLLs from its directory to be sure. - _linkDeps "$dllPath" "$dir" "" - done + _linkDeps_visited[$dir/$dll]=1 + done < <(_dllDeps "$target") } +# linkDLLsDir can be used to override the destination path for links. This is +# useful if you're trying to link dependencies of libraries into the directory +# containing an executable. +# +# Arguments can be a file or directory path. Directories are searched +# recursively. linkDLLs() { # shellcheck disable=SC2154 - if [ ! -d "$prefix" ]; then return; fi ( set -e shopt -s globstar nullglob @@ -68,15 +105,26 @@ linkDLLs() { allowedImpureDLLsMap[$dll]=1 done - cd "$prefix" - - # Iterate over any DLL that we depend on. - local target - for target in {bin,lib,libexec}/**/*.{exe,dll}; do - [[ ! -f "$target" || ! -x "$target" ]] || - _linkDeps "$target" "$(dirname "$target")" "1" + local target file + for target in "$@"; do + # Iterate over any DLL that we depend on. + if [[ -f "$target" ]]; then + _linkDeps "$target" "${linkDLLsDir-$(dirname "$target")}" + elif [[ -d "$target" ]]; then + for file in "${target%/}"/**/*.{exe,dll}; do + _linkDeps "$file" "${linkDLLsDir-$(dirname "$file")}" + done + else + echo "linkDLLs: $target is not a file or directory, skipping." 1>&2 + fi done ) } -fixupOutputHooks+=(linkDLLs) +_linkDLLs() { + # shellcheck disable=SC2154 + if [[ ! -d $prefix || ${dontLinkDLLs-} ]]; then return; fi + linkDLLs "$prefix"/{bin,lib,libexec}/ +} + +fixupOutputHooks+=(_linkDLLs) diff --git a/pkgs/development/compilers/gcc/common/builder.nix b/pkgs/development/compilers/gcc/common/builder.nix index b1b5daeb00f1a..1e90828a6643d 100644 --- a/pkgs/development/compilers/gcc/common/builder.nix +++ b/pkgs/development/compilers/gcc/common/builder.nix @@ -363,6 +363,13 @@ originalAttrs: fi done '' + + lib.optionalString stdenv.targetPlatform.isCygwin '' + targetBinDir="''${targetConfig+$targetConfig/}bin" + for i in "''${!outputBin}/$targetLibDir"/cyg*.dll; do + mkdir -p "''${!outputLib}/$targetBinDir" + mv "$i" "''${!outputLib}/$targetBinDir"/ + done + '' # if cross-compiling, link from $lib/lib to $lib/${targetConfig}. # since native-compiles have $lib/lib as a directory (not a # symlink), this ensures that in every case we can assume that From 96e83b0389dbeb8f82f0e67811158f4c99250569 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Wed, 22 Oct 2025 15:27:03 -0300 Subject: [PATCH 056/119] cygwin.newlib-cygwin-nobin: remove --- pkgs/os-specific/cygwin/default.nix | 2 -- pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/os-specific/cygwin/default.nix b/pkgs/os-specific/cygwin/default.nix index 09f69ff9f9b25..0bbf4d96c5190 100644 --- a/pkgs/os-specific/cygwin/default.nix +++ b/pkgs/os-specific/cygwin/default.nix @@ -18,8 +18,6 @@ makeScopeWithSplicing' { w32api-headers = callPackage ./w32api { headersOnly = true; }; newlib-cygwin = callPackage ./newlib-cygwin { }; - # this is here to avoid symlinks being made to cygwin1.dll in /nix/store - newlib-cygwin-nobin = callPackage ./newlib-cygwin/nobin.nix { }; newlib-cygwin-headers = callPackage ./newlib-cygwin { headersOnly = true; }; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 1c42b9fc40035..8a26101591ee5 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6849,7 +6849,7 @@ with pkgs; else if libc == "ucrt" then if stdenv.hostPlatform.isMinGW then windows.mingw_w64 else windows.sdk else if libc == "cygwin" then - cygwin.newlib-cygwin-nobin + cygwin.newlib-cygwin else if libc == "libSystem" then if stdenv.hostPlatform.useiOSPrebuilt then darwin.iosSdkPkgs.libraries else darwin.libSystem else if libc == "fblibc" then From 4da783473ef5730899e209f60df6db6309625a46 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Wed, 22 Oct 2025 22:25:52 -0300 Subject: [PATCH 057/119] lzip: fix cygwin-build --- pkgs/by-name/lz/lzip/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/lz/lzip/package.nix b/pkgs/by-name/lz/lzip/package.nix index 1d92e7e6439a6..0bfe47a8c0c44 100644 --- a/pkgs/by-name/lz/lzip/package.nix +++ b/pkgs/by-name/lz/lzip/package.nix @@ -23,7 +23,7 @@ stdenv.mkDerivation rec { hash = "sha256-CUGKbY+4P1ET9b2FbglwPfXTe64DCMZo0PNG49PwpW8="; }; - patches = lib.optionals stdenv.hostPlatform.isMinGW [ + patches = lib.optionals (stdenv.hostPlatform.isMinGW || stdenv.hostPlatform.isCygwin) [ ./mingw-install-exe-file.patch ]; From e47f06a1245727c096bc8b157e65353e0da186ff Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 23 Oct 2025 14:17:40 -0300 Subject: [PATCH 058/119] cygwin: add tests --- pkgs/os-specific/cygwin/default.nix | 2 + pkgs/os-specific/cygwin/tests/default.nix | 130 ++++++++++++++++++ pkgs/os-specific/cygwin/tests/dll/Makefile | 16 +++ pkgs/os-specific/cygwin/tests/dll/hello.c | 7 + pkgs/os-specific/cygwin/tests/dll/hello.h | 2 + pkgs/os-specific/cygwin/tests/dll2/Makefile | 16 +++ pkgs/os-specific/cygwin/tests/dll2/hello2.c | 6 + pkgs/os-specific/cygwin/tests/dll2/hello2.h | 2 + pkgs/os-specific/cygwin/tests/exe/Makefile | 13 ++ pkgs/os-specific/cygwin/tests/exe/main.c | 6 + .../cygwin/tests/user32-dll/Makefile | 16 +++ .../cygwin/tests/user32-dll/peek.c | 7 + .../cygwin/tests/user32-dll/peek.h | 2 + .../cygwin/tests/user32-exe/Makefile | 13 ++ .../cygwin/tests/user32-exe/main.c | 6 + pkgs/os-specific/cygwin/tests/user32/Makefile | 13 ++ pkgs/os-specific/cygwin/tests/user32/main.c | 7 + 17 files changed, 264 insertions(+) create mode 100644 pkgs/os-specific/cygwin/tests/default.nix create mode 100644 pkgs/os-specific/cygwin/tests/dll/Makefile create mode 100644 pkgs/os-specific/cygwin/tests/dll/hello.c create mode 100644 pkgs/os-specific/cygwin/tests/dll/hello.h create mode 100644 pkgs/os-specific/cygwin/tests/dll2/Makefile create mode 100644 pkgs/os-specific/cygwin/tests/dll2/hello2.c create mode 100644 pkgs/os-specific/cygwin/tests/dll2/hello2.h create mode 100644 pkgs/os-specific/cygwin/tests/exe/Makefile create mode 100644 pkgs/os-specific/cygwin/tests/exe/main.c create mode 100644 pkgs/os-specific/cygwin/tests/user32-dll/Makefile create mode 100644 pkgs/os-specific/cygwin/tests/user32-dll/peek.c create mode 100644 pkgs/os-specific/cygwin/tests/user32-dll/peek.h create mode 100644 pkgs/os-specific/cygwin/tests/user32-exe/Makefile create mode 100644 pkgs/os-specific/cygwin/tests/user32-exe/main.c create mode 100644 pkgs/os-specific/cygwin/tests/user32/Makefile create mode 100644 pkgs/os-specific/cygwin/tests/user32/main.c diff --git a/pkgs/os-specific/cygwin/default.nix b/pkgs/os-specific/cygwin/default.nix index 0bbf4d96c5190..2a8bb75ad17d4 100644 --- a/pkgs/os-specific/cygwin/default.nix +++ b/pkgs/os-specific/cygwin/default.nix @@ -19,5 +19,7 @@ makeScopeWithSplicing' { newlib-cygwin = callPackage ./newlib-cygwin { }; newlib-cygwin-headers = callPackage ./newlib-cygwin { headersOnly = true; }; + + tests = callPackage ./tests { }; }; } diff --git a/pkgs/os-specific/cygwin/tests/default.nix b/pkgs/os-specific/cygwin/tests/default.nix new file mode 100644 index 0000000000000..a8744001dc2dc --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/default.nix @@ -0,0 +1,130 @@ +{ + dieHook, + lib, + stdenv, + testers, + runCommand, +}: + +rec { + dll = stdenv.mkDerivation { + name = "dll"; + src = ./dll; + outputs = [ + "out" + "dev" + ]; + buildInputs = [ dll2 ]; + strictDeps = true; + }; + + dll2 = stdenv.mkDerivation { + name = "dll2"; + src = ./dll2; + outputs = [ + "out" + "dev" + ]; + }; + + exe = stdenv.mkDerivation { + name = "exe"; + src = ./exe; + buildInputs = [ dll ]; + nativeBuildInputs = [ dieHook ]; + strictDeps = true; + doCheck = true; + postFixup = ''[[ -e "$out"/bin/cyghello2.dll ]] || die missing indirect dependency''; + }; + + link-dll = exe.overrideAttrs { + name = "link-dll"; + preFixup = '' + ln -s ${lib.getLib dll}/bin/cyghello.dll "$out"/bin/ + ''; + }; + + user32 = stdenv.mkDerivation { + name = "user32"; + src = ./user32; + allowedImpureDLLs = [ "USER32.dll" ]; + }; + + impure-dll = testers.testBuildFailure ( + user32.overrideAttrs { + name = "impure-dll"; + allowedImpureDLLs = [ ]; + } + ); + + user32-dll = stdenv.mkDerivation { + name = "user32-dll"; + src = ./user32-dll; + outputs = [ + "out" + "dev" + ]; + allowedImpureDLLs = [ "USER32.dll" ]; + }; + + user32-exe = stdenv.mkDerivation { + name = "user32-exe"; + src = ./user32-exe; + buildInputs = [ user32-dll ]; + strictDeps = true; + doCheck = true; + }; + + link-dir-dll = exe.overrideAttrs { + name = "link-dir-dll"; + preFixup = '' + mkdir "$out"/libexec + ln -s ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/libexec/ + linkDLLsDir="$out"/bin linkDLLs "$out"/libexec/cygpeek.dll + ''; + }; + + link-dir-exe = exe.overrideAttrs { + name = "link-dir-exe"; + preFixup = '' + mkdir "$out"/libexec + ln -s ${lib.getLib user32-exe}/bin/{peek.exe,cygpeek.dll} "$out"/libexec/ + linkDLLsDir="$out"/bin linkDLLs "$out"/libexec/peek.exe + ''; + }; + + link-user32-dll = exe.overrideAttrs { + name = "link-user32-dll"; + preFixup = '' + ln -s ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/bin/ + ''; + }; + + copy-dll-impure = testers.testBuildFailure ( + user32-exe.overrideAttrs { + name = "copy-dll-impure"; + preFixup = '' + cp ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/bin/ + ''; + } + ); + + copy-dll = user32-exe.overrideAttrs { + name = "copy-dll"; + preFixup = '' + cp ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/bin/ + linkDLLs "$out"/bin/cygpeek.dll + ''; + allowedImpureDLLs = [ "USER32.dll" ]; + }; + + double-link = user32-exe.overrideAttrs { + name = "double-link"; + preFixup = ''linkDLLs "$out"''; + }; + + utf8-glob = runCommand "utf8-glob" { } '' + touch NetLock_Arany_=Class_Gold=_FÅ‘tanstvny:49412ce40010.crt + ls -l NetLock* > "$out" + ''; +} diff --git a/pkgs/os-specific/cygwin/tests/dll/Makefile b/pkgs/os-specific/cygwin/tests/dll/Makefile new file mode 100644 index 0000000000000..25e1e53c38e4b --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/dll/Makefile @@ -0,0 +1,16 @@ +.PHONY: all install +all: cyghello.dll + +install: $(out)/bin/cyghello.dll $(out)/lib/libhello.dll.a $(out)/include/hello.h + +cyghello.dll libhello.dll.a: hello.c + $(CC) -o $@ $^ -shared -Wl,--out-implib,libhello.dll.a -Wl,--export-all-symbols -lhello2 + +$(out)/bin/cyghello.dll: cyghello.dll + install -m755 -D $< $@ + +$(out)/lib/libhello.dll.a: libhello.dll.a + install -m644 -D $< $@ + +$(out)/include/hello.h: hello.h + install -m644 -D $< $@ diff --git a/pkgs/os-specific/cygwin/tests/dll/hello.c b/pkgs/os-specific/cygwin/tests/dll/hello.c new file mode 100644 index 0000000000000..db1a301c91a4d --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/dll/hello.c @@ -0,0 +1,7 @@ +#include "hello.h" +#include +#include + +void hello() { + hello2(); +} diff --git a/pkgs/os-specific/cygwin/tests/dll/hello.h b/pkgs/os-specific/cygwin/tests/dll/hello.h new file mode 100644 index 0000000000000..a4a0b54c6052c --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/dll/hello.h @@ -0,0 +1,2 @@ +#pragma once +void hello(); diff --git a/pkgs/os-specific/cygwin/tests/dll2/Makefile b/pkgs/os-specific/cygwin/tests/dll2/Makefile new file mode 100644 index 0000000000000..87c5c1a9b9ccf --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/dll2/Makefile @@ -0,0 +1,16 @@ +.PHONY: all install +all: cyghello2.dll + +install: $(out)/bin/cyghello2.dll $(out)/lib/libhello2.dll.a $(out)/include/hello2.h + +cyghello2.dll libhello2.dll.a: hello2.c + $(CC) -o $@ $^ -shared -Wl,--out-implib,libhello2.dll.a -Wl,--export-all-symbols + +$(out)/bin/cyghello2.dll: cyghello2.dll + install -m755 -D $< $@ + +$(out)/lib/libhello2.dll.a: libhello2.dll.a + install -m644 -D $< $@ + +$(out)/include/hello2.h: hello2.h + install -m644 -D $< $@ diff --git a/pkgs/os-specific/cygwin/tests/dll2/hello2.c b/pkgs/os-specific/cygwin/tests/dll2/hello2.c new file mode 100644 index 0000000000000..d23050fbb7761 --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/dll2/hello2.c @@ -0,0 +1,6 @@ +#include +#include "hello2.h" + +void hello2() { + printf("Hello, World!\n"); +} diff --git a/pkgs/os-specific/cygwin/tests/dll2/hello2.h b/pkgs/os-specific/cygwin/tests/dll2/hello2.h new file mode 100644 index 0000000000000..34e200a07e95c --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/dll2/hello2.h @@ -0,0 +1,2 @@ +#pragma once +void hello2(); diff --git a/pkgs/os-specific/cygwin/tests/exe/Makefile b/pkgs/os-specific/cygwin/tests/exe/Makefile new file mode 100644 index 0000000000000..da16b5d08c79b --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/exe/Makefile @@ -0,0 +1,13 @@ +.PHONY: all check install +all: hello.exe + +install: $(out)/bin/hello.exe + +hello.exe: main.c + $(CC) -o $@ $^ -lhello + +check: hello.exe + ./hello.exe + +$(out)/bin/hello.exe: hello.exe + install -m755 -D $< $@ diff --git a/pkgs/os-specific/cygwin/tests/exe/main.c b/pkgs/os-specific/cygwin/tests/exe/main.c new file mode 100644 index 0000000000000..9dbc882ea430e --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/exe/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + hello(); + return 0; +} diff --git a/pkgs/os-specific/cygwin/tests/user32-dll/Makefile b/pkgs/os-specific/cygwin/tests/user32-dll/Makefile new file mode 100644 index 0000000000000..483ad8854a060 --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/user32-dll/Makefile @@ -0,0 +1,16 @@ +.PHONY: all install +all: cygpeek.dll + +install: $(out)/bin/cygpeek.dll $(out)/lib/libpeek.dll.a $(out)/include/peek.h + +cygpeek.dll libpeek.dll.a: peek.c + $(CC) -o $@ $^ -shared -Wl,--out-implib,libpeek.dll.a -Wl,--export-all-symbols + +$(out)/bin/cygpeek.dll: cygpeek.dll + install -m755 -D $< $@ + +$(out)/lib/libpeek.dll.a: libpeek.dll.a + install -m644 -D $< $@ + +$(out)/include/peek.h: peek.h + install -m644 -D $< $@ diff --git a/pkgs/os-specific/cygwin/tests/user32-dll/peek.c b/pkgs/os-specific/cygwin/tests/user32-dll/peek.c new file mode 100644 index 0000000000000..715adb003c158 --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/user32-dll/peek.c @@ -0,0 +1,7 @@ +#include + +int peek() +{ + MSG msg; + PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); +} diff --git a/pkgs/os-specific/cygwin/tests/user32-dll/peek.h b/pkgs/os-specific/cygwin/tests/user32-dll/peek.h new file mode 100644 index 0000000000000..800f23f77da5d --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/user32-dll/peek.h @@ -0,0 +1,2 @@ +#pragma once +void peek(); diff --git a/pkgs/os-specific/cygwin/tests/user32-exe/Makefile b/pkgs/os-specific/cygwin/tests/user32-exe/Makefile new file mode 100644 index 0000000000000..2316018189140 --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/user32-exe/Makefile @@ -0,0 +1,13 @@ +.PHONY: all check install +all: peek.exe + +install: $(out)/bin/peek.exe + +peek.exe: main.c + $(CC) -o $@ $^ -lpeek + +check: peek.exe + ./peek.exe + +$(out)/bin/peek.exe: peek.exe + install -m755 -D $< $@ diff --git a/pkgs/os-specific/cygwin/tests/user32-exe/main.c b/pkgs/os-specific/cygwin/tests/user32-exe/main.c new file mode 100644 index 0000000000000..cddc78c91cabe --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/user32-exe/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + peek(); + return 0; +} diff --git a/pkgs/os-specific/cygwin/tests/user32/Makefile b/pkgs/os-specific/cygwin/tests/user32/Makefile new file mode 100644 index 0000000000000..6c696a2e8cd02 --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/user32/Makefile @@ -0,0 +1,13 @@ +.PHONY: all check install +all: hello.exe + +install: $(out)/bin/hello.exe + +hello.exe: main.c + $(CC) -o $@ $^ + +check: hello.exe + ./hello.exe + +$(out)/bin/hello.exe: hello.exe + install -m755 -D $< $@ diff --git a/pkgs/os-specific/cygwin/tests/user32/main.c b/pkgs/os-specific/cygwin/tests/user32/main.c new file mode 100644 index 0000000000000..9cc135770d21f --- /dev/null +++ b/pkgs/os-specific/cygwin/tests/user32/main.c @@ -0,0 +1,7 @@ +#include + +int main() +{ + MSG msg; + PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); +} From 1269b735ac525f078d1fd9f7e36795561dd2bbcf Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 23 Oct 2025 16:00:17 -0300 Subject: [PATCH 059/119] cygwin-dll-path: init hook --- pkgs/build-support/cc-wrapper/default.nix | 19 ++++++++++++------- .../setup-hooks/cygwin-dll-path.sh | 10 ++++++++++ pkgs/stdenv/generic/make-derivation.nix | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 pkgs/build-support/setup-hooks/cygwin-dll-path.sh diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 89cc7c4ce4fd5..b3c009595562d 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -602,13 +602,18 @@ stdenvNoCC.mkDerivation { dontUnpack = true; installPhase = if targetPlatform.isCygwin then - '' - echo addToSearchPath "HOST_PATH" "${cc_solib}/bin" >> $out - # Work around build failure caused by the gnulib workaround for - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870. remove after - # gnulib is updated in core packages (e.g. iconv, gnupatch, gnugrep) - echo appendToVar configureFlags gl_cv_clean_version_stddef=yes >> $out - '' + ( + '' + echo addToSearchPath "_HOST_PATH" "${cc_solib}/bin" >> $out + # Work around build failure caused by the gnulib workaround for + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870. remove after + # gnulib is updated in core packages (e.g. iconv, gnupatch, gnugrep) + echo appendToVar configureFlags gl_cv_clean_version_stddef=yes >> $out + '' + + lib.optionalString (hostPlatform.canExecute targetPlatform) '' + echo addToSearchPath "_PATH" "${cc_solib}/bin" >> $out + '' + ) else '' echo addToSearchPath "LINK_DLL_FOLDERS" "${cc_solib}/lib" > $out diff --git a/pkgs/build-support/setup-hooks/cygwin-dll-path.sh b/pkgs/build-support/setup-hooks/cygwin-dll-path.sh new file mode 100644 index 0000000000000..27994475aa913 --- /dev/null +++ b/pkgs/build-support/setup-hooks/cygwin-dll-path.sh @@ -0,0 +1,10 @@ +# shellcheck shell=bash + +_addDLLPaths() { + # this reverts part of what strictDeps does, but this is needed for DLLs to be + # found before cygwin-dll-link runs + addToSearchPath "_PATH" "$1/bin" +} + +# shellcheck disable=SC2154 +addEnvHooks "$targetOffset" _addDLLPaths diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 0a46f9b11c534..75b3e674f6f9b 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -476,6 +476,7 @@ let ++ optional separateDebugInfo' ../../build-support/setup-hooks/separate-debug-info.sh ++ optional isWindows ../../build-support/setup-hooks/win-dll-link.sh ++ optional isCygwin ../../build-support/setup-hooks/cygwin-dll-link.sh + ++ optional (isCygwin && canExecuteHostOnBuild) ../../build-support/setup-hooks/cygwin-dll-path.sh ++ optionals doCheck nativeCheckInputs ++ optionals doInstallCheck nativeInstallCheckInputs; From 932af9951732b406750df84e8f0ed2e55361d761 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 23 Oct 2025 17:25:19 -0300 Subject: [PATCH 060/119] flake-systems: add cygwin --- lib/systems/flake-systems.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/systems/flake-systems.nix b/lib/systems/flake-systems.nix index 851dc1af71818..050551bff594f 100644 --- a/lib/systems/flake-systems.nix +++ b/lib/systems/flake-systems.nix @@ -25,4 +25,5 @@ "powerpc64le-linux" "riscv64-linux" "x86_64-freebsd" + "x86_64-cygwin" ] From 68f916a4a4d0ab5737a521ede34f5d7df9068ef7 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 23 Oct 2025 18:29:15 -0300 Subject: [PATCH 061/119] texinfo: fix cygwin build --- pkgs/development/tools/misc/texinfo/common.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/development/tools/misc/texinfo/common.nix b/pkgs/development/tools/misc/texinfo/common.nix index 00dd5a5811a59..6c78eeee0521e 100644 --- a/pkgs/development/tools/misc/texinfo/common.nix +++ b/pkgs/development/tools/misc/texinfo/common.nix @@ -106,7 +106,9 @@ stdenv.mkDerivation { libiconv gawk ] - ++ optional interactive ncurses; + ++ optional interactive ncurses + # cygwin needs this so the perl DLL is in HOST_PATH for XS + ++ optional (!crossBuildTools && stdenv.hostPlatform.isCygwin) perl; configureFlags = [ "PERL=${buildPackages.perl}/bin/perl" From 59cfee00cd7c8ebff21241a5ed815e6ef7109c83 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 24 Oct 2025 19:22:20 -0300 Subject: [PATCH 062/119] fetchurl: disable gssSupport on cygwin --- pkgs/top-level/all-packages.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 8a26101591ee5..21444a8ec6418 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -611,7 +611,9 @@ with pkgs; # So turn gssSupport off there, and on Windows. # On other platforms, keep the previous value. gssSupport = - if stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWindows then + if + stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isCygwin + then false else old.gssSupport or true; # `? true` is the default From e6b0fc12da4a718d8ea69a751bac885e87e42875 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sat, 25 Oct 2025 10:26:36 -0300 Subject: [PATCH 063/119] findutils: fix cygwin build --- pkgs/tools/misc/findutils/default.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkgs/tools/misc/findutils/default.nix b/pkgs/tools/misc/findutils/default.nix index a5e8459355ac9..9a89b54c30d4a 100644 --- a/pkgs/tools/misc/findutils/default.nix +++ b/pkgs/tools/misc/findutils/default.nix @@ -22,6 +22,10 @@ stdenv.mkDerivation (finalAttrs: { postPatch = '' substituteInPlace xargs/xargs.c --replace 'char default_cmd[] = "echo";' 'char default_cmd[] = "${coreutils}/bin/echo";' + '' + # on cygwin, ARG_MAX is a low value which only applies to executing non-cygwin processes + + lib.optionalString stdenv.hostPlatform.isCygwin '' + substituteInPlace lib/buildcmd.c --replace-fail '#ifdef ARG_MAX' '#if 0' ''; patches = [ @@ -40,6 +44,11 @@ stdenv.mkDerivation (finalAttrs: { doCheck = !stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isFreeBSD + # FAIL: tests/find/depth-unreadable-dir.sh + # FAIL: tests/find/used.sh + # FAIL: tests/find/newer.sh + # FAIL: tests/find/type_list.sh + && !stdenv.hostPlatform.isCygwin && !(stdenv.hostPlatform.libc == "glibc" && stdenv.hostPlatform.isi686) && (stdenv.hostPlatform.libc != "musl") && stdenv.hostPlatform == stdenv.buildPlatform; From 1a7850db15c341c28a827ecca4b698a912f0abec Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sat, 25 Oct 2025 18:42:11 -0300 Subject: [PATCH 064/119] cygwin: fix bootstrap on non-cross --- .../cygwin/newlib-cygwin/default.nix | 20 ++++++++++++++++++- pkgs/os-specific/cygwin/w32api/default.nix | 20 ++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix index f9fef7af0e5a3..22296637442ea 100644 --- a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix +++ b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix @@ -11,11 +11,29 @@ perl, w32api, w32api-headers, + newlib-cygwin-headers, headersOnly ? false, }: -(if headersOnly then stdenvNoCC else stdenvNoLibc).mkDerivation ( +let + stdenv = + let + bintools = stdenvNoLibc.cc.bintools.override { + libc = newlib-cygwin-headers; + noLibc = false; + }; + in + stdenvNoLibc.override { + cc = stdenvNoLibc.cc.override { + libc = newlib-cygwin-headers; + noLibc = false; + inherit bintools; + }; + }; + +in +(if headersOnly then stdenvNoCC else stdenv).mkDerivation ( finalAttrs: { pname = "newlib-cygwin${lib.optionalString headersOnly "-headers"}"; diff --git a/pkgs/os-specific/cygwin/w32api/default.nix b/pkgs/os-specific/cygwin/w32api/default.nix index b99f84e67365a..8d900d3889263 100644 --- a/pkgs/os-specific/cygwin/w32api/default.nix +++ b/pkgs/os-specific/cygwin/w32api/default.nix @@ -4,11 +4,29 @@ stdenvNoLibc, autoreconfHook, windows, + newlib-cygwin-headers, headersOnly ? false, }: -(if headersOnly then stdenvNoCC else stdenvNoLibc).mkDerivation ( +let + stdenv = + let + bintools = stdenvNoLibc.cc.bintools.override { + libc = newlib-cygwin-headers; + noLibc = false; + }; + in + stdenvNoLibc.override { + cc = stdenvNoLibc.cc.override { + libc = newlib-cygwin-headers; + noLibc = false; + inherit bintools; + }; + }; + +in +(if headersOnly then stdenvNoCC else stdenv).mkDerivation ( { pname = "w32api${lib.optionalString headersOnly "-headers"}"; From fe1739a549dbd01a6590bf22a6bf7a4039a6a29c Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 26 Oct 2025 09:01:40 -0300 Subject: [PATCH 065/119] icu: fix cygwin build --- pkgs/development/libraries/icu/make-icu.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/icu/make-icu.nix b/pkgs/development/libraries/icu/make-icu.nix index 00ba528081ac4..a6b8096857113 100644 --- a/pkgs/development/libraries/icu/make-icu.nix +++ b/pkgs/development/libraries/icu/make-icu.nix @@ -144,7 +144,13 @@ let substituteInPlace "$dev/bin/icu-config" \ ${lib.concatMapStringsSep " " (r: "--replace '${r.from}' '${r.to}'") replacements} '' - ); + ) + # TODO: use MINGW_MOVEDLLSTOBINDIR? + + lib.optionalString stdenv.hostPlatform.isCygwin '' + mkdir -p "$out"/bin + set -x + mv "$out"/lib/cyg*.dll "$out"/bin/ + ''; postFixup = ''moveToOutput lib/icu "$dev" ''; }; From 29737eab4b9ddfa441a1ccaec7feb449cfa16324 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 31 Oct 2025 09:45:23 -0300 Subject: [PATCH 066/119] cpython: add tests --- .../interpreters/python/cpython/default.nix | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 85a7b65898caf..678a6bf4188c1 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -95,6 +95,7 @@ # tests testers, + runCommand, # allow pythonMinimal to prevent accidental dependencies it doesn't want # Having this as an option is useful to allow overriding, eg. adding things to @@ -832,9 +833,24 @@ stdenv.mkDerivation (finalAttrs: { ]; }; - tests = passthru.tests // { - pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; - }; + tests = + passthru.tests + // { + pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + } + // ( + let + testPython = + name: script: + runCommand "python-test-${name}" { + inherit script; + } ''"${lib.getExe finalAttrs.finalPackage}" -c "$script" > "$out"''; + in + { + sax = testPython "sax" "import xml.sax;xml.sax.make_parser()"; + semaphore = testPython "semaphore" "from _multiprocessing import SemLock"; + } + ); }; enableParallelBuilding = true; From 6a7f4ffdb823aae2a87851b9bbb42c71312c6db3 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 31 Oct 2025 15:08:26 -0300 Subject: [PATCH 067/119] cacert: fix cygwin build --- pkgs/by-name/ca/cacert/package.nix | 40 +++++++++++++++++------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/pkgs/by-name/ca/cacert/package.nix b/pkgs/by-name/ca/cacert/package.nix index ccfb2b777d96d..3f42bb0e78235 100644 --- a/pkgs/by-name/ca/cacert/package.nix +++ b/pkgs/by-name/ca/cacert/package.nix @@ -94,23 +94,29 @@ stdenv.mkDerivation { --p11kit_output ca-bundle.trust.p11-kit ''; - installPhase = '' - install -D -t "$out/etc/ssl/certs" ca-bundle.crt - - # install standard PEM compatible bundle - install -D -t "$out/etc/ssl/certs" ca-no-trust-rules-bundle.crt - - # install p11-kit specific output to p11kit output - install -D -t "$p11kit/etc/ssl/trust-source" ca-bundle.trust.p11-kit - - # install individual certs in unbundled output - install -D -t "$unbundled/etc/ssl/certs" unbundled/*.crt - - # install hashed certs in hashed output - # use cp as install doesn't copy symlinks - mkdir -p $hashed/etc/ssl/certs/ - cp -P hashed/* $hashed/etc/ssl/certs/ - ''; + installPhase = + # on cygwin, globbing returns an invalid path when LANG is unset + # > install: cannot stat 'unbundled/NetLock_Arany_=Class_Gold=_F'$'\030''Å‘tan'$'\372''s'$'\355''tv'$'\341''ny:49412ce40010.crt': No such file or directory + lib.optionalString stdenv.buildPlatform.isCygwin '' + export LANG=C + '' + + '' + install -D -t "$out/etc/ssl/certs" ca-bundle.crt + + # install standard PEM compatible bundle + install -D -t "$out/etc/ssl/certs" ca-no-trust-rules-bundle.crt + + # install p11-kit specific output to p11kit output + install -D -t "$p11kit/etc/ssl/trust-source" ca-bundle.trust.p11-kit + + # install individual certs in unbundled output + install -D -t "$unbundled/etc/ssl/certs" unbundled/*.crt + + # install hashed certs in hashed output + # use cp as install doesn't copy symlinks + mkdir -p $hashed/etc/ssl/certs/ + cp -P hashed/* $hashed/etc/ssl/certs/ + ''; setupHook = ./setup-hook.sh; From 6e8abb58e2d9724f86a04ca806a9e99f33d15331 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 31 Oct 2025 16:03:54 -0300 Subject: [PATCH 068/119] perlPackages.NetSMTPSSL: fix cygwin build --- pkgs/top-level/perl-packages.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/top-level/perl-packages.nix b/pkgs/top-level/perl-packages.nix index 14a176e0eb0f5..d80eff9222716 100644 --- a/pkgs/top-level/perl-packages.nix +++ b/pkgs/top-level/perl-packages.nix @@ -25985,6 +25985,8 @@ with self; hash = "sha256-eynEWt0Z09UIS3Ufe6iajkBHmkRs4hz9nMdB5VgzKgA="; }; propagatedBuildInputs = [ IOSocketSSL ]; + # TODO: fix PATH needed for dependencies + doCheck = !stdenv.buildPlatform.isCygwin; meta = { description = "SSL support for Net::SMTP"; license = with lib.licenses; [ From 2ebfacb0ed4382d6ece7ddbbcd19a6171b13b820 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 2 Nov 2025 17:11:37 -0400 Subject: [PATCH 069/119] ninja: fix cygwin build --- pkgs/by-name/ni/ninja/fix-cygwin-build.patch | 12 ++++++++++++ pkgs/by-name/ni/ninja/package.nix | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 pkgs/by-name/ni/ninja/fix-cygwin-build.patch diff --git a/pkgs/by-name/ni/ninja/fix-cygwin-build.patch b/pkgs/by-name/ni/ninja/fix-cygwin-build.patch new file mode 100644 index 0000000000000..04211bcf00949 --- /dev/null +++ b/pkgs/by-name/ni/ninja/fix-cygwin-build.patch @@ -0,0 +1,12 @@ +diff --git a/src/util.cc b/src/util.cc +index aeb1ce4..876cc3d 100644 +--- a/src/util.cc ++++ b/src/util.cc +@@ -17,6 +17,7 @@ + #ifdef __CYGWIN__ + #include + #include ++#include + #elif defined( _WIN32) + #include + #include diff --git a/pkgs/by-name/ni/ninja/package.nix b/pkgs/by-name/ni/ninja/package.nix index 6f15be615ace1..2625feb1f4334 100644 --- a/pkgs/by-name/ni/ninja/package.nix +++ b/pkgs/by-name/ni/ninja/package.nix @@ -40,6 +40,10 @@ stdenv.mkDerivation (finalAttrs: { depsBuildBuild = [ buildPackages.stdenv.cc ]; + env = lib.optionalAttrs stdenv.hostPlatform.isCygwin { + NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isCygwin "-D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE"; + }; + nativeBuildInputs = [ python3 re2c @@ -62,7 +66,8 @@ stdenv.mkDerivation (finalAttrs: { url = "https://github.com/ninja-build/ninja/commit/9cf13cd1ecb7ae649394f4133d121a01e191560b.patch"; hash = "sha256-zlMs9LDJ2thtiSUjbsONyqoyYxrB/Ilt2Ljr0nCU6nQ="; }) - ]; + ] + ++ lib.optional stdenv.hostPlatform.isCygwin ./fix-cygwin-build.patch; postPatch = '' # write rebuild args to file after bootstrap From 6801b7683165bf3aeedeeb04f562ad82702d3504 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 2 Nov 2025 20:29:15 -0400 Subject: [PATCH 070/119] libxml2: fix cygwin build --- pkgs/development/libraries/libxml2/common.nix | 2 +- .../libraries/libxml2/fix-cygwin-build.patch | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/libraries/libxml2/fix-cygwin-build.patch diff --git a/pkgs/development/libraries/libxml2/common.nix b/pkgs/development/libraries/libxml2/common.nix index bc43cfd9d6e3e..48a9cf7e1bd7c 100644 --- a/pkgs/development/libraries/libxml2/common.nix +++ b/pkgs/development/libraries/libxml2/common.nix @@ -49,7 +49,7 @@ stdenv'.mkDerivation (finalAttrs: { ++ lib.optional (enableStatic && enableShared) "static"; outputMan = "bin"; - patches = [ ] ++ extraPatches; + patches = [ ] ++ lib.optional stdenv.hostPlatform.isCygwin ./fix-cygwin-build.patch ++ extraPatches; strictDeps = true; diff --git a/pkgs/development/libraries/libxml2/fix-cygwin-build.patch b/pkgs/development/libraries/libxml2/fix-cygwin-build.patch new file mode 100644 index 0000000000000..a1905964c0827 --- /dev/null +++ b/pkgs/development/libraries/libxml2/fix-cygwin-build.patch @@ -0,0 +1,12 @@ +diff --git a/globals.c b/globals.c +index e0b05a2..546c8be 100644 +--- a/globals.c ++++ b/globals.c +@@ -347,6 +347,7 @@ const xmlSAXLocator xmlDefaultSAXLocator = { + * + * Default old SAX v1 handler for HTML, builds the DOM tree + */ ++XMLPUBVAR const xmlSAXHandlerV1 htmlDefaultSAXHandler; + const xmlSAXHandlerV1 htmlDefaultSAXHandler = { + xmlSAX2InternalSubset, + NULL, From b896ff6561aa2b566148c4bb0a702c669a0653a2 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 2 Nov 2025 21:37:42 -0400 Subject: [PATCH 071/119] opensp: fix cygwin build --- pkgs/by-name/op/opensp/package.nix | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/pkgs/by-name/op/opensp/package.nix b/pkgs/by-name/op/opensp/package.nix index d376fbe329ddc..c1f91b9552749 100644 --- a/pkgs/by-name/op/opensp/package.nix +++ b/pkgs/by-name/op/opensp/package.nix @@ -10,6 +10,7 @@ automake, libtool, autoreconfHook, + updateAutotoolsGnuConfigScriptsHook, }: stdenv.mkDerivation rec { @@ -48,10 +49,6 @@ stdenv.mkDerivation rec { sed -i -e 's/name="idm.*"//g' $out/share/doc/OpenSP/releasenotes.html ''; - preConfigure = lib.optionalString stdenv.hostPlatform.isCygwin '' - autoreconf -fi - ''; - strictDeps = true; nativeBuildInputs = [ @@ -61,12 +58,8 @@ stdenv.mkDerivation rec { ] # Clang 16 fails to build due to inappropriate definitions in the `config.h` generated by the # existing configure scripts. Regenerate them to make sure they detect its features correctly. - ++ lib.optional stdenv.cc.isClang autoreconfHook - ++ lib.optionals stdenv.hostPlatform.isCygwin [ - autoconf - automake - libtool - ]; + ++ lib.optional (stdenv.cc.isClang || stdenv.hostPlatform.isCygwin) autoreconfHook + ++ lib.optional stdenv.hostPlatform.isCygwin updateAutotoolsGnuConfigScriptsHook; env = lib.optionalAttrs stdenv.cc.isGNU { NIX_CFLAGS_COMPILE = "-fpermissive"; From 9cdc10946432c9e4d4f3cfe670a651430914f1a7 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 3 Nov 2025 22:35:54 -0400 Subject: [PATCH 072/119] libgit2: fix cygwin build --- pkgs/by-name/li/libgit2/package.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/by-name/li/libgit2/package.nix b/pkgs/by-name/li/libgit2/package.nix index 20655c7b77e1d..20b070359a7a3 100644 --- a/pkgs/by-name/li/libgit2/package.nix +++ b/pkgs/by-name/li/libgit2/package.nix @@ -82,6 +82,18 @@ stdenv.mkDerivation (finalAttrs: { # failed to set permissions on ...: Operation not permitted testArgs+=(-xrepo::init::extended_1) testArgs+=(-xrepo::template::extended_with_template_and_shared_mode) + '' + + lib.optionalString stdenv.buildPlatform.isCygwin '' + testArgs+=( + -xiterator::workdir::skips_unreadable_dirs + -xodb::loose::permissions_standard + -xodb::loose::permissions_readonly + -xodb::loose::permissions_readwrite + -xpack::packbuilder::permissions_readwrite + -xstatus::worktree::unreadable + ) + '' + + '' ( set -x From 523ea40e5ac5d4b0d569516248f2b17650eacc27 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 3 Nov 2025 23:26:21 -0400 Subject: [PATCH 073/119] WIP: cygwin.rebase: init at 4.6.6 --- pkgs/os-specific/cygwin/default.nix | 2 ++ pkgs/os-specific/cygwin/rebase/default.nix | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 pkgs/os-specific/cygwin/rebase/default.nix diff --git a/pkgs/os-specific/cygwin/default.nix b/pkgs/os-specific/cygwin/default.nix index 2a8bb75ad17d4..798aadf47aa67 100644 --- a/pkgs/os-specific/cygwin/default.nix +++ b/pkgs/os-specific/cygwin/default.nix @@ -20,6 +20,8 @@ makeScopeWithSplicing' { newlib-cygwin = callPackage ./newlib-cygwin { }; newlib-cygwin-headers = callPackage ./newlib-cygwin { headersOnly = true; }; + rebase = callPackage ./rebase { }; + tests = callPackage ./tests { }; }; } diff --git a/pkgs/os-specific/cygwin/rebase/default.nix b/pkgs/os-specific/cygwin/rebase/default.nix new file mode 100644 index 0000000000000..fd26fc8e3b897 --- /dev/null +++ b/pkgs/os-specific/cygwin/rebase/default.nix @@ -0,0 +1,22 @@ +{ + autoreconfHook, + fetchgit, + lib, + stdenv, + w32api-headers, +}: + +stdenv.mkDerivation rec { + pname = "rebase"; + version = "4.6.6"; + + src = fetchgit { + url = "https://cygwin.com/git/cygwin-apps/rebase.git"; + rev = "${pname}-${version}"; + hash = "sha256-mZNPjgIwkUPOBZvMMVeVTXqJRu/sXVoZshm9Q1oa2u0="; + }; + + strictDeps = true; + + nativeBuildInputs = [ autoreconfHook ]; +} From 5ca40ac501332a670cad1c24afeb68962b55ebdb Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 6 Nov 2025 10:16:21 -0400 Subject: [PATCH 074/119] meson: fix cygwin build --- pkgs/by-name/me/meson/package.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/me/meson/package.nix b/pkgs/by-name/me/meson/package.nix index 322bf863e0f90..20570bd0ea252 100644 --- a/pkgs/by-name/me/meson/package.nix +++ b/pkgs/by-name/me/meson/package.nix @@ -142,9 +142,15 @@ python3.pkgs.buildPythonApplication rec { # fails for unknown reason "test cases/python/4 custom target depends extmodule" ] + ++ lib.optionals stdenv.hostPlatform.isCygwin [ + # fails for unknown reason + "test cases/common/122 no buildincdir" + "test cases/common/184 openmp" + "test cases/windows/8 find program" + ] )) ++ [ - ''HOME="$TMPDIR" ${ + ''HOME="$TMPDIR" ${if stdenv.hostPlatform.isCygwin then "CYGWIN=winsymlinks=native " else ""}${ if python3.isPyPy then python3.interpreter else "python" } ./run_project_tests.py'' "runHook postCheck" From 2caf1254dca155b2968af4f4c4cc083845c7d0f4 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 6 Nov 2025 16:12:43 -0400 Subject: [PATCH 075/119] bmake: fix cygwin build --- pkgs/by-name/bm/bmake/package.nix | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pkgs/by-name/bm/bmake/package.nix b/pkgs/by-name/bm/bmake/package.nix index 8c7c6841cf3e4..5f89824f21561 100644 --- a/pkgs/by-name/bm/bmake/package.nix +++ b/pkgs/by-name/bm/bmake/package.nix @@ -73,12 +73,20 @@ stdenv.mkDerivation (finalAttrs: { # * Disable deptgt-delete_on_error test (alpine does this too) # * Disable shell-ksh test (ksh doesn't compile with musl) # * Fix test failing due to different strerror(3) output for musl and glibc - postPatch = lib.optionalString (stdenv.hostPlatform.libc == "musl") '' - sed -i unit-tests/Makefile \ - -e '/deptgt-delete_on_error/d' \ - -e '/shell-ksh/d' - substituteInPlace unit-tests/opt-chdir.exp --replace "File name" "Filename" - ''; + postPatch = + lib.optionalString (stdenv.hostPlatform.libc == "musl") '' + sed -i unit-tests/Makefile \ + -e '/deptgt-delete_on_error/d' \ + -e '/shell-ksh/d' + substituteInPlace unit-tests/opt-chdir.exp --replace "File name" "Filename" + '' + + + # this test doesn't give a permissions warning on cygwin + # TODO: find out why + lib.optionalString stdenv.hostPlatform.isCygwin '' + sed -i unit-tests/Makefile \ + -e '/objdir-writable/d' + ''; buildPhase = '' runHook preBuild From 189c6f1780c96be582e715ea2dd88d6fa4ea5b3e Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 6 Nov 2025 14:58:50 -0400 Subject: [PATCH 076/119] HACK: undo changes causing rebuilds --- pkgs/by-name/op/opensp/package.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/by-name/op/opensp/package.nix b/pkgs/by-name/op/opensp/package.nix index c1f91b9552749..85985fc81490e 100644 --- a/pkgs/by-name/op/opensp/package.nix +++ b/pkgs/by-name/op/opensp/package.nix @@ -49,6 +49,8 @@ stdenv.mkDerivation rec { sed -i -e 's/name="idm.*"//g' $out/share/doc/OpenSP/releasenotes.html ''; + preConfigure = ""; + strictDeps = true; nativeBuildInputs = [ From 1060da313efcc5ab8f9f2e078f677b9fed4e5434 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 7 Nov 2025 15:00:13 -0400 Subject: [PATCH 077/119] git: fix cygwin build --- pkgs/by-name/gi/git/package.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/by-name/gi/git/package.nix b/pkgs/by-name/gi/git/package.nix index a1bc5aca526c3..0462747005a32 100644 --- a/pkgs/by-name/gi/git/package.nix +++ b/pkgs/by-name/gi/git/package.nix @@ -559,6 +559,11 @@ stdenv.mkDerivation (finalAttrs: { # Fails largely due to assumptions about BOM # Tested to fail: 2.18.0 disable_test t0028-working-tree-encoding + '' + + lib.optionalString stdenv.hostPlatform.isCygwin '' + disable_test t0006-date + disable_test t0610-reftable-basics + disable_test t6137-pathspec-wildcards-literal ''; stripDebugList = [ From d9f6ad8febfbdcbb79332cdf4faba3a8c3b8077c Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 9 Nov 2025 14:05:35 -0400 Subject: [PATCH 078/119] gcc: enable threads on cygwin --- pkgs/development/compilers/gcc/common/configure-flags.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/compilers/gcc/common/configure-flags.nix b/pkgs/development/compilers/gcc/common/configure-flags.nix index 15e5b8133cdd0..b112db0beea3c 100644 --- a/pkgs/development/compilers/gcc/common/configure-flags.nix +++ b/pkgs/development/compilers/gcc/common/configure-flags.nix @@ -298,6 +298,9 @@ let # Workaround build failures like: # cc1: error: fp software completion requires '-mtrap-precision=i' [-Werror] "--disable-werror" + ] + ++ lib.optionals targetPlatform.isCygwin [ + "--enable-threads" ]; in From 206fac70d76ed6ce17b954d62e03c9cc9dcfef4b Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 10 Nov 2025 10:14:12 -0400 Subject: [PATCH 079/119] git: disable tests by default on cygwin --- pkgs/by-name/gi/git/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/gi/git/package.nix b/pkgs/by-name/gi/git/package.nix index 0462747005a32..7473ba7416e21 100644 --- a/pkgs/by-name/gi/git/package.nix +++ b/pkgs/by-name/gi/git/package.nix @@ -49,7 +49,7 @@ withSsh ? false, sysctl, deterministic-host-uname, # trick Makefile into targeting the host platform when cross-compiling - doInstallCheck ? !stdenv.hostPlatform.isDarwin, # extremely slow on darwin + doInstallCheck ? !stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isCygwin, # extremely slow on darwin and cygwin tests, rustSupport ? false, cargo, From 9509da1b2b5d76ede838d479e9221252119ecad8 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 10 Nov 2025 10:43:22 -0400 Subject: [PATCH 080/119] ld-wrapper: add hook to check for --high-entropy-va on cygwin --- .../bintools-wrapper/cygwin-ld-wrapper-hook.sh | 8 ++++++++ pkgs/build-support/bintools-wrapper/default.nix | 4 ++++ 2 files changed, 12 insertions(+) create mode 100644 pkgs/build-support/bintools-wrapper/cygwin-ld-wrapper-hook.sh diff --git a/pkgs/build-support/bintools-wrapper/cygwin-ld-wrapper-hook.sh b/pkgs/build-support/bintools-wrapper/cygwin-ld-wrapper-hook.sh new file mode 100644 index 0000000000000..8587b93cdd726 --- /dev/null +++ b/pkgs/build-support/bintools-wrapper/cygwin-ld-wrapper-hook.sh @@ -0,0 +1,8 @@ +for x in ${extraBefore+"${extraBefore[@]}"} \ + ${params+"${params[@]}"} \ + ${extraAfter+"${extraAfter[@]}"}; do + if [[ $x == --high-entropy-va ]]; then + echo "ld-wrapper: --high-entropy-va will cause instability on cygwin" >&2 + exit 1 + fi +done diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 36b121378be4a..984d5eb3a34d7 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -385,6 +385,10 @@ stdenvNoCC.mkDerivation { hardening_unsupported_flags+=" relro bindnow" '' + + optionalString targetPlatform.isCygwin '' + cp ${./cygwin-ld-wrapper-hook.sh} $out/nix-support/ld-wrapper-hook + '' + + optionalString (libc != null && targetPlatform.isAvr) '' for isa in avr5 avr3 avr4 avr6 avr25 avr31 avr35 avr51 avrxmega2 avrxmega4 avrxmega5 avrxmega6 avrxmega7 tiny-stack; do echo "-L${getLib libc}/avr/lib/$isa" >> $out/nix-support/libc-cflags From d8842baf3e3103f7c6a91dc50540afa5df06d011 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 10 Nov 2025 20:24:24 -0400 Subject: [PATCH 081/119] HACK: nix: disable tests on cygwin --- .../package-management/nix/modular/packaging/everything.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/tools/package-management/nix/modular/packaging/everything.nix b/pkgs/tools/package-management/nix/modular/packaging/everything.nix index b93c0c1a99995..f37bbc87eab1d 100644 --- a/pkgs/tools/package-management/nix/modular/packaging/everything.nix +++ b/pkgs/tools/package-management/nix/modular/packaging/everything.nix @@ -145,9 +145,9 @@ stdenv.mkDerivation (finalAttrs: { nix-fetchers-tests.tests.run nix-flake-tests.tests.run - # Make sure the functional tests have passed - nix-functional-tests ] + # Make sure the functional tests have passed + ++ lib.optional (!stdenv.buildPlatform.isCygwin) nix-functional-tests ++ lib.optionals (!stdenv.hostPlatform.isStatic && stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ From ca84ceb00451ef8466198e73be08e19a49535c57 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 10 Nov 2025 21:39:46 -0400 Subject: [PATCH 082/119] cmocka: fix cygwin build --- pkgs/by-name/cm/cmocka/fix-cygwin-build.patch | 59 +++++++++++++++++++ pkgs/by-name/cm/cmocka/package.nix | 3 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 pkgs/by-name/cm/cmocka/fix-cygwin-build.patch diff --git a/pkgs/by-name/cm/cmocka/fix-cygwin-build.patch b/pkgs/by-name/cm/cmocka/fix-cygwin-build.patch new file mode 100644 index 0000000000000..5e88d13b9c8d2 --- /dev/null +++ b/pkgs/by-name/cm/cmocka/fix-cygwin-build.patch @@ -0,0 +1,59 @@ +diff --git a/cmake/Modules/AddCMockaTest.cmake b/cmake/Modules/AddCMockaTest.cmake +index 12fbd79..c619639 100644 +--- a/cmake/Modules/AddCMockaTest.cmake ++++ b/cmake/Modules/AddCMockaTest.cmake +@@ -123,17 +123,21 @@ function(ADD_CMOCKA_TEST_ENVIRONMENT _TARGET_NAME) + if (WIN32 OR CYGWIN OR MINGW OR MSVC) + file(TO_NATIVE_PATH "${cmocka-library_BINARY_DIR}" CMOCKA_DLL_PATH) + +- if (TARGET_SYSTEM_EMULATOR) +- set(DLL_PATH_ENV "WINEPATH=${CMOCKA_DLL_PATH};$ENV{WINEPATH}") ++ if (CYGWIN) ++ set(DLL_PATH_ENV "PATH=${CMOCKA_DLL_PATH}:$ENV{PATH}") + else() +- set(DLL_PATH_ENV "PATH=${CMOCKA_DLL_PATH}\\${CMAKE_BUILD_TYPE};$ENV{PATH}") ++ if (TARGET_SYSTEM_EMULATOR) ++ set(DLL_PATH_ENV "WINEPATH=${CMOCKA_DLL_PATH};$ENV{WINEPATH}") ++ else() ++ set(DLL_PATH_ENV "PATH=${CMOCKA_DLL_PATH}\\${CMAKE_BUILD_TYPE};$ENV{PATH}") ++ endif() ++ # ++ # IMPORTANT NOTE: The set_tests_properties(), below, internally ++ # stores its name/value pairs with a semicolon delimiter. ++ # because of this we must protect the semicolons in the path ++ # ++ string(REPLACE ";" "\\;" DLL_PATH_ENV "${DLL_PATH_ENV}") + endif() +- # +- # IMPORTANT NOTE: The set_tests_properties(), below, internally +- # stores its name/value pairs with a semicolon delimiter. +- # because of this we must protect the semicolons in the path +- # +- string(REPLACE ";" "\\;" DLL_PATH_ENV "${DLL_PATH_ENV}") + + set_tests_properties(${_TARGET_NAME} + PROPERTIES +diff --git a/example/mock/chef_wrap/CMakeLists.txt b/example/mock/chef_wrap/CMakeLists.txt +index 205ccd4..0b8b98d 100644 +--- a/example/mock/chef_wrap/CMakeLists.txt ++++ b/example/mock/chef_wrap/CMakeLists.txt +@@ -15,6 +15,4 @@ set_target_properties(waiter_test_wrap + PROPERTIES + LINK_FLAGS "-Wl,--wrap=chef_cook" + ) +-if (WIN32 OR MINGW OR CYGWIN) +- set_tests_properties(waiter_test_wrap PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") +-endif (WIN32 OR MINGW OR CYGWIN) ++add_cmocka_test_environment(waiter_test_wrap) +diff --git a/example/mock/uptime/CMakeLists.txt b/example/mock/uptime/CMakeLists.txt +index 967185f..8e047e3 100644 +--- a/example/mock/uptime/CMakeLists.txt ++++ b/example/mock/uptime/CMakeLists.txt +@@ -13,6 +13,7 @@ add_cmocka_test(test_uptime + SOURCES test_uptime.c + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_LIBRARIES cmocka::cmocka) ++add_cmocka_test_environment(test_uptime) + set_property(TARGET + test_uptime + PROPERTY diff --git a/pkgs/by-name/cm/cmocka/package.nix b/pkgs/by-name/cm/cmocka/package.nix index baeea60c9fcad..1b8772fb7fe8b 100644 --- a/pkgs/by-name/cm/cmocka/package.nix +++ b/pkgs/by-name/cm/cmocka/package.nix @@ -16,7 +16,8 @@ stdenv.mkDerivation rec { patches = [ ./uintptr_t.patch - ]; + ] + ++ lib.optional stdenv.hostPlatform.isCygwin ./fix-cygwin-build.patch; nativeBuildInputs = [ cmake ]; From fb48947778b17ad393f82d3e628b5702ff1bb9a5 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 10 Nov 2025 22:15:45 -0400 Subject: [PATCH 083/119] libcbor: fix cygwin build --- pkgs/by-name/li/libcbor/package.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/li/libcbor/package.nix b/pkgs/by-name/li/libcbor/package.nix index c2445e7d8965e..bdfe9c20c3c8b 100644 --- a/pkgs/by-name/li/libcbor/package.nix +++ b/pkgs/by-name/li/libcbor/package.nix @@ -45,7 +45,11 @@ stdenv.mkDerivation (finalAttrs: { # Tests are restricted while pkgsStatic.cmocka is broken. Tracked at: # https://github.com/NixOS/nixpkgs/issues/213623 - doCheck = !stdenv.hostPlatform.isStatic && stdenv.hostPlatform == stdenv.buildPlatform; + doCheck = + !stdenv.hostPlatform.isStatic + && stdenv.hostPlatform == stdenv.buildPlatform + # cygwin tests fail to link + && !stdenv.hostPlatform.isCygwin; nativeCheckInputs = [ cmocka ]; From 65a52c1d590fc10fc6bab966a3e9e4d373530090 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 10 Nov 2025 22:50:09 -0400 Subject: [PATCH 084/119] cocom-tool-set: fix cygwin build --- pkgs/by-name/co/cocom-tool-set/package.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/by-name/co/cocom-tool-set/package.nix b/pkgs/by-name/co/cocom-tool-set/package.nix index 9ab545e01c4ff..0be3f3b9dd570 100644 --- a/pkgs/by-name/co/cocom-tool-set/package.nix +++ b/pkgs/by-name/co/cocom-tool-set/package.nix @@ -23,6 +23,10 @@ stdenv.mkDerivation (finalAttrs: { ]; }; + # cocom does $(DESTDIR)/$(libdir) which results in //nix/store/... + # on cygwin this is interpreted as a network path. + installFlags = lib.optionalString stdenv.buildPlatform.isCygwin "DESTDIR=/."; + autoreconfFlags = "REGEX"; strictDeps = true; From 5554f416e7d561eeedacba0de83a37478f4970e9 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 10 Nov 2025 23:00:53 -0400 Subject: [PATCH 085/119] HACK: undo changes causing rebuilds --- pkgs/by-name/co/cocom-tool-set/package.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/co/cocom-tool-set/package.nix b/pkgs/by-name/co/cocom-tool-set/package.nix index 0be3f3b9dd570..85ed5eebd7369 100644 --- a/pkgs/by-name/co/cocom-tool-set/package.nix +++ b/pkgs/by-name/co/cocom-tool-set/package.nix @@ -25,7 +25,8 @@ stdenv.mkDerivation (finalAttrs: { # cocom does $(DESTDIR)/$(libdir) which results in //nix/store/... # on cygwin this is interpreted as a network path. - installFlags = lib.optionalString stdenv.buildPlatform.isCygwin "DESTDIR=/."; + ${if stdenv.buildPlatform.isCygwin then "installFlags" else null} = + lib.optionalString stdenv.buildPlatform.isCygwin "DESTDIR=/."; autoreconfFlags = "REGEX"; From c56e88ed88ef57158dbaeb28b4ff5b49b17fd349 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 10 Nov 2025 23:53:46 -0400 Subject: [PATCH 086/119] cygwin.newlib-cygwin: fix cygwin build --- pkgs/os-specific/cygwin/newlib-cygwin/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix index 22296637442ea..d7234e7416ccd 100644 --- a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix +++ b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix @@ -138,6 +138,9 @@ in perl ]; + # -lintl from gettext breaks link on cygwin + dontAddExtraLibs = stdenv.buildPlatform.isCygwin; + buildInputs = [ w32api ]; makeFlags = [ From c125dfb1ffd2e916365a62dda6bd6c5125fa5946 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 10 Nov 2025 23:54:44 -0400 Subject: [PATCH 087/119] HACK: undo changes causing rebuilds --- pkgs/os-specific/cygwin/newlib-cygwin/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix index d7234e7416ccd..1ae0f9fbad01f 100644 --- a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix +++ b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix @@ -139,7 +139,8 @@ in ]; # -lintl from gettext breaks link on cygwin - dontAddExtraLibs = stdenv.buildPlatform.isCygwin; + ${if stdenv.buildPlatform.isCygwin then "dontAddExtraLibs" else null} = + stdenv.buildPlatform.isCygwin; buildInputs = [ w32api ]; From 049e54152e34d42d6c029b34b8608ef401ce0b24 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 11 Nov 2025 10:14:44 -0400 Subject: [PATCH 088/119] HACK: add check-cygwin script --- check-cygwin | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 check-cygwin diff --git a/check-cygwin b/check-cygwin new file mode 100755 index 0000000000000..818e0f5175c21 --- /dev/null +++ b/check-cygwin @@ -0,0 +1,14 @@ +#!/bin/sh +set -eo pipefail +echo BAD: +nix derivation show -r .#cygwinSystem.config.system.build.tarball.stdenvDeps \ + | jq -r 'map_values(select(.system == "x86_64-cygwin")) | keys_unsorted .[]' + +nix derivation show -r -f. --argstr system x86_64-cygwin nix \ + | jq -r 'map_values(select(.system == "x86_64-linux")) | keys_unsorted .[]' \ + | sort > target +nix derivation show -r .#cygwinSystem.config.system.build.tarball.stdenvDeps \ + | jq -r 'map_values(select(.system == "x86_64-linux")) | keys_unsorted .[]' \ + | sort > bootstrap +echo MISSING: +comm -13 bootstrap target From ac2fdb5888b04ca174e92c344ddd32a0f3c0836b Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 11 Nov 2025 12:40:17 -0400 Subject: [PATCH 089/119] bintools-wrapper: fix unsupported hardening on cygwin --- pkgs/build-support/bintools-wrapper/default.nix | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pkgs/build-support/bintools-wrapper/default.nix b/pkgs/build-support/bintools-wrapper/default.nix index 984d5eb3a34d7..3f87960fce50f 100644 --- a/pkgs/build-support/bintools-wrapper/default.nix +++ b/pkgs/build-support/bintools-wrapper/default.nix @@ -377,11 +377,7 @@ stdenvNoCC.mkDerivation { fi '' - + optionalString hostPlatform.isCygwin '' - hardening_unsupported_flags+=" pic" - '' - - + optionalString (targetPlatform.isAvr || targetPlatform.isWindows) '' + + optionalString (targetPlatform.isAvr || targetPlatform.isWindows || targetPlatform.isCygwin) '' hardening_unsupported_flags+=" relro bindnow" '' From b50f76797091765abb4d0f9028376c125d6e1ad1 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 11 Nov 2025 12:40:54 -0400 Subject: [PATCH 090/119] stdenv/cygwin: init cross-based stdenv --- pkgs/stdenv/cygwin/default.nix | 134 +++++++++++++++++++++++++++++++++ pkgs/stdenv/default.nix | 4 +- 2 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 pkgs/stdenv/cygwin/default.nix diff --git a/pkgs/stdenv/cygwin/default.nix b/pkgs/stdenv/cygwin/default.nix new file mode 100644 index 0000000000000..08ae179438db6 --- /dev/null +++ b/pkgs/stdenv/cygwin/default.nix @@ -0,0 +1,134 @@ +{ + lib, + localSystem, + crossSystem, + config, + overlays, + crossOverlays ? [ ], +}: + +assert crossSystem == localSystem; +let + bootStages = import ../. { + inherit lib overlays; + + localSystem = lib.systems.elaborate "x86_64-linux"; + + crossSystem = localSystem; + crossOverlays = [ ]; + + # Ignore custom stdenvs when cross compiling for compatibility + # Use replaceCrossStdenv instead. + config = builtins.removeAttrs config [ "replaceStdenv" ]; + }; + +in +bootStages +++ [ + + ( + prevStage: + let + name = "cygwin"; + + initialPath = + ((import ../generic/common-path.nix) { pkgs = prevStage; }) + # needed for cygwin1.dll + ++ [ "/" ]; + + shell = "${prevStage.bashNonInteractive}/bin/bash"; + + stdenvNoCC = import ../generic { + inherit + config + initialPath + shell + fetchurlBoot + ; + name = "stdenvNoCC-${name}"; + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; + cc = null; + }; + + fetchurlBoot = import ../../build-support/fetchurl { + inherit lib stdenvNoCC; + inherit (prevStage) curl; + inherit (config) rewriteURL hashedMirrors; + }; + + gcc = ( + prevStage.gccFun { + noSysDirs = true; + majorMinorVersion = toString prevStage.default-gcc-version; + targetPackages.stdenv.cc.bintools = prevStage.stdenv.cc.bintools; + } + ); + + in + { + inherit config overlays stdenvNoCC; + stdenv = import ../generic rec { + name = "stdenv-cygwin"; + + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; + inherit + config + initialPath + fetchurlBoot + shell + ; + + cc = lib.makeOverridable (import ../../build-support/cc-wrapper) { + inherit lib stdenvNoCC; + name = "${name}-cc"; + cc = gcc; + isGNU = true; + libc = prevStage.cygwin.newlib-cygwin; + inherit (prevStage) gnugrep coreutils expand-response-params; + nativeTools = false; + nativeLibc = false; + propagateDoc = false; + runtimeShell = shell; + bintools = lib.makeOverridable (import ../../build-support/bintools-wrapper) { + inherit lib stdenvNoCC; + name = "${name}-bintools"; + bintools = prevStage.bintools-unwrapped; + libc = prevStage.cygwin.newlib-cygwin; + inherit (prevStage) gnugrep coreutils expand-response-params; + nativeTools = false; + nativeLibc = false; + propagateDoc = false; + runtimeShell = shell; + }; + }; + + overrides = self: super: { + fetchurl = lib.makeOverridable fetchurlBoot; + __bootstrapPackages = + (import ../generic/common-path.nix) { pkgs = prevStage; } + ++ [ + gcc + gcc.lib + ] + ++ (with prevStage; [ + curl + curl.dev + cygwin.newlib-cygwin + cygwin.newlib-cygwin.bin + cygwin.newlib-cygwin.dev + cygwin.w32api + cygwin.w32api.dev + bintools-unwrapped + gnugrep + coreutils + expand-response-params + ]); + }; + }; + } + ) +] diff --git a/pkgs/stdenv/default.nix b/pkgs/stdenv/default.nix index 3cbe274a2f0e8..80004c25ebdfb 100644 --- a/pkgs/stdenv/default.nix +++ b/pkgs/stdenv/default.nix @@ -50,13 +50,13 @@ else if localSystem.isLinux then stagesLinux else if localSystem.isDarwin then stagesDarwin +else if localSystem.isCygwin then + (import ./cygwin args) # misc special cases else { # switch x86_64-solaris = stagesNix; - i686-cygwin = stagesNative; - x86_64-cygwin = stagesNative; x86_64-freebsd = stagesFreeBSD; } .${localSystem.system} or stagesNative From b61f4fa24cefc89e1d66b86c262f4ff329f9ec40 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 11 Nov 2025 13:37:23 -0400 Subject: [PATCH 091/119] libev: fix cygwin build --- pkgs/by-name/li/libev/package.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/li/libev/package.nix b/pkgs/by-name/li/libev/package.nix index 86462cc5380f8..deeb6333ed6e1 100644 --- a/pkgs/by-name/li/libev/package.nix +++ b/pkgs/by-name/li/libev/package.nix @@ -5,7 +5,8 @@ fetchpatch, updateAutotoolsGnuConfigScriptsHook, # Note: -static hasn’t work on darwin - static ? with stdenv.hostPlatform; isStatic && !isDarwin, + # cygwin requires libtool -no-undefined for shared + static ? with stdenv.hostPlatform; (isStatic && !isDarwin) || isCygwin, }: # Note: this package is used for bootstrapping fetchurl, and thus From edac4bc75b697e2168ea0e777a3f4b8eb414c9be Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 13 Nov 2025 16:04:26 -0400 Subject: [PATCH 092/119] perlPackages.Test2Harness: disable checks on cygwin --- pkgs/top-level/perl-packages.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/top-level/perl-packages.nix b/pkgs/top-level/perl-packages.nix index d80eff9222716..46957c2f3bdee 100644 --- a/pkgs/top-level/perl-packages.nix +++ b/pkgs/top-level/perl-packages.nix @@ -33244,7 +33244,8 @@ with self; # The t/integration/preload.t test is broken on riscv64 # https://github.com/Test-More/Test2-Harness/issues/290 - doCheck = !stdenv.hostPlatform.isRiscV; + # There seems to be a similar failure on cygwin + doCheck = !stdenv.hostPlatform.isRiscV && !stdenv.buildPlatform.isCygwin; propagatedBuildInputs = [ DataUUID From eb85f9a42451f81481c549c267b4b5077212ef7d Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 14 Nov 2025 10:03:20 -0400 Subject: [PATCH 093/119] doctest: fix cygwin build --- pkgs/by-name/do/doctest/package.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/do/doctest/package.nix b/pkgs/by-name/do/doctest/package.nix index 6eae43308fbfb..6aa3bdc8b3b4a 100644 --- a/pkgs/by-name/do/doctest/package.nix +++ b/pkgs/by-name/do/doctest/package.nix @@ -25,7 +25,12 @@ stdenv.mkDerivation rec { excludes = [ ".github/workflows/main.yml" ]; hash = "sha256-kOBy0om6MPM2vLXZjNLXiezZqVgNr/viBI7mXrOZts8="; }) - ]; + ] + ++ lib.optional stdenv.hostPlatform.isCygwin (fetchpatch { + name = "doctest-fix-cygwin-tests.patch"; + url = "https://github.com/doctest/doctest/commit/0e174a246558a8f5ef7299a3fd870c30281fd8d1.patch"; + hash = "sha256-M7ByNFHCUb0ahsfNr4oUGTbR45qfdS9d5N8bGdQl/+Q="; + }); nativeBuildInputs = [ cmake ]; From e0700a1a58507b33e2f506a907b2096961f0f9bf Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 14 Nov 2025 13:57:35 -0400 Subject: [PATCH 094/119] vim: fix cygwin build --- pkgs/applications/editors/vim/default.nix | 32 ++++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/pkgs/applications/editors/vim/default.nix b/pkgs/applications/editors/vim/default.nix index 809e9808b1bee..d10513080d252 100644 --- a/pkgs/applications/editors/vim/default.nix +++ b/pkgs/applications/editors/vim/default.nix @@ -78,20 +78,26 @@ stdenv.mkDerivation { substituteInPlace src/which.sh --replace '$PATH' '$HOST_PATH' ''; - postInstall = '' - ln -s $out/bin/vim $out/bin/vi - mkdir -p $out/share/vim - cp "${vimrc}" $out/share/vim/vimrc + postInstall = + let + exeSuffix = stdenv.hostPlatform.extensions.executable; + in + '' + ln -s $out/bin/vim${exeSuffix} $out/bin/vi + mkdir -p $out/share/vim + cp "${vimrc}" $out/share/vim/vimrc - # Prevent bugs in the upstream makefile from silently failing and missing outputs. - # Some of those are build-time requirements for other packages. - for tool in ex xxd vi view vimdiff; do - if [ ! -e "$out/bin/$tool" ]; then - echo "ERROR: install phase did not install '$tool'." - exit 1 - fi - done - ''; + # Prevent bugs in the upstream makefile from silently failing and missing outputs. + # Some of those are build-time requirements for other packages. + for tool in ex xxd${exeSuffix} vi view vimdiff; do + if [ ! -e "$out/bin/$tool" ]; then + echo "ERROR: install phase did not install '$tool'." + exit 1 + fi + done + ''; + + allowedImpureDLLs = [ "USER32.dll" ]; __impureHostDeps = [ "/dev/ptmx" ]; } From 5f9b03e886743c6336bd30011cdb10568ff71fa2 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 14 Nov 2025 16:21:13 -0400 Subject: [PATCH 095/119] toml11: fix cygwin build --- pkgs/by-name/to/toml11/package.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/to/toml11/package.nix b/pkgs/by-name/to/toml11/package.nix index dd5924edd489b..5527949ee13ca 100644 --- a/pkgs/by-name/to/toml11/package.nix +++ b/pkgs/by-name/to/toml11/package.nix @@ -38,7 +38,11 @@ stdenv.mkDerivation (finalAttrs: { ]; cmakeFlags = [ (lib.cmakeBool "TOML11_BUILD_TOML_TESTS" finalAttrs.finalPackage.doCheck) - ]; + ] + ++ lib.optional stdenv.hostPlatform.isCygwin ( + lib.cmakeFeature "CMAKE_CXX_FLAGS" "-D_POSIX_C_SOURCE=200809L" + ); + checkInputs = [ doctest nlohmann_json From fa7eec4821fea893b6ee1bb3d3fd04eec34e902c Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 14 Nov 2025 22:14:40 -0400 Subject: [PATCH 096/119] nixVersions.nixComponents_2_31.nix-expr-tests: fix cygwin test --- .../nix/modular/src/libexpr-tests/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/package-management/nix/modular/src/libexpr-tests/package.nix b/pkgs/tools/package-management/nix/modular/src/libexpr-tests/package.nix index 1d5c729287788..02809a64588a5 100644 --- a/pkgs/tools/package-management/nix/modular/src/libexpr-tests/package.nix +++ b/pkgs/tools/package-management/nix/modular/src/libexpr-tests/package.nix @@ -43,7 +43,7 @@ mkMesonExecutable (finalAttrs: { meta.broken = !stdenv.hostPlatform.emulatorAvailable buildPackages; } ( - lib.optionalString stdenv.hostPlatform.isWindows '' + lib.optionalString (stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isCygwin) '' export HOME="$PWD/home-dir" mkdir -p "$HOME" '' From 34a0e5add37be556be3e350d51e89f1d32079929 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Wed, 12 Nov 2025 13:57:42 -0400 Subject: [PATCH 097/119] WIP: add cygwin workflow --- .github/workflows/cygwin.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/cygwin.yml diff --git a/.github/workflows/cygwin.yml b/.github/workflows/cygwin.yml new file mode 100644 index 0000000000000..869045b4e0b8f --- /dev/null +++ b/.github/workflows/cygwin.yml @@ -0,0 +1,28 @@ +name: cygwin +on: + push: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - run: nix build .#cygwinSystem.config.system.build.tarball + - uses: actions/upload-artifact@v4 + with: + name: tarball + path: result + test: + runs-on: windows-latest + needs: build + steps: + - uses: actions/download-artifact@v4 + with: + name: tarball + - run: tarball/install.ps1 cygwin + - run: cygwin/cygwin.ps1 -c 'nix build --no-sandbox nixpkgs#cygwinSystem.config.system.build.tarball' + - uses: actions/upload-artifact@v4 + with: + name: tarball + path: result From c6ce3fdfd95c74e20f7e851c44ee6dc107f4e94b Mon Sep 17 00:00:00 2001 From: David McFarland Date: Fri, 28 Nov 2025 14:21:07 -0400 Subject: [PATCH 098/119] HACK: wip --- .github/workflows/cygwin.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cygwin.yml b/.github/workflows/cygwin.yml index 869045b4e0b8f..96ecdc1f4f406 100644 --- a/.github/workflows/cygwin.yml +++ b/.github/workflows/cygwin.yml @@ -8,7 +8,8 @@ jobs: - uses: actions/checkout@v5 - uses: DeterminateSystems/nix-installer-action@main - uses: DeterminateSystems/magic-nix-cache-action@main - - run: nix build .#cygwinSystem.config.system.build.tarball + - name: build + run: nix build .#cygwinSystem.config.system.build.tarball - uses: actions/upload-artifact@v4 with: name: tarball @@ -20,9 +21,12 @@ jobs: - uses: actions/download-artifact@v4 with: name: tarball - - run: tarball/install.ps1 cygwin - - run: cygwin/cygwin.ps1 -c 'nix build --no-sandbox nixpkgs#cygwinSystem.config.system.build.tarball' - - uses: actions/upload-artifact@v4 - with: - name: tarball - path: result + - name: install + run: tarball/install.ps1 cygwin + - name: build + shell: cygwin/cygwin.ps1 {0} + run: nix build --no-sandbox nixpkgs#hello + # - uses: actions/upload-artifact@v4 + # with: + # name: tarball + # path: result From 2d001642702a560509504bf60901d8c170d559c8 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 1 Dec 2025 20:34:25 -0400 Subject: [PATCH 099/119] WIP: add hydra VM --- hydra/flake.lock | 25 ++++++++++++++++++++++++ hydra/flake.nix | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 hydra/flake.lock create mode 100644 hydra/flake.nix diff --git a/hydra/flake.lock b/hydra/flake.lock new file mode 100644 index 0000000000000..b1c86ff778843 --- /dev/null +++ b/hydra/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1764587062, + "narHash": "sha256-hdFa0TAVQAQLDF31cEW3enWmBP+b592OvHs6WVe3D8k=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c1cb7d097cb250f6e1904aacd5f2ba5ffd8a49ce", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/hydra/flake.nix b/hydra/flake.nix new file mode 100644 index 0000000000000..1327ee59199c1 --- /dev/null +++ b/hydra/flake.nix @@ -0,0 +1,49 @@ +{ + outputs = + { nixpkgs, ... }: + { + nixosConfigurations.container = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + { + boot.isNspawnContainer = true; + + services.hydra = { + enable = true; + hydraURL = "http://localhost:3000"; + notificationSender = "hydra@localhost"; + useSubstitutes = true; + }; + + networking.firewall.allowedTCPPorts = [ 3000 ]; + networking.useHostResolvConf = nixpkgs.lib.mkForce false; + networking.nameservers = [ "8.8.8.8" ]; + + programs.ssh.extraConfig = nixpkgs.lib.mkAfter '' + Host cygwin-vm + User Quickemu + HostName 10.233.1.1 + Port = 22220 + ''; + + services.openssh = { + knownHosts = { + cygwin-vm = { + hostNames = [ "[10.233.1.1]:22220" ]; + publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJGc5UkkNeYGjBLpgvdZZ8GeW8QtZsvC9IuTMNzLJ/N"; + }; + }; + }; + + nix.distributedBuilds = true; + nix.buildMachines = [ + { + hostName = "cygwin-vm"; + system = "x86_64-cygwin"; + } + ]; + } + ]; + }; + }; +} From aa2d3208cf84f562f277ee36eb787e3ebcc65240 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 11 Dec 2025 14:45:10 -0400 Subject: [PATCH 100/119] lowdown: move dlls to bin/ --- pkgs/by-name/lo/lowdown/package.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/by-name/lo/lowdown/package.nix b/pkgs/by-name/lo/lowdown/package.nix index 684ca14b0cd9a..d74416a0cba6e 100644 --- a/pkgs/by-name/lo/lowdown/package.nix +++ b/pkgs/by-name/lo/lowdown/package.nix @@ -92,6 +92,12 @@ stdenv.mkDerivation rec { "install_static" ]; + postInstall = lib.optionalString stdenv.hostPlatform.isCygwin '' + mkdir -p "$lib"/bin + mv "$lib"/lib/*.dll "$lib"/bin/ + chmod +x "$lib"/bin/*.dll + ''; + doInstallCheck = !stdenv.hostPlatform.isDarwin || !enableDarwinSandbox; installCheckPhase = '' runHook preInstallCheck From fee0530954d0e980ffc682fa1bd441c0460d355e Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 11 Dec 2025 14:45:43 -0400 Subject: [PATCH 101/119] treewide: undo changes causing rebuilds --- pkgs/by-name/lo/lowdown/package.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkgs/by-name/lo/lowdown/package.nix b/pkgs/by-name/lo/lowdown/package.nix index d74416a0cba6e..07842dd4fcae1 100644 --- a/pkgs/by-name/lo/lowdown/package.nix +++ b/pkgs/by-name/lo/lowdown/package.nix @@ -92,11 +92,15 @@ stdenv.mkDerivation rec { "install_static" ]; - postInstall = lib.optionalString stdenv.hostPlatform.isCygwin '' - mkdir -p "$lib"/bin - mv "$lib"/lib/*.dll "$lib"/bin/ - chmod +x "$lib"/bin/*.dll - ''; + postInstall = + if stdenv.hostPlatform.isCygwin then + '' + mkdir -p "$lib"/bin + mv "$lib"/lib/*.dll "$lib"/bin/ + chmod +x "$lib"/bin/*.dll + '' + else + null; doInstallCheck = !stdenv.hostPlatform.isDarwin || !enableDarwinSandbox; installCheckPhase = '' From 23a0c244b2d431a09e7a9699d5023f98df7774b1 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 14 Dec 2025 21:28:54 -0400 Subject: [PATCH 102/119] newlib-cygwin: add patch to fix POLLHUP --- .../cygwin/newlib-cygwin/default.nix | 2 + ...ng-POLLHUP-when-write-pipe-is-closed.patch | 90 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 pkgs/os-specific/cygwin/newlib-cygwin/fix-missing-POLLHUP-when-write-pipe-is-closed.patch diff --git a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix index 1ae0f9fbad01f..c4238b2d033a7 100644 --- a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix +++ b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix @@ -65,6 +65,8 @@ in # where nix runs on cygwin, we can attempt to upstream this again. ./store-tls-pointer-in-win32-tls.patch ./Cygwin-only-use-native-symlinks-when-they-preserve-t.patch + # This fixes the nix libutil MonitorFdHup.shouldNotBlock test + ./fix-missing-POLLHUP-when-write-pipe-is-closed.patch ] # After cygwin hosted builds are working, we should upstream this ++ lib.optional ( diff --git a/pkgs/os-specific/cygwin/newlib-cygwin/fix-missing-POLLHUP-when-write-pipe-is-closed.patch b/pkgs/os-specific/cygwin/newlib-cygwin/fix-missing-POLLHUP-when-write-pipe-is-closed.patch new file mode 100644 index 0000000000000..c23b623c2a9b5 --- /dev/null +++ b/pkgs/os-specific/cygwin/newlib-cygwin/fix-missing-POLLHUP-when-write-pipe-is-closed.patch @@ -0,0 +1,90 @@ +diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h +index bdd87ebb7..3c505e545 100644 +--- a/winsup/cygwin/local_includes/fhandler.h ++++ b/winsup/cygwin/local_includes/fhandler.h +@@ -456,6 +456,7 @@ public: + virtual class fhandler_timerfd *is_timerfd () { return NULL; } + virtual class fhandler_mqueue *is_mqueue () { return NULL; } + virtual int is_windows () {return 0; } ++ virtual bool is_hung_up () { return false; } + + virtual void raw_read (void *ptr, size_t& ulen); + virtual ssize_t raw_write (const void *ptr, size_t ulen); +@@ -723,6 +724,8 @@ class fhandler_socket_wsock: public fhandler_socket + + fhandler_socket_wsock *is_wsock_socket () { return this; } + ++ bool is_hung_up () { return saw_shutdown_read(); } ++ + ssize_t recvfrom (void *ptr, size_t len, int flags, + struct sockaddr *from, int *fromlen); + ssize_t recvmsg (struct msghdr *msg, int flags); +@@ -1221,12 +1224,15 @@ class fhandler_pipe: public fhandler_pipe_fifo + { + private: + pid_t popen_pid; ++ bool hung_up = false; + void release_select_sem (const char *); + public: + fhandler_pipe (); + + bool ispipe() const { return true; } + void set_pipe_buf_size (); ++ bool is_hung_up () { return hung_up; } ++ void set_hung_up () { hung_up = true; } + + void set_popen_pid (pid_t pid) {popen_pid = pid;} + pid_t get_popen_pid () const {return popen_pid;} +diff --git a/winsup/cygwin/poll.cc b/winsup/cygwin/poll.cc +index a67507bbd..039958b1e 100644 +--- a/winsup/cygwin/poll.cc ++++ b/winsup/cygwin/poll.cc +@@ -58,8 +58,7 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout) + FD_SET(fds[i].fd, read_fds); + if (fds[i].events & POLLOUT) + FD_SET(fds[i].fd, write_fds); +- if (fds[i].events & POLLPRI) +- FD_SET(fds[i].fd, except_fds); ++ FD_SET(fds[i].fd, except_fds); + } + else if (fds[i].fd >= 0) + { +@@ -99,9 +98,8 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout) + /* Check if the descriptor has been closed, or if shutdown for the + read side has been called on a socket. */ + if (cygheap->fdtab.not_open (fds[i].fd) +- || ((sock = cygheap->fdtab[fds[i].fd]->is_wsock_socket ()) +- && sock->saw_shutdown_read ())) +- fds[i].revents = POLLHUP; ++ || cygheap->fdtab[fds[i].fd]->is_hung_up()) ++ fds[i].revents |= POLLHUP; + else + { + if ((fds[i].events & POLLIN) && FD_ISSET(fds[i].fd, read_fds)) +diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc +index 8a94ac076..6830669b8 100644 +--- a/winsup/cygwin/select.cc ++++ b/winsup/cygwin/select.cc +@@ -749,6 +749,7 @@ peek_pipe (select_record *s, bool from_select) + if (n == PDA_ERROR) + { + select_printf ("read: %s, n %d", fh->get_name (), n); ++ ((fhandler_pipe *) fh)->set_hung_up (); + if (s->except_selected) + gotone += s->except_ready = true; + if (s->read_selected) +@@ -786,6 +787,14 @@ out: + if (n == PDA_ERROR && s->except_selected) + gotone += s->except_ready = true; + } ++ ++ if (!s->read_selected && dev == FH_PIPER) { ++ ssize_t n = pipe_data_available (s->fd, fh, h, PDA_READ); ++ if (n == PDA_ERROR) { ++ ((fhandler_pipe *) fh)->set_hung_up (); ++ gotone += s->except_ready = true; ++ } ++ } + return gotone; + } + From 71c9e2e1f12ba96acd7e1a4c327b078a3ae9ae5d Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 21 Dec 2025 21:08:51 -0400 Subject: [PATCH 103/119] cygwin: add bootstrap tools --- .../bootstrap-files/refresh-tarballs.bash | 2 + pkgs/stdenv/cygwin/default.nix | 10 ++ .../cygwin/make-bootstrap-tools-cross.nix | 30 ++++++ pkgs/stdenv/cygwin/make-bootstrap-tools.nix | 95 +++++++++++++++++++ pkgs/top-level/release-cross.nix | 9 +- 5 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 pkgs/stdenv/cygwin/make-bootstrap-tools-cross.nix create mode 100644 pkgs/stdenv/cygwin/make-bootstrap-tools.nix diff --git a/maintainers/scripts/bootstrap-files/refresh-tarballs.bash b/maintainers/scripts/bootstrap-files/refresh-tarballs.bash index 0fa2c28bb18a4..e50b0f01d10ce 100755 --- a/maintainers/scripts/bootstrap-files/refresh-tarballs.bash +++ b/maintainers/scripts/bootstrap-files/refresh-tarballs.bash @@ -99,6 +99,7 @@ CROSS_TARGETS=( s390x-unknown-linux-gnu x86_64-unknown-freebsd loongarch64-unknown-linux-gnu + x86_64-pc-cygwin ) is_cross() { @@ -168,6 +169,7 @@ for target in "${targets[@]}"; do *linux*) nixpkgs_prefix="pkgs/stdenv/linux" ;; *darwin*) nixpkgs_prefix="pkgs/stdenv/darwin" ;; *freebsd*) nixpkgs_prefix="pkgs/stdenv/freebsd" ;; + *cygwin*) nixpkgs_prefix="pkgs/stdenv/cygwin" ;; *) die "don't know where to put '$target'" ;; esac diff --git a/pkgs/stdenv/cygwin/default.nix b/pkgs/stdenv/cygwin/default.nix index 08ae179438db6..0652a6ad9b066 100644 --- a/pkgs/stdenv/cygwin/default.nix +++ b/pkgs/stdenv/cygwin/default.nix @@ -5,6 +5,16 @@ config, overlays, crossOverlays ? [ ], + bootstrapFiles ? + let + table = { + x86_64-cygwin = import ./bootstrap-files/x86_64-pc-cygwin.nix; + }; + files = + table.${localSystem.system} + or (throw "unsupported platform ${localSystem.system} for the cygwin stdenv"); + in + files, }: assert crossSystem == localSystem; diff --git a/pkgs/stdenv/cygwin/make-bootstrap-tools-cross.nix b/pkgs/stdenv/cygwin/make-bootstrap-tools-cross.nix new file mode 100644 index 0000000000000..c133be97d600c --- /dev/null +++ b/pkgs/stdenv/cygwin/make-bootstrap-tools-cross.nix @@ -0,0 +1,30 @@ +{ + system ? builtins.currentSystem, +}: + +let + inherit (releaseLib) lib; + releaseLib = import ../../top-level/release-lib.nix { + # We're not using any functions from release-lib.nix that look at + # supportedSystems. + supportedSystems = [ ]; + }; + + make = + crossSystem: + import ./make-bootstrap-tools.nix { + pkgs = releaseLib.pkgsForCross crossSystem system; + }; +in +lib.mapAttrs (n: make) ( + with lib.systems.examples; + { + # NOTE: Only add platforms for which there are files in `./bootstrap-files` + # or for which you plan to request the tarball upload soon. See the + # maintainers/scripts/bootstrap-files/README.md + # on how to request an upload. + # Sort following the sorting in `./default.nix` `bootstrapFiles` argument. + + x86_64-pc-cygwin = x86_64-cygwin; + } +) diff --git a/pkgs/stdenv/cygwin/make-bootstrap-tools.nix b/pkgs/stdenv/cygwin/make-bootstrap-tools.nix new file mode 100644 index 0000000000000..3ec24ecf68fec --- /dev/null +++ b/pkgs/stdenv/cygwin/make-bootstrap-tools.nix @@ -0,0 +1,95 @@ +{ + pkgs ? import ../../.. { }, +}: +let + inherit (pkgs) runCommand; + # splicing doesn't seem to work right here + inherit (pkgs.buildPackages) dumpnar rsync; + + pack-env = + paths: + pkgs.buildEnv { + name = "pack-env"; + paths = paths; + includeClosures = true; + ignoreCollisions = true; + }; + + pack-all = + packCmd: name: pkgs: fixups: + (runCommand name + { + nativeBuildInputs = [ + rsync + dumpnar + ]; + } + ( + let + in + '' + rsync --chmod="+w" -av -L --exclude=cygwin1.dll "${pack-env pkgs}"/ . + + base=$PWD + rm -rf nix nix-support + mkdir nix-support + for dir in $requisites; do + cd "$dir/nix-support" 2>/dev/null || continue + for f in $(find . -type f); do + mkdir -p "$base/nix-support/$(dirname $f)" + cat $f >>"$base/nix-support/$f" + done + done + rm -f $base/nix-support/propagated-build-inputs + cd $base + + ${fixups} + + ${packCmd} + '' + ) + ); + nar-all = pack-all "dumpnar . | xz -9 -e -T $NIX_BUILD_CORES >$out"; + tar-all = pack-all "XZ_OPT=\"-9 -e -T $NIX_BUILD_CORES\" tar cJf $out --hard-dereference --sort=name --numeric-owner --owner=0 --group=0 --mtime=@1 ."; + coreutils-big = pkgs.coreutils.override { singleBinary = false; }; + mkdir = runCommand "mkdir" { coreutils = coreutils-big; } '' + mkdir -p $out/bin + cp $coreutils/bin/mkdir.exe $out/bin + ''; + + curl = pkgs.curl.overrideAttrs (old: { + # these use the build shebang + # TODO: fix in curl + postFixup = old.postFixup or "" + '' + rm "$dev"/bin/curl-config "$bin"/bin/wcurl + ''; + }); +in +rec { + unpack = nar-all "unpack.nar.xz" (with pkgs; [ + bashNonInteractive + mkdir + xz + gnutar + ]) ""; + bootstrap-tools = tar-all "bootstrap-tools.tar.xz" (with pkgs; [ + gcc + # gcc.lib + curl + curl.dev + cygwin.newlib-cygwin + cygwin.newlib-cygwin.bin + cygwin.newlib-cygwin.dev + cygwin.w32api + cygwin.w32api.dev + # bintools-unwrapped + gnugrep + coreutils + expand-response-params + ]) ""; + build = runCommand "build" { } '' + mkdir -p $out/on-server + ln -s ${unpack} $out/on-server/unpack.nar.xz + ln -s ${bootstrap-tools} $out/on-server/bootstrap-tools.tar.xz + ''; +} diff --git a/pkgs/top-level/release-cross.nix b/pkgs/top-level/release-cross.nix index 95d30e66077a4..4e393d821cd63 100644 --- a/pkgs/top-level/release-cross.nix +++ b/pkgs/top-level/release-cross.nix @@ -300,12 +300,16 @@ in let linuxTools = import ../stdenv/linux/make-bootstrap-tools-cross.nix { system = "x86_64-linux"; }; freebsdTools = import ../stdenv/freebsd/make-bootstrap-tools-cross.nix { system = "x86_64-linux"; }; + cygwinTools = import ../stdenv/cygwin/make-bootstrap-tools-cross.nix { system = "x86_64-linux"; }; linuxMeta = { maintainers = [ maintainers.dezgeg ]; }; freebsdMeta = { maintainers = [ maintainers.rhelmot ]; }; + cygwinMeta = { + maintainers = [ maintainers.corngood ]; + }; mkBootstrapToolsJob = meta: drv: assert elem drv.system supportedSystems; @@ -331,8 +335,11 @@ in freebsd = mapAttrsRecursiveCond (as: !isDerivation as) ( name: mkBootstrapToolsJob freebsdMeta ) freebsdTools; + cygwin = mapAttrsRecursiveCond (as: !isDerivation as) ( + name: mkBootstrapToolsJob cygwinMeta + ) cygwinTools; in - linux // freebsd; + linux // freebsd // cygwin; # Cross-built nixStatic for platforms for enabled-but-unsupported platforms mips64el-nixCrossStatic = mapTestOnCross systems.examples.mips64el-linux-gnuabi64 nixCrossStatic; From cde24bddfb2cb6f21a0d48996c5d0a423e02ec50 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 22 Dec 2025 09:05:44 -0400 Subject: [PATCH 104/119] HACK: remove cygwin workflow --- .github/workflows/cygwin.yml | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 .github/workflows/cygwin.yml diff --git a/.github/workflows/cygwin.yml b/.github/workflows/cygwin.yml deleted file mode 100644 index 96ecdc1f4f406..0000000000000 --- a/.github/workflows/cygwin.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: cygwin -on: - push: -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v5 - - uses: DeterminateSystems/nix-installer-action@main - - uses: DeterminateSystems/magic-nix-cache-action@main - - name: build - run: nix build .#cygwinSystem.config.system.build.tarball - - uses: actions/upload-artifact@v4 - with: - name: tarball - path: result - test: - runs-on: windows-latest - needs: build - steps: - - uses: actions/download-artifact@v4 - with: - name: tarball - - name: install - run: tarball/install.ps1 cygwin - - name: build - shell: cygwin/cygwin.ps1 {0} - run: nix build --no-sandbox nixpkgs#hello - # - uses: actions/upload-artifact@v4 - # with: - # name: tarball - # path: result From c36eb2ab326fa8076f1e9e44f53c8213d6d63939 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 22 Dec 2025 22:40:37 -0400 Subject: [PATCH 105/119] cocom-tool-set: fix cross build --- .../co/cocom-tool-set/fix-cross-build.patch | 37 +++++++++++++++++++ pkgs/by-name/co/cocom-tool-set/package.nix | 8 ++++ 2 files changed, 45 insertions(+) create mode 100644 pkgs/by-name/co/cocom-tool-set/fix-cross-build.patch diff --git a/pkgs/by-name/co/cocom-tool-set/fix-cross-build.patch b/pkgs/by-name/co/cocom-tool-set/fix-cross-build.patch new file mode 100644 index 0000000000000..252a50a06b2e4 --- /dev/null +++ b/pkgs/by-name/co/cocom-tool-set/fix-cross-build.patch @@ -0,0 +1,37 @@ +diff --git a/configure b/configure +index bd6d039..64d1b17 100755 +--- a/configure ++++ b/configure +@@ -5706,13 +5706,7 @@ if test $xnet = yes; then + SPECIAL_LINK_OPTION="$SPECIAL_LINK_OPTION -lxnet" + fi + +-if test "$cross_compiling" = yes; then +- { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling +-See \`config.log' for more details." >&5 +-echo "$as_me: error: cannot run test program while cross compiling +-See \`config.log' for more details." >&2;} +- { (exit 1); exit 1; }; } +-else ++if true; then + cat >conftest.$ac_ext <<_ACEOF + /* confdefs.h. */ + _ACEOF +@@ -5775,7 +5775,7 @@ if test x$dino_shlib = x; then + echo +++We will not use DINO shared library + DINO_GCC_FPIC=-DNO_DINO_SHLIB + DINO_LIB_SUFFIX=a +- DINO_MAKELIB="ar rc \\\$\$0" ++ DINO_MAKELIB="$AR rc \\\$\$0" + DINO_AFTER_MAKELIB="$RANLIB \\\$\$0;echo \\\$\$0" + DINO_ADDITIONAL_LIBS="$DINO_LIB_NAME.$DINO_LIB_SUFFIX" + if test x$no_extern_shlib = x; then +@@ -5790,7 +5790,7 @@ if test x$no_extern_shlib != x; then + EXTERN_GCC_FPIC=-DNO_EXTERN_SHLIB + DINO_GCC_FPIC="$DINO_GCC_FPIC -DNO_EXTERN_SHLIB" + EXTERN_LIB_SUFFIX=a +- EXTERN_MAKELIB="ar rc \\\$\$0" ++ EXTERN_MAKELIB="$AR rc \\\$\$0" + EXTERN_AFTER_MAKELIB="$RANLIB \\\$\$0;echo \\\$\$0" + DINO_ADDITIONAL_LIBS="$DINO_ADDITIONAL_LIBS mpi.$EXTERN_LIB_SUFFIX ieee.$EXTERN_LIB_SUFFIX ipcerr.$EXTERN_LIB_SUFFIX socket.$EXTERN_LIB_SUFFIX gmp.$EXTERN_LIB_SUFFIX" + else diff --git a/pkgs/by-name/co/cocom-tool-set/package.nix b/pkgs/by-name/co/cocom-tool-set/package.nix index 85ed5eebd7369..96257ecb68a8c 100644 --- a/pkgs/by-name/co/cocom-tool-set/package.nix +++ b/pkgs/by-name/co/cocom-tool-set/package.nix @@ -4,6 +4,7 @@ fetchurl, autoreconfHook, bison, + buildPackages, }: stdenv.mkDerivation (finalAttrs: { pname = "cocom"; @@ -14,6 +15,13 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-4UOrVW15o17zHsHiQIl8m4qNC2aT5QorbkfX/UsgBRk="; }; + patches = lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) ./fix-cross-build.patch; + + preConfigure = lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + substituteInPlace DINO/Makefile.in + --replace-fail ../SPRUT/sprut "${buildPackages.cocom-tool-set}"/bin/sprut + ''; + env = { RANLIB = "${stdenv.cc.targetPrefix}gcc-ranlib"; NIX_CFLAGS_COMPILE = toString [ From 472efe4c66b13d1659d17893ba4a4c026c933c84 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 22 Dec 2025 22:41:03 -0400 Subject: [PATCH 106/119] treewide: undo changes causing rebuilds --- pkgs/by-name/co/cocom-tool-set/package.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkgs/by-name/co/cocom-tool-set/package.nix b/pkgs/by-name/co/cocom-tool-set/package.nix index 96257ecb68a8c..750eafc072661 100644 --- a/pkgs/by-name/co/cocom-tool-set/package.nix +++ b/pkgs/by-name/co/cocom-tool-set/package.nix @@ -17,10 +17,14 @@ stdenv.mkDerivation (finalAttrs: { patches = lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) ./fix-cross-build.patch; - preConfigure = lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' - substituteInPlace DINO/Makefile.in - --replace-fail ../SPRUT/sprut "${buildPackages.cocom-tool-set}"/bin/sprut - ''; + ${if (stdenv.buildPlatform != stdenv.hostPlatform) then "preConfigure" else null} = + lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) + '' + substituteInPlace DINO/Makefile.in \ + --replace-fail ../SPRUT/sprut "${buildPackages.cocom-tool-set}"/bin/sprut \ + --replace-fail ../MSTA/msta "${buildPackages.cocom-tool-set}"/bin/msta \ + --replace-fail ../SHILKA/shilka "${buildPackages.cocom-tool-set}"/bin/shilka + ''; env = { RANLIB = "${stdenv.cc.targetPrefix}gcc-ranlib"; From 7755344d320215012e12acc3d49a752453e7c8a4 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 22 Dec 2025 23:06:45 -0400 Subject: [PATCH 107/119] WIP: cygwin bootstrap stdenv --- bootstrap.nix | 1 + .../cygwin/newlib-cygwin/default.nix | 24 +- pkgs/os-specific/cygwin/w32api/default.nix | 20 +- pkgs/stdenv/cygwin/default.nix | 554 +++++++++++++++--- pkgs/stdenv/cygwin/linkBootstrap.sh | 59 ++ pkgs/stdenv/cygwin/make-bootstrap-tools.nix | 164 +++--- 6 files changed, 639 insertions(+), 183 deletions(-) create mode 100644 bootstrap.nix create mode 100755 pkgs/stdenv/cygwin/linkBootstrap.sh diff --git a/bootstrap.nix b/bootstrap.nix new file mode 100644 index 0000000000000..1b8e999df6f13 --- /dev/null +++ b/bootstrap.nix @@ -0,0 +1 @@ +/nix/store/2m6hgrgdccz1yrpqlda0iz3ysxcipnj2-unpacked diff --git a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix index c4238b2d033a7..ad25645d978e5 100644 --- a/pkgs/os-specific/cygwin/newlib-cygwin/default.nix +++ b/pkgs/os-specific/cygwin/newlib-cygwin/default.nix @@ -1,12 +1,10 @@ { lib, - stdenv, stdenvNoCC, stdenvNoLibc, autoreconfHook, bison, buildPackages, - cocom-tool-set, flex, perl, w32api, @@ -24,13 +22,17 @@ let noLibc = false; }; in - stdenvNoLibc.override { - cc = stdenvNoLibc.cc.override { - libc = newlib-cygwin-headers; - noLibc = false; - inherit bintools; - }; - }; + # we only want to do this on cygwin because newlib-cygwin-headers doesn't + # evaluate on other platforms + stdenvNoLibc.override ( + lib.optionalAttrs stdenvNoLibc.hostPlatform.isCygwin { + cc = stdenvNoLibc.cc.override { + libc = newlib-cygwin-headers; + noLibc = false; + inherit bintools; + }; + } + ); in (if headersOnly then stdenvNoCC else stdenv).mkDerivation ( @@ -40,9 +42,10 @@ in version = "3.6.4"; src = buildPackages.fetchgit { - url = "https://cygwin.com/git/newlib-cygwin.git"; + url = "git://cygwin.com/git/newlib-cygwin"; rev = "cygwin-${finalAttrs.version}"; hash = "sha256-+WYKwqcDAc7286GzbgKKAxNJCOf3AeNnF8XEVPoor+g="; + fetchSubmodules = false; }; outputs = [ @@ -135,7 +138,6 @@ in nativeBuildInputs = [ autoreconfHook bison - cocom-tool-set flex perl ]; diff --git a/pkgs/os-specific/cygwin/w32api/default.nix b/pkgs/os-specific/cygwin/w32api/default.nix index 8d900d3889263..7318db70414b2 100644 --- a/pkgs/os-specific/cygwin/w32api/default.nix +++ b/pkgs/os-specific/cygwin/w32api/default.nix @@ -17,13 +17,17 @@ let noLibc = false; }; in - stdenvNoLibc.override { - cc = stdenvNoLibc.cc.override { - libc = newlib-cygwin-headers; - noLibc = false; - inherit bintools; - }; - }; + # we only want to do this on cygwin because newlib-cygwin-headers doesn't + # evaluate on other platforms + stdenvNoLibc.override ( + lib.optionalAttrs stdenvNoLibc.hostPlatform.isCygwin { + cc = stdenvNoLibc.cc.override { + libc = newlib-cygwin-headers; + noLibc = false; + inherit bintools; + }; + } + ); in (if headersOnly then stdenvNoCC else stdenv).mkDerivation ( @@ -69,7 +73,7 @@ in } else { - nativeBuildInputs = [ autoreconfHook ]; + # nativeBuildInputs = [ autoreconfHook ]; hardeningDisable = [ "stackprotector" diff --git a/pkgs/stdenv/cygwin/default.nix b/pkgs/stdenv/cygwin/default.nix index 0652a6ad9b066..d3e1943d1c0c8 100644 --- a/pkgs/stdenv/cygwin/default.nix +++ b/pkgs/stdenv/cygwin/default.nix @@ -8,7 +8,15 @@ bootstrapFiles ? let table = { - x86_64-cygwin = import ./bootstrap-files/x86_64-pc-cygwin.nix; + x86_64-cygwin = { + # import ./bootstrap-files/x86_64-pc-cygwin.nix; + unpack = import { + url = "https://github.com/corngood/nixpkgs/releases/download/bootstrap%2Fv0.1/unpack.nar.xz"; + hash = "sha256-B5pezEcJkWtI0nDRCeOjtwSQ4OTuA2ef06keEvr4i4E="; + name = "unpack"; + unpack = true; + }; + }; }; files = table.${localSystem.system} @@ -19,126 +27,504 @@ assert crossSystem == localSystem; let - bootStages = import ../. { - inherit lib overlays; - - localSystem = lib.systems.elaborate "x86_64-linux"; - - crossSystem = localSystem; - crossOverlays = [ ]; + cygwinDllLink = derivation { + inherit (localSystem) system; + name = "cygwin-dll-link.sh"; + src = ../../os-specific/cygwin/cygwin-dll-link.sh; + builder = "${bootstrapFiles.unpack}/bin/bash"; + args = [ + "-c" + "sed s:@objdump@:${bootstrapFiles.unpack}/bin/objdump:g $src > $out" + ]; + PATH = "${bootstrapFiles.unpack}/bin"; + }; + linkBootstrap = ( + attrs: + derivation ( + attrs + // { + inherit (localSystem) system; + name = attrs.name or (baseNameOf (builtins.elemAt attrs.paths 0)); + version = "bootstrap"; + src = bootstrapFiles.unpack; + builder = "${bootstrapFiles.unpack}/bin/bash"; + args = [ + ./linkBootstrap.sh + ]; + PATH = "${bootstrapFiles.unpack}/bin"; + inherit cygwinDllLink; + paths = attrs.paths; + } + ) + ); - # Ignore custom stdenvs when cross compiling for compatibility - # Use replaceCrossStdenv instead. - config = builtins.removeAttrs config [ "replaceStdenv" ]; + bootstrap-packages = { + bashNonInteractive = linkBootstrap { + paths = [ + "bin/bash" + "bin/sh" + ]; + shell = "bin/bash"; + shellPath = "/bin/bash"; + }; + binutils-unwrapped = linkBootstrap { + name = "binutils"; + paths = map (str: "bin/" + str) [ + "ld" + "as" + "addr2line" + "ar" + "c++filt" + "dlltool" + "elfedit" + "gprof" + "objdump" + "nm" + "objcopy" + "ranlib" + "readelf" + "size" + "strings" + "strip" + "windres" + ]; + }; + bzip2.bin = linkBootstrap { paths = [ "bin/bzip2" ]; }; + coreutils = linkBootstrap { + name = "coreutils"; + paths = map (str: "bin/" + str) [ + "base64" + "basename" + "cat" + "chcon" + "chgrp" + "chmod" + "chown" + "chroot" + "cksum" + "comm" + "cp" + "csplit" + "cut" + "date" + "dd" + "df" + "dir" + "dircolors" + "dirname" + "du" + "echo" + "env" + "expand" + "expr" + "factor" + "false" + "fmt" + "fold" + "groups" + "head" + "hostid" + "id" + "install" + "join" + "kill" + "link" + "ln" + "logname" + "ls" + "md5sum" + "mkdir" + "mkfifo" + "mknod" + "mktemp" + "mv" + "nice" + "nl" + "nohup" + "nproc" + "numfmt" + "od" + "paste" + "pathchk" + "pinky" + "pr" + "printenv" + "printf" + "ptx" + "pwd" + "readlink" + "realpath" + "rm" + "rmdir" + "runcon" + "seq" + "shred" + "shuf" + "sleep" + "sort" + "split" + "stat" + "stty" + "sum" + "tac" + "tail" + "tee" + "test" + "timeout" + "touch" + "tr" + "true" + "truncate" + "tsort" + "tty" + "uname" + "unexpand" + "uniq" + "unlink" + "users" + "vdir" + "wc" + "who" + "whoami" + "yes" + "[" + ]; + }; + curl = linkBootstrap { + paths = [ + "bin/curl" + ]; + }; + diffutils = linkBootstrap { + name = "diffutils"; + paths = map (str: "bin/" + str) [ + "diff" + "cmp" + #"diff3" + #"sdiff" + ]; + }; + # expand-response-params = bootstrapFiles.unpack; + file = linkBootstrap { + name = "file"; + paths = [ "bin/file" ]; + }; + findutils = linkBootstrap { + name = "findutils"; + paths = [ + "bin/find" + "bin/xargs" + ]; + }; + gawk = linkBootstrap { + paths = [ + "bin/awk" + "bin/gawk" + ]; + }; + gcc-unwrapped = linkBootstrap { + name = "gcc"; + paths = map (str: "bin/" + str) [ + "gcc" + "g++" + "cygatomic-1.dll" + "cyggcc_s-seh-1.dll" + "cygquadmath-0.dll" + "cygstdc++-6.dll" + ]; + }; + git = linkBootstrap { paths = [ "bin/git" ]; }; + gnugrep = linkBootstrap { + paths = [ + "bin/grep" + "bin/egrep" + "bin/fgrep" + ]; + }; + gnumake = linkBootstrap { paths = [ "bin/make" ]; }; + gnused = linkBootstrap { paths = [ "bin/sed" ]; }; + gnutar = linkBootstrap { paths = [ "bin/tar" ]; }; + gzip = linkBootstrap { + paths = [ + "bin/gzip" + #"bin/gunzip" + ]; + postBuild = '' + rm "$out"/bin/gzip + sed -E 's:/nix/store/[^/]*:'$src':' "$src"/bin/gzip > "$out"/bin/gzip + chmod +x "$out"/bin/gzip + ''; + }; + libc = linkBootstrap { + name = "libc"; + paths = [ + "include" + "lib" + ]; + }; + patch = linkBootstrap { paths = [ "bin/patch" ]; }; + xz.bin = linkBootstrap { paths = [ "bin/xz" ]; }; }; in -bootStages -++ [ - +[ ( prevStage: let - name = "cygwin"; - initialPath = - ((import ../generic/common-path.nix) { pkgs = prevStage; }) + # TODO: switch to this + # ((import ../generic/common-path.nix) { pkgs = bootstrap-packages; }) + with bootstrap-packages; + [ + coreutils + diffutils + gnutar + file + findutils + gnumake + gnused + gnugrep + gawk + patch + bashNonInteractive + gzip + bzip2.bin + xz.bin + ] # needed for cygwin1.dll + # TODO: remove? ++ [ "/" ]; - shell = "${prevStage.bashNonInteractive}/bin/bash"; + shell = "${bootstrap-packages.bashNonInteractive}/bin/bash"; + + stdenvNoCC = import ../generic rec { + name = "stdenv-cygwin-boot0"; - stdenvNoCC = import ../generic { + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; inherit config initialPath - shell fetchurlBoot + shell ; - name = "stdenvNoCC-${name}"; - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = localSystem; + + hasCC = false; cc = null; + + extraNativeBuildInputs = [ + cygwinDllLink + ]; + + overrides = self: super: { + fetchurl = lib.makeOverridable fetchurlBoot; + fetchgit = super.fetchgit.override { + inherit (bootstrap-packages) git; + cacert = null; + git-lfs = null; + }; + }; }; fetchurlBoot = import ../../build-support/fetchurl { inherit lib stdenvNoCC; - inherit (prevStage) curl; + inherit (bootstrap-packages) curl; inherit (config) rewriteURL hashedMirrors; }; - gcc = ( - prevStage.gccFun { - noSysDirs = true; - majorMinorVersion = toString prevStage.default-gcc-version; - targetPackages.stdenv.cc.bintools = prevStage.stdenv.cc.bintools; - } - ); - in { inherit config overlays stdenvNoCC; - stdenv = import ../generic rec { - name = "stdenv-cygwin"; + stdenv = stdenvNoCC; + } + ) - buildPlatform = localSystem; - hostPlatform = localSystem; - targetPlatform = localSystem; - inherit - config - initialPath - fetchurlBoot - shell - ; + (prevStage: { + inherit config overlays; + inherit (prevStage) stdenvNoCC; - cc = lib.makeOverridable (import ../../build-support/cc-wrapper) { - inherit lib stdenvNoCC; - name = "${name}-cc"; - cc = gcc; - isGNU = true; - libc = prevStage.cygwin.newlib-cygwin; - inherit (prevStage) gnugrep coreutils expand-response-params; + stdenv = import ../generic rec { + name = "stdenv-cygwin-boot1"; + + inherit config; + inherit (prevStage.stdenv) + buildPlatform + hostPlatform + targetPlatform + fetchurlBoot + initialPath + shell + ; + + extraNativeBuildInputs = [ + cygwinDllLink + ]; + + cc = lib.makeOverridable (import ../../build-support/cc-wrapper) { + inherit lib; + inherit (prevStage) stdenvNoCC; + name = "${name}-cc"; + cc = bootstrap-packages.gcc-unwrapped; + isGNU = true; + libc = prevStage.cygwin.newlib-cygwin-headers; + inherit (bootstrap-packages) gnugrep coreutils; + expand-response-params = ""; + nativeTools = false; + nativeLibc = false; + propagateDoc = false; + runtimeShell = shell; + bintools = lib.makeOverridable (import ../../build-support/bintools-wrapper) { + inherit lib; + inherit (prevStage) stdenvNoCC; + name = "${name}-bintools"; + bintools = bootstrap-packages.binutils-unwrapped; + libc = prevStage.cygwin.newlib-cygwin-headers; + inherit (bootstrap-packages) gnugrep coreutils; + expand-response-params = ""; nativeTools = false; nativeLibc = false; propagateDoc = false; runtimeShell = shell; - bintools = lib.makeOverridable (import ../../build-support/bintools-wrapper) { - inherit lib stdenvNoCC; - name = "${name}-bintools"; - bintools = prevStage.bintools-unwrapped; - libc = prevStage.cygwin.newlib-cygwin; - inherit (prevStage) gnugrep coreutils expand-response-params; - nativeTools = false; - nativeLibc = false; - propagateDoc = false; - runtimeShell = shell; + }; + }; + + overrides = self: super: { + fetchurl = lib.makeOverridable fetchurlBoot; + fetchgit = super.fetchgit.override { + inherit (bootstrap-packages) git; + cacert = null; + git-lfs = null; + }; + }; + }; + }) + + (prevStage: { + inherit config overlays; + + stdenv = import ../generic rec { + name = "stdenv-cygwin-boot2"; + + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; + inherit config; + inherit (prevStage.stdenv) fetchurlBoot initialPath shell; + + extraNativeBuildInputs = [ + cygwinDllLink + ]; + + cc = lib.makeOverridable (import ../../build-support/cc-wrapper) { + inherit lib; + inherit (prevStage) stdenvNoCC; + name = "${name}-cc"; + cc = bootstrap-packages.gcc-unwrapped; + isGNU = true; + libc = bootstrap-packages.libc // { + inherit (prevStage.cygwin) w32api; + }; + inherit (bootstrap-packages) gnugrep coreutils; + expand-response-params = ""; + nativeTools = false; + nativeLibc = false; + propagateDoc = false; + runtimeShell = shell; + bintools = lib.makeOverridable (import ../../build-support/bintools-wrapper) { + inherit lib; + inherit (prevStage) stdenvNoCC; + name = "${name}-bintools"; + bintools = bootstrap-packages.binutils-unwrapped; + libc = bootstrap-packages.libc // { + inherit (prevStage.cygwin) w32api; }; + inherit (bootstrap-packages) gnugrep coreutils; + expand-response-params = ""; + nativeTools = false; + nativeLibc = false; + propagateDoc = false; + runtimeShell = shell; }; + }; - overrides = self: super: { - fetchurl = lib.makeOverridable fetchurlBoot; - __bootstrapPackages = - (import ../generic/common-path.nix) { pkgs = prevStage; } - ++ [ - gcc - gcc.lib - ] - ++ (with prevStage; [ - curl - curl.dev - cygwin.newlib-cygwin - cygwin.newlib-cygwin.bin - cygwin.newlib-cygwin.dev - cygwin.w32api - cygwin.w32api.dev - bintools-unwrapped - gnugrep - coreutils - expand-response-params - ]); + overrides = self: super: { + fetchurl = lib.makeOverridable fetchurlBoot; + __realFetchUrl = super.fetchurl; + fetchgit = super.fetchgit.override { + inherit (bootstrap-packages) git; + cacert = null; + git-lfs = null; }; }; - } - ) + }; + }) + + (prevStage: { + inherit config overlays; + + stdenv = import ../generic rec { + name = "stdenv-cygwin-boot3"; + + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; + inherit config; + + initialPath = ((import ../generic/common-path.nix) { pkgs = prevStage; }); + + extraNativeBuildInputs = [ + prevStage.cygwin.cygwinDllLinkHook + ]; + + cc = prevStage.gcc; + + shell = cc.shell; + + inherit (prevStage.stdenv) fetchurlBoot; + + overrides = self: super: { + inherit (prevStage) fetchurl; + __realFetchUrl = super.fetchurl; + }; + }; + }) + + (prevStage: { + inherit config overlays; + + stdenv = import ../generic rec { + name = "stdenv-cygwin"; + + buildPlatform = localSystem; + hostPlatform = localSystem; + targetPlatform = localSystem; + inherit config; + + initialPath = ((import ../generic/common-path.nix) { pkgs = prevStage; }); + + extraNativeBuildInputs = [ + prevStage.cygwin.cygwinDllLinkHook + ]; + + cc = prevStage.gcc.override (old: { + cc = old.cc.overrideAttrs (old: { + # break dependency on previous stage cygintl-8.dll + preFixup = old.preFixup or "" + '' + ln -s "${lib.getLib prevStage.gettext}"/bin/cygintl-8.dll "$out"/bin + ''; + }); + }); + + shell = cc.shell; + + inherit (prevStage.stdenv) fetchurlBoot; + + disallowedRequisites = [ bootstrapFiles.unpack ]; + + overrides = self: super: { + fetchurl = prevStage.__realFetchUrl; + }; + }; + }) ] diff --git a/pkgs/stdenv/cygwin/linkBootstrap.sh b/pkgs/stdenv/cygwin/linkBootstrap.sh new file mode 100755 index 0000000000000..de112c83d8f52 --- /dev/null +++ b/pkgs/stdenv/cygwin/linkBootstrap.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +for path in $paths; do + if [[ -e $src/$path.exe ]]; then + path=$path.exe + fi + if ! [[ -e $src/$path ]]; then + echo "Error: $path does not exist" + exit 1 + fi + mkdir -p $out/$(dirname $path) + CYGWIN+=\ winsymlinks:nativestrict ln -s $src/$path $out/$path +done + +addEnvHooks() { + true +} + +# HACK: copied from stdenv +# refactor cygwin-dll-link? +concatTo() { + local - + set -o noglob + local -n targetref="$1"; shift + local arg default name type + for arg in "$@"; do + IFS="=" read -r name default <<< "$arg" + local -n nameref="$name" + if [[ -z "${nameref[*]}" && -n "$default" ]]; then + targetref+=( "$default" ) + elif type=$(declare -p "$name" 2> /dev/null); then + case "${type#* }" in + -A*) + echo "concatTo(): ERROR: trying to use concatTo on an associative array." >&2 + return 1 ;; + -a*) + targetref+=( "${nameref[@]}" ) ;; + *) + if [[ "$name" = *"Array" ]]; then + nixErrorLog "concatTo(): $name is not declared as array, treating as a singleton. This will become an error in future" + # Reproduces https://github.com/NixOS/nixpkgs/pull/318614/files#diff-7c7ca80928136cfc73a02d5b28350bd900e331d6d304857053ffc9f7beaad576L359 + targetref+=( ${nameref+"${nameref[@]}"} ) + else + # shellcheck disable=SC2206 + targetref+=( ${nameref-} ) + fi + ;; + esac + fi + done +} + +source "$cygwinDllLink" + +_linkDeps_inputPath=$src/bin +allowedImpureDLLs=(KERNEL32.dll ntdll.dll) +linkDLLs $out/bin + +[[ ! -v postBuild ]] || eval "$postBuild" diff --git a/pkgs/stdenv/cygwin/make-bootstrap-tools.nix b/pkgs/stdenv/cygwin/make-bootstrap-tools.nix index 3ec24ecf68fec..daf2df80f4fe8 100644 --- a/pkgs/stdenv/cygwin/make-bootstrap-tools.nix +++ b/pkgs/stdenv/cygwin/make-bootstrap-tools.nix @@ -4,92 +4,96 @@ let inherit (pkgs) runCommand; # splicing doesn't seem to work right here - inherit (pkgs.buildPackages) dumpnar rsync; + inherit (pkgs.buildPackages) dumpnar rsync nukeReferences; - pack-env = - paths: - pkgs.buildEnv { - name = "pack-env"; - paths = paths; - includeClosures = true; - ignoreCollisions = true; - }; + unpacked = + let + inherit (pkgs) + bashNonInteractive + binutils-unwrapped + bzip2 + coreutils + diffutils + file + findutils + gawk + gcc-unwrapped + gitMinimal # for fetchgit (newlib-cygwin) + gnugrep + gnumake + gnused + gnutar + gzip + patch + xz + ; - pack-all = - packCmd: name: pkgs: fixups: - (runCommand name + inherit (pkgs.cygwin) + newlib-cygwin + w32api + ; + + curl = pkgs.curl.overrideAttrs (old: { + # these use the build shebang + # TODO: fix in curl + postFixup = old.postFixup or "" + '' + rm "$dev"/bin/curl-config "$bin"/bin/wcurl + ''; + }); + + in + runCommand "unpacked" { - nativeBuildInputs = [ - rsync - dumpnar - ]; + nativeBuildInputs = [ nukeReferences ]; + # The result should not contain any references (store paths) so + # that we can safely copy them out of the store and to other + # locations in the store. + allowedReferences = [ ]; + strictDeps = true; } - ( - let - in - '' - rsync --chmod="+w" -av -L --exclude=cygwin1.dll "${pack-env pkgs}"/ . + '' + mkdir -p "$out"/{bin,include,lib,libexec} + cp -d "${bashNonInteractive}"/bin/* "$out"/bin/ + cp -d "${binutils-unwrapped}"/bin/* "$out"/bin/ + cp -d "${bzip2}"/bin/* "$out"/bin/ + cp -d "${coreutils}"/bin/* "$out"/bin/ + cp -d "${curl}"/bin/* "$out"/bin/ + cp -d "${diffutils}"/bin/* "$out"/bin/ + cp -d "${file}"/bin/* "$out"/bin/ + cp -d "${findutils}"/bin/* "$out"/bin/ + cp -d "${gawk}"/bin/* "$out"/bin/ + cp -d "${gcc-unwrapped}"/bin/* "$out"/bin/ + cp -rd ${gcc-unwrapped}/include/* $out/include/ + cp -rd ${gcc-unwrapped}/lib/* $out/lib/ + cp -rd ${gcc-unwrapped}/libexec/* $out/libexec/ + cp -frd ${gcc-unwrapped.lib}/bin/* $out/bin/ + cp -rd ${gcc-unwrapped.lib}/lib/* $out/lib/ + cp -d "${gitMinimal}"/bin/* "$out"/bin/ + cp -d "${gnugrep}"/bin/* "$out"/bin/ + cp -d "${gnumake}"/bin/* "$out"/bin/ + cp -d "${gnused}"/bin/* "$out"/bin/ + cp -d "${gnutar}"/bin/* "$out"/bin/ + (shopt -s dotglob; cp -d "${gzip}"/bin/* "$out"/bin/) + cp -rd ${newlib-cygwin.dev}/include/* $out/include/ + cp -rd ${newlib-cygwin}/lib/* "$out"/lib/ + cp -d "${patch}"/bin/* "$out"/bin/ + cp -d "${w32api}"/lib/w32api/lib{advapi,shell,user,kernel}32.a "$out"/lib/ + cp -d "${xz}"/bin/* "$out"/bin/ - base=$PWD - rm -rf nix nix-support - mkdir nix-support - for dir in $requisites; do - cd "$dir/nix-support" 2>/dev/null || continue - for f in $(find . -type f); do - mkdir -p "$base/nix-support/$(dirname $f)" - cat $f >>"$base/nix-support/$f" - done - done - rm -f $base/nix-support/propagated-build-inputs - cd $base + chmod -R +w "$out" - ${fixups} + find "$out" -type l -print0 | while read -d $'\0' link; do + [[ -L "$link" && -e "$link" ]] || continue + [[ $(realpath "$link") != "$out"* ]] || continue + cp "$link" "$link"~ + mv "$link"~ "$link" + done - ${packCmd} - '' - ) - ); - nar-all = pack-all "dumpnar . | xz -9 -e -T $NIX_BUILD_CORES >$out"; - tar-all = pack-all "XZ_OPT=\"-9 -e -T $NIX_BUILD_CORES\" tar cJf $out --hard-dereference --sort=name --numeric-owner --owner=0 --group=0 --mtime=@1 ."; - coreutils-big = pkgs.coreutils.override { singleBinary = false; }; - mkdir = runCommand "mkdir" { coreutils = coreutils-big; } '' - mkdir -p $out/bin - cp $coreutils/bin/mkdir.exe $out/bin - ''; - - curl = pkgs.curl.overrideAttrs (old: { - # these use the build shebang - # TODO: fix in curl - postFixup = old.postFixup or "" + '' - rm "$dev"/bin/curl-config "$bin"/bin/wcurl - ''; - }); + find "$out" -print0 | xargs -0 nuke-refs -e "$out" + ''; in -rec { - unpack = nar-all "unpack.nar.xz" (with pkgs; [ - bashNonInteractive - mkdir - xz - gnutar - ]) ""; - bootstrap-tools = tar-all "bootstrap-tools.tar.xz" (with pkgs; [ - gcc - # gcc.lib - curl - curl.dev - cygwin.newlib-cygwin - cygwin.newlib-cygwin.bin - cygwin.newlib-cygwin.dev - cygwin.w32api - cygwin.w32api.dev - # bintools-unwrapped - gnugrep - coreutils - expand-response-params - ]) ""; - build = runCommand "build" { } '' - mkdir -p $out/on-server - ln -s ${unpack} $out/on-server/unpack.nar.xz - ln -s ${bootstrap-tools} $out/on-server/bootstrap-tools.tar.xz - ''; +{ + unpack = runCommand "unpack.nar.xz" { + nativeBuildInputs = [ dumpnar ]; + } "dumpnar ${unpacked} | xz -9 -e -T $NIX_BUILD_CORES >$out"; } From 5005d950cd690753fd4af9ab779872ab56f9eaf8 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 28 Dec 2025 21:30:02 -0400 Subject: [PATCH 108/119] gnupatch: fix cygwin build --- pkgs/tools/text/gnupatch/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/tools/text/gnupatch/default.nix b/pkgs/tools/text/gnupatch/default.nix index ddb0914dbe842..4cd0dd23825a1 100644 --- a/pkgs/tools/text/gnupatch/default.nix +++ b/pkgs/tools/text/gnupatch/default.nix @@ -27,7 +27,7 @@ stdenv.mkDerivation (finalAttrs: { "ac_cv_func_strnlen_working=yes" ]; - doCheck = stdenv.hostPlatform.libc != "musl"; # not cross; + doCheck = stdenv.hostPlatform.libc != "musl" && !stdenv.hostPlatform.isCygwin; # not cross; nativeCheckInputs = [ ed ]; meta = { From ed482dee18e534048850f0a0d118d359d39fef77 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 28 Dec 2025 22:24:27 -0400 Subject: [PATCH 109/119] cygwin-dll-link: search outputs first --- pkgs/build-support/setup-hooks/cygwin-dll-link.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh index ccf9d9e617f83..734b60f351381 100644 --- a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh +++ b/pkgs/build-support/setup-hooks/cygwin-dll-link.sh @@ -8,9 +8,11 @@ _moveDLLsToLib() { preFixupHooks+=(_moveDLLsToLib) +declare _linkDeps_binPath + _addOutputDLLPaths() { for output in $(getAllOutputNames); do - addToSearchPath "HOST_PATH" "${!output}/bin" + addToSearchPath _linkDeps_binPath "${!output}/bin" done } @@ -68,11 +70,13 @@ _linkDeps() { # Locate the DLL - it should be an *executable* file on $HOST_PATH. # This intentionally doesn't use $dir because we want to prefer dependencies # that are already linked next to the target. - if ! dllPath="$(PATH="$(dirname "$target"):$HOST_PATH" type -P "$dll")"; then + local searchPath + searchPath="$(dirname "$target"):$_linkDeps_binPath:$HOST_PATH" + if ! dllPath="$(PATH="$searchPath" type -P "$dll")"; then if [[ -z "$inOutput" || -n "${allowedImpureDLLsMap[$dll]}" ]]; then continue fi - echo unable to find "$dll" in "$HOST_PATH" >&2 + echo unable to find "$dll" in "$searchPath" >&2 exit 1 fi fi From 138a729a3113979a662c1e0bb9ff8079afc11c1f Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 29 Dec 2025 14:53:21 -0400 Subject: [PATCH 110/119] cygwin-dll-link: improve link handling --- pkgs/build-support/cc-wrapper/default.nix | 2 +- .../cygwin}/cygwin-dll-link.sh | 58 +++++++++++-------- pkgs/os-specific/cygwin/default.nix | 11 ++++ pkgs/stdenv/cross/default.nix | 5 +- pkgs/stdenv/generic/make-derivation.nix | 1 - 5 files changed, 49 insertions(+), 28 deletions(-) rename pkgs/{build-support/setup-hooks => os-specific/cygwin}/cygwin-dll-link.sh (67%) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index b3c009595562d..fee4f8aea190b 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -604,7 +604,7 @@ stdenvNoCC.mkDerivation { if targetPlatform.isCygwin then ( '' - echo addToSearchPath "_HOST_PATH" "${cc_solib}/bin" >> $out + echo addToSearchPath "_linkDeps_inputPath" "${cc_solib}/bin" >> $out # Work around build failure caused by the gnulib workaround for # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114870. remove after # gnulib is updated in core packages (e.g. iconv, gnupatch, gnugrep) diff --git a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh b/pkgs/os-specific/cygwin/cygwin-dll-link.sh similarity index 67% rename from pkgs/build-support/setup-hooks/cygwin-dll-link.sh rename to pkgs/os-specific/cygwin/cygwin-dll-link.sh index 734b60f351381..006dc0408cd0f 100644 --- a/pkgs/build-support/setup-hooks/cygwin-dll-link.sh +++ b/pkgs/os-specific/cygwin/cygwin-dll-link.sh @@ -8,22 +8,18 @@ _moveDLLsToLib() { preFixupHooks+=(_moveDLLsToLib) -declare _linkDeps_binPath +declare _linkDeps_inputPath _linkDeps_outputPath _addOutputDLLPaths() { for output in $(getAllOutputNames); do - addToSearchPath _linkDeps_binPath "${!output}/bin" + addToSearchPath _linkDeps_outputPath "${!output}/bin" done } preFixupHooks+=(_addOutputDLLPaths) _dllDeps() { - if [[ -z "${OBJDUMP:-}" ]]; then - echo "_dllDeps: '\$OBJDUMP' variable is empty, skipping." 1>&2 - return - fi - "$OBJDUMP" -p "$1" \ + @objdump@ -p "$1" \ | sed -n 's/.*DLL Name: \(.*\)/\1/p' \ | sort -u } @@ -32,20 +28,24 @@ declare -Ag _linkDeps_visited _linkDeps() { local target="$1" dir="$2" + + # canonicalise these for the dictionary + target=$(realpath -s "$target") + dir=$(realpath -s "$dir") + if [[ -v _linkDeps_visited[$target] ]]; then echo "_linkDeps: $target was already linked." 1>&2 return fi - if [[ ! -f "$target" || ! -x "$target" ]]; then + if [[ ! -f $target || ! -x $target ]]; then echo "_linkDeps: $target is not an executable file, skipping." 1>&2 return fi - local realTarget output inOutput - realTarget="$(readlink -f "$target")" + local output inOutput for output in $outputs ; do - if [[ $realTarget == "${!output}"* ]]; then - echo "_linkDeps: $target ($realTarget) is in $output (${!output})." 1>&2 + if [[ $target == "${!output}"* && ! -L $target ]]; then + echo "_linkDeps: $target is in $output (${!output})." 1>&2 inOutput=1 break fi @@ -55,25 +55,32 @@ _linkDeps() { local dll while read -r dll; do echo ' dll:' "$dll" - if [[ -v _linkDeps_visited[$dir/$dll] ]]; then + local dllPath=$dir/$dll + if [[ -v _linkDeps_visited[$dllPath] ]]; then echo "_linkDeps: $dll was already linked into $dir." 1>&2 continue fi - if [[ -L "$dir/$dll" || -e "$dir/$dll" ]]; then - echo ' already exists' - _linkDeps "$dir/$dll" "$dir" + if [[ -L $dllPath ]]; then + echo ' already linked' + dllPath=$(realpath -s "$(readlink "$dllPath")") + _linkDeps "$dllPath" "$dir" + elif [[ -e $dllPath ]]; then + echo ' already exits' + _linkDeps "$dllPath" "$dir" else - local dllPath if [[ $dll = cygwin1.dll ]]; then dllPath=/bin/cygwin1.dll else - # Locate the DLL - it should be an *executable* file on $HOST_PATH. - # This intentionally doesn't use $dir because we want to prefer dependencies - # that are already linked next to the target. - local searchPath - searchPath="$(dirname "$target"):$_linkDeps_binPath:$HOST_PATH" - if ! dllPath="$(PATH="$searchPath" type -P "$dll")"; then - if [[ -z "$inOutput" || -n "${allowedImpureDLLsMap[$dll]}" ]]; then + # This intentionally doesn't use $dir because we want to prefer + # dependencies that are already linked next to the target. + local searchPath realTarget + searchPath=$_linkDeps_outputPath:$_linkDeps_inputPath:$HOST_PATH + if [[ -L $target ]]; then + searchPath=$searchPath:$(dirname "$(readlink "$target")") + fi + searchPath=$(dirname "$target"):$searchPath + if ! dllPath=$(PATH="$searchPath" type -P "$dll"); then + if [[ -z $inOutput || -n ${allowedImpureDLLsMap[$dll]} ]]; then continue fi echo unable to find "$dll" in "$searchPath" >&2 @@ -86,6 +93,7 @@ _linkDeps() { fi _linkDeps_visited[$dir/$dll]=1 done < <(_dllDeps "$target") + wait $! } # linkDLLsDir can be used to override the destination path for links. This is @@ -98,7 +106,7 @@ linkDLLs() { # shellcheck disable=SC2154 ( set -e - shopt -s globstar nullglob + shopt -s globstar nullglob dotglob local -a allowedImpureDLLsArray concatTo allowedImpureDLLsArray allowedImpureDLLs diff --git a/pkgs/os-specific/cygwin/default.nix b/pkgs/os-specific/cygwin/default.nix index 798aadf47aa67..d8083ccd05de8 100644 --- a/pkgs/os-specific/cygwin/default.nix +++ b/pkgs/os-specific/cygwin/default.nix @@ -1,6 +1,10 @@ { + lib, makeScopeWithSplicing', generateSplicesForMkScope, + makeSetupHook, + binutils-unwrapped, + stdenv, }: let @@ -23,5 +27,12 @@ makeScopeWithSplicing' { rebase = callPackage ./rebase { }; tests = callPackage ./tests { }; + + cygwinDllLinkHook = makeSetupHook { + name = "cygwin-dll-link-hook"; + substitutions = { + objdump = "${lib.getBin binutils-unwrapped}/${stdenv.targetPlatform.config}/bin/objdump"; + }; + } ./cygwin-dll-link.sh; }; } diff --git a/pkgs/stdenv/cross/default.nix b/pkgs/stdenv/cross/default.nix index cc53957eee0dc..b194c780a3196 100644 --- a/pkgs/stdenv/cross/default.nix +++ b/pkgs/stdenv/cross/default.nix @@ -83,7 +83,10 @@ lib.init bootStages || p.isGenode; in f hostPlatform && !(f buildPlatform) - ) buildPackages.updateAutotoolsGnuConfigScriptsHook; + ) buildPackages.updateAutotoolsGnuConfigScriptsHook + ++ lib.optional ( + hostPlatform.isCygwin && !buildPlatform.isCygwin + ) buildPackages.cygwin.cygwinDllLinkHook; }) ); in diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index 75b3e674f6f9b..6b4f9acdc4b05 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -475,7 +475,6 @@ let nativeBuildInputs ++ optional separateDebugInfo' ../../build-support/setup-hooks/separate-debug-info.sh ++ optional isWindows ../../build-support/setup-hooks/win-dll-link.sh - ++ optional isCygwin ../../build-support/setup-hooks/cygwin-dll-link.sh ++ optional (isCygwin && canExecuteHostOnBuild) ../../build-support/setup-hooks/cygwin-dll-path.sh ++ optionals doCheck nativeCheckInputs ++ optionals doInstallCheck nativeInstallCheckInputs; From db641b83117f78a217df06a9cd38753497d57730 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 1 Jan 2026 12:12:22 -0400 Subject: [PATCH 111/119] workflows: add cygwin bootstrap release --- .github/workflows/cygwin-bootstrap.yml | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/cygwin-bootstrap.yml diff --git a/.github/workflows/cygwin-bootstrap.yml b/.github/workflows/cygwin-bootstrap.yml new file mode 100644 index 0000000000000..d0e4ec1a71bfd --- /dev/null +++ b/.github/workflows/cygwin-bootstrap.yml @@ -0,0 +1,31 @@ +name: Cygwin Bootstrap Release +on: + push: + tags: 'bootstrap/*' + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Create Release + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: | + tag="${GITHUB_REF_NAME}" + gh release create --draft "$tag" --title "$tag" + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + persist-credentials: false + - uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a + - uses: DeterminateSystems/magic-nix-cache-action@b4ad0b1e587499958543d6e793cd46510a21e7c2 + - name: Build + run: nix build -f pkgs/top-level/release-cross.nix bootstrapTools.x86_64-pc-cygwin.unpack -o unpack.nar.xz + - name: Upload + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: gh release upload "${GITHUB_REF_NAME}" unpack.nar.xz From e83bb8e019c77ea71065ac40ea175b77a72a552d Mon Sep 17 00:00:00 2001 From: David McFarland Date: Thu, 8 Jan 2026 19:12:32 -0400 Subject: [PATCH 112/119] nix-perl-bindings: fix cygwin build --- .../nix/modular/src/perl/package.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/tools/package-management/nix/modular/src/perl/package.nix b/pkgs/tools/package-management/nix/modular/src/perl/package.nix index d769d45d0f59a..ab80d78978c07 100644 --- a/pkgs/tools/package-management/nix/modular/src/perl/package.nix +++ b/pkgs/tools/package-management/nix/modular/src/perl/package.nix @@ -29,8 +29,20 @@ perl.pkgs.toPerlModule ( nix-store bzip2 libsodium + perl ]; + env = lib.optionalAttrs stdenv.hostPlatform.isCygwin { + NIX_CFLAGS_COMPILE = toString ( + lib.optionals stdenv.hostPlatform.isCygwin [ + # longjmp, siginfo_t + "-D_POSIX_C_SOURCE=199309L" + # putenv + "-D_XOPEN_SOURCE" + ] + ); + }; + # `perlPackages.Test2Harness` is marked broken for Darwin doCheck = !stdenv.isDarwin; From 7565e9180f23b2a6fb1474995302c555a6bd7b9b Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 13 Jan 2026 11:25:25 -0400 Subject: [PATCH 113/119] groff: fix cygwin build --- pkgs/by-name/gr/groff/package.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/gr/groff/package.nix b/pkgs/by-name/gr/groff/package.nix index 8e6913dbf8bb7..784a4a3909265 100644 --- a/pkgs/by-name/gr/groff/package.nix +++ b/pkgs/by-name/gr/groff/package.nix @@ -117,7 +117,9 @@ stdenv.mkDerivation rec { ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ "gl_cv_func_signbit=yes" - ]; + ] + # src/libs/libgroff/getopt.c:125:14: error: conflicting types for 'getenv'; have 'char *(void)' + ++ lib.optional stdenv.hostPlatform.isCygwin "CFLAGS=-std=gnu17"; makeFlags = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ # Trick to get the build system find the proper 'native' groff From 5a9e01ba54ac290b2e1e6573f5a6a724c54c0ba1 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 13 Jan 2026 11:25:33 -0400 Subject: [PATCH 114/119] opensp: fix cygwin build --- pkgs/by-name/op/opensp/package.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/by-name/op/opensp/package.nix b/pkgs/by-name/op/opensp/package.nix index 85985fc81490e..5280cdf0e2e6d 100644 --- a/pkgs/by-name/op/opensp/package.nix +++ b/pkgs/by-name/op/opensp/package.nix @@ -51,6 +51,10 @@ stdenv.mkDerivation rec { preConfigure = ""; + configureFlags = + # dcigettext.c:154:7: error: conflicting types for 'getcwd'; have 'char *(void)' + lib.optional stdenv.hostPlatform.isCygwin "CFLAGS=-std=gnu17"; + strictDeps = true; nativeBuildInputs = [ From 4a4224d357eedccf66ec89fb59ebbf9d7ef5d1c0 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 13 Jan 2026 12:51:17 -0400 Subject: [PATCH 115/119] treewide: undo changes causing rebuilds --- .../tools/package-management/nix/modular/src/perl/package.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/tools/package-management/nix/modular/src/perl/package.nix b/pkgs/tools/package-management/nix/modular/src/perl/package.nix index ab80d78978c07..1f348cb78a330 100644 --- a/pkgs/tools/package-management/nix/modular/src/perl/package.nix +++ b/pkgs/tools/package-management/nix/modular/src/perl/package.nix @@ -29,8 +29,8 @@ perl.pkgs.toPerlModule ( nix-store bzip2 libsodium - perl - ]; + ] + ++ lib.optional stdenv.hostPlatform.isCygwin perl; env = lib.optionalAttrs stdenv.hostPlatform.isCygwin { NIX_CFLAGS_COMPILE = toString ( From 72f975eb1c4714ef741483300112510df71f31a4 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sat, 24 Jan 2026 09:54:51 -0400 Subject: [PATCH 116/119] HACK: add test workflow --- .github/workflows/cygwin.yml | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/cygwin.yml diff --git a/.github/workflows/cygwin.yml b/.github/workflows/cygwin.yml new file mode 100644 index 0000000000000..a9ae42de60c8d --- /dev/null +++ b/.github/workflows/cygwin.yml @@ -0,0 +1,55 @@ +name: cygwin + +permissions: {} + +on: + push: + +jobs: + build-tarball: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + persist-credentials: false + - uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a + - uses: DeterminateSystems/magic-nix-cache-action@b4ad0b1e587499958543d6e793cd46510a21e7c2 + - name: build tarball + run: nix build -f nixos/release.nix cygwinTarball.x86_64-linux + - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 + with: + name: tarball + path: result + build-bootstrap: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + persist-credentials: false + - uses: DeterminateSystems/nix-installer-action@c5a866b6ab867e88becbed4467b93592bce69f8a + - uses: DeterminateSystems/magic-nix-cache-action@b4ad0b1e587499958543d6e793cd46510a21e7c2 + - name: build bootstrap + run: nix build -f pkgs/top-level/release-cross.nix bootstrapTools.x86_64-pc-cygwin.unpack -o unpack.nar.xz + - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 + with: + name: bootstrap + path: unpack.nar.xz + test: + runs-on: windows-latest + needs: build-tarball + steps: + - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 + with: + name: tarball + - name: install + run: tarball/install.ps1 cygwin + - name: get-info + shell: pwsh cygwin/cygwin.ps1 {0} + run: nix-info + # - name: build + # shell: pwsh cygwin/cygwin.ps1 {0} + # run: nix build --no-sandbox nixpkgs#hello + # - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 + # with: + # name: tarball + # path: result From 741f74ec00221d94cfc4841c8bcdfe632815f810 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 25 Jan 2026 10:57:11 -0400 Subject: [PATCH 117/119] xz: fix cygwin build --- pkgs/tools/compression/xz/default.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/tools/compression/xz/default.nix b/pkgs/tools/compression/xz/default.nix index ed8fc7a0bab60..6e23ddc862db3 100644 --- a/pkgs/tools/compression/xz/default.nix +++ b/pkgs/tools/compression/xz/default.nix @@ -33,7 +33,11 @@ stdenv.mkDerivation (finalAttrs: { "doc" ]; - configureFlags = lib.optional enableStatic "--disable-shared"; + configureFlags = + lib.optional enableStatic "--disable-shared" + # If cygpath isn't available, libtool tries to run cmd.exe for this test, + # but neither are in stdenv. + ++ lib.optional stdenv.buildPlatform.isCygwin "lt_cv_cmd_slashes=one"; enableParallelBuilding = true; doCheck = true; From 96f2ed136afdcce4f744cdadf5afe7b393461945 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Sun, 25 Jan 2026 23:13:26 -0400 Subject: [PATCH 118/119] zstd: fix cygwin build --- pkgs/tools/compression/zstd/default.nix | 29 ++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/pkgs/tools/compression/zstd/default.nix b/pkgs/tools/compression/zstd/default.nix index a014b652d313f..8cac630059244 100644 --- a/pkgs/tools/compression/zstd/default.nix +++ b/pkgs/tools/compression/zstd/default.nix @@ -13,7 +13,8 @@ enableStatic ? static, # these need to be ran on the host, thus disable when cross-compiling buildContrib ? stdenv.hostPlatform == stdenv.buildPlatform, - doCheck ? stdenv.hostPlatform == stdenv.buildPlatform, + # permissions tests are currently failing on cygwin + doCheck ? stdenv.hostPlatform == stdenv.buildPlatform && !stdenv.buildPlatform.isCygwin, nix-update-script, # for passthru.tests @@ -56,15 +57,23 @@ stdenv.mkDerivation (finalAttrs: { }) ]; - postPatch = lib.optionalString (!static) '' - substituteInPlace build/cmake/CMakeLists.txt \ - --replace 'message(SEND_ERROR "You need to build static library to build tests")' "" - substituteInPlace build/cmake/tests/CMakeLists.txt \ - --replace 'libzstd_static' 'libzstd_shared' - sed -i \ - "1aexport ${lib.optionalString stdenv.hostPlatform.isDarwin "DY"}LD_LIBRARY_PATH=$PWD/build_/lib" \ - tests/playTests.sh - ''; + postPatch = + let + libPath = + if stdenv.hostPlatform.isCygwin then + "PATH=$PWD/build_/lib:$PATH" + else + "${lib.optionalString stdenv.hostPlatform.isDarwin "DY"}LD_LIBRARY_PATH=$PWD/build_/lib"; + in + lib.optionalString (!static) '' + substituteInPlace build/cmake/CMakeLists.txt \ + --replace 'message(SEND_ERROR "You need to build static library to build tests")' "" + substituteInPlace build/cmake/tests/CMakeLists.txt \ + --replace 'libzstd_static' 'libzstd_shared' + sed -i \ + "1aexport ${libPath}" \ + tests/playTests.sh + ''; cmakeFlags = lib.attrsets.mapAttrsToList (name: value: "-DZSTD_${name}:BOOL=${if value then "ON" else "OFF"}") From fe35c10363077cce88e96f8dbd5bb0f91127ac76 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Mon, 26 Jan 2026 10:23:00 -0400 Subject: [PATCH 119/119] dumpnar: fix cygwin build --- pkgs/by-name/du/dumpnar/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/du/dumpnar/package.nix b/pkgs/by-name/du/dumpnar/package.nix index a2206f68096f4..1dcefb39242e8 100644 --- a/pkgs/by-name/du/dumpnar/package.nix +++ b/pkgs/by-name/du/dumpnar/package.nix @@ -17,7 +17,7 @@ stdenv.mkDerivation { installPhase = '' mkdir -p $out/bin - cp dumpnar $out/bin/ + cp dumpnar${stdenv.hostPlatform.extensions.executable} $out/bin/ ''; meta = {