diff --git a/tidepool/npins/sources.json b/tidepool/npins/sources.json index 69857a6..9185dd6 100644 --- a/tidepool/npins/sources.json +++ b/tidepool/npins/sources.json @@ -20,9 +20,9 @@ }, "branch": "main", "submodules": false, - "revision": "137908ce11cc8a2b65f25ad81a9d6fdfa80cdc13", + "revision": "c55943c5e8197cbc2d0e506693fd5e7e3ea0a0c3", "url": null, - "hash": "sha256-xfEIYhQzCPzo9SWs7uSAw8SnkwAwCZusDCgyzNFCmZ8=" + "hash": "sha256-XBhIQ0XR1QabTgyo2c5wMk6xk/Bd3bCUlnTzRPcVfcw=" } }, "version": 6 diff --git a/tidepool/src/builders/basic.nix b/tidepool/src/builders/basic.nix index 268fc43..b0011d2 100644 --- a/tidepool/src/builders/basic.nix +++ b/tidepool/src/builders/basic.nix @@ -2,7 +2,7 @@ let cfg = config.builders.basic; - inherit (config) lib; + inherit (config) lib packages; inherit (config.internal.packages) foundation; in { @@ -82,7 +82,8 @@ in ); in builtins.concatStringsSep ":" ( - [ bins ] ++ (lib.lists.when (package.env ? PATH) [ package.env.PATH ]) + (lib.lists.when (package.env ? PATH) [ package.env.PATH ]) + ++ [ bins ] ); builder = cfg.executable; diff --git a/tidepool/src/lib/packages.nix b/tidepool/src/lib/packages.nix index 5133a94..15dd15e 100644 --- a/tidepool/src/lib/packages.nix +++ b/tidepool/src/lib/packages.nix @@ -1,4 +1,4 @@ -{ config }: +{ config }@global: let inherit (config) lib; in @@ -98,13 +98,13 @@ in contexts = builtins.map (dependency: dependency.context or { }) dependencies; result = lib.modules.run { args = { - global = config; + global = global.config; }; prefix = [ "" ]; - modules = builtins.map (context: { config = context; }) contexts ++ [ + modules = (builtins.map (context: { config = context; }) contexts) ++ [ { - freeform = lib.types.any; + freeform = lib.types.raw; options = config.packages.context.options // { target = lib.options.create { @@ -128,25 +128,7 @@ in description = "The collected dependencies."; writable = false; default.value = collected; - type = lib.types.submodule { - options = { - build = { - only = lib.options.create { type = lib.types.list.of lib.types.package; }; - build = lib.options.create { type = lib.types.list.of lib.types.package; }; - host = lib.options.create { type = lib.types.list.of lib.types.package; }; - target = lib.options.create { type = lib.types.list.of lib.types.package; }; - }; - host = { - only = lib.options.create { type = lib.types.list.of lib.types.package; }; - host = lib.options.create { type = lib.types.list.of lib.types.package; }; - target = lib.options.create { type = lib.types.list.of lib.types.package; }; - }; - target = { - only = lib.options.create { type = lib.types.list.of lib.types.package; }; - target = lib.options.create { type = lib.types.list.of lib.types.package; }; - }; - }; - }; + type = lib.types.raw; }; }; @@ -211,13 +193,15 @@ in path: let dependencies = lib.attrs.selectOrThrow path collected; - hooks = builtins.map ( - dependency: - let - getHooks = dependency.hooks or (lib.fp.const { }); - in - getHooks ctx - ) dependencies; + hooks = builtins.map + ( + dependency: + let + getHooks = dependency.hooks or (lib.fp.const { }); + in + getHooks ctx + ) + dependencies; in hooks; in @@ -289,14 +273,14 @@ in package = lib.packages.resolve alias; platform = { - build = lib.modules.override 10 build; - host = lib.modules.override 10 host; - target = lib.modules.override 10 target; + build = lib.modules.override 75 build; + host = lib.modules.override 75 host; + target = lib.modules.override 75 target; }; withPlatform = lib.modules.run { args = { - global = config; + global = global.config; }; modules = package.__modules__ ++ [ @@ -341,7 +325,7 @@ in withPackage = lib.modules.run { args = { - global = config; + global = global.config; }; modules = package.__modules__ ++ [ @@ -362,19 +346,50 @@ in ) ]; }; + + isSupported = lib.packages.supports package build host target; in - withPackage.config; + if isSupported then + withPackage.config + else + builtins.throw "Package `${ + lib.options.getIdentifier [ + "packages" + package.namespace + package.id + "versions" + package.version + ] + }` does not support the platform build=${build.double}, host=${host.double}, target=${target.double}"; + + supports = alias: build: host: target: + let + buildSystem = lib.systems.withBuildInfo build; + hostSystem = lib.systems.withBuildInfo host; + targetSystem = lib.systems.withBuildInfo target; + + package = lib.packages.resolve alias; + matches = builtins.filter + (platform: + platform.build.double == buildSystem.double && + platform.host.double == hostSystem.double && + platform.target.double == targetSystem.double) + package.platforms; + in + builtins.length matches > 0; create = namespace: name: alias: { ${namespace} = { ${name} = lib.modules.merge [ alias { - versions = builtins.mapAttrs (version: package: { - id = lib.modules.overrides.default name; - version = lib.modules.overrides.default version; - namespace = lib.modules.overrides.default namespace; - }) alias.versions; + versions = builtins.mapAttrs + (version: package: { + id = lib.modules.overrides.default name; + version = lib.modules.overrides.default version; + namespace = lib.modules.overrides.default namespace; + }) + alias.versions; } ]; }; diff --git a/tidepool/src/lib/types.nix b/tidepool/src/lib/types.nix index 8cd2881..bc547e9 100644 --- a/tidepool/src/lib/types.nix +++ b/tidepool/src/lib/types.nix @@ -274,7 +274,7 @@ in prefix = location; args = { - global = config; + global = global.config; }; modules = modules ++ [ @@ -297,7 +297,7 @@ in prefix = location; args = { - global = config; + global = global.config; }; modules = modules ++ [ @@ -418,8 +418,10 @@ in modules = config.__modules__ ++ normalized; result = lib.modules.run { + prefix = meta.prefix; + args = { - global = config; + global = global.config; }; modules = [ diff --git a/tidepool/src/packages/foundation/binutils/default.nix b/tidepool/src/packages/foundation/binutils/default.nix index 27402f3..7ee1c56 100644 --- a/tidepool/src/packages/foundation/binutils/default.nix +++ b/tidepool/src/packages/foundation/binutils/default.nix @@ -2,8 +2,10 @@ { config.packages.foundation.binutils = { stable = config.packages.foundation.binutils.versions."2.41-bootstrap"; + latest = config.packages.foundation.binutils.versions."2.41"; versions = { + "2.41" = ./versions/2.41.nix; "2.41-bootstrap" = ./versions/2.41-bootstrap.nix; }; }; diff --git a/tidepool/src/packages/foundation/binutils/patches/2.41-deterministic.patch b/tidepool/src/packages/foundation/binutils/patches/2.41-deterministic.patch new file mode 100644 index 0000000..bc72da5 --- /dev/null +++ b/tidepool/src/packages/foundation/binutils/patches/2.41-deterministic.patch @@ -0,0 +1,12 @@ +diff -ur orig/binutils-2.23.1/ld/ldlang.c binutils-2.23.1/ld/ldlang.c +--- orig/ld/ldlang.c ++++ new/ld/ldlang.c +@@ -3095,6 +3095,8 @@ + ldfile_output_machine)) + einfo (_("%P%F:%s: can not set architecture: %E\n"), name); + ++ link_info.output_bfd->flags |= BFD_DETERMINISTIC_OUTPUT; ++ + link_info.hash = bfd_link_hash_table_create (link_info.output_bfd); + if (link_info.hash == NULL) + einfo (_("%P%F: can not create hash table: %E\n")); diff --git a/tidepool/src/packages/foundation/binutils/versions/2.41.nix b/tidepool/src/packages/foundation/binutils/versions/2.41.nix new file mode 100644 index 0000000..3f7404f --- /dev/null +++ b/tidepool/src/packages/foundation/binutils/versions/2.41.nix @@ -0,0 +1,164 @@ +{ config, global }: + +let + inherit (global) lib packages builders mirrors; + inherit (global.internal.packages) foundation; + + # Stages as referred to in LFS: + # https://www.linuxfromscratch.org/lfs/view/development/partintro/toolchaintechnotes.html + isStage1 = config.platform.build.double == config.platform.host.double && config.platform.host.double != config.platform.target.double; + isStage2 = config.platform.build.double != config.platform.host.double && config.platform.host.double != config.platform.target.double; + isStage3 = config.platform.build.double != config.platform.host.double && config.platform.host.double == config.platform.target.double; + isStage4 = config.platform.build.double == config.platform.host.double && config.platform.host.double == config.platform.target.double; + + isBuildBootstrapped = config.platform.build.double == "i686-linux"; + isHostBootstrapped = config.platform.host.double == "i686-linux"; + + isFullyBootstrapped = isBuildBootstrapped && isHostBootstrapped; + + isCross = config.platform.build.double != config.platform.host.double; + + patches = [ + ../patches/2.41-deterministic.patch + ]; + + configureFlags = [ + "--prefix=${builtins.placeholder "out"}" + "--build=${config.platform.build.triple}" + "--host=${config.platform.host.triple}" + "--target=${config.platform.target.triple}" + + "--with-sysroot=/" + "--enable-deterministic-archives" + + "--disable-gprofng" + + # Turn on --enable-new-dtags by default to make the linker set + # RUNPATH instead of RPATH on binaries. This is important because + # RUNPATH can be overridden using LD_LIBRARY_PATH at runtime. + "--enable-new-dtags" + + # By default binutils searches $libdir for libraries. This brings in + # libbfd and libopcodes into a default visibility. Drop default lib + # path to force users to declare their use of these libraries. + "--with-lib-path=:" + + "--disable-multilib" + ]; +in +{ + config = { + meta = { + description = "Tools for manipulating binaries (linker, assembler, etc.)"; + homepage = "https://www.gnu.org/software/binutils"; + license = lib.licenses.gpl3Plus; + }; + + platforms = [ + { build = "i686-linux"; host = "i686-linux"; target = "i686-linux"; } + { build = "i686-linux"; host = "i686-linux"; target = "x86_64-linux"; } + ]; + + builder = builders.basic; + + src = builtins.fetchurl { + url = "${mirrors.gnu}/binutils/binutils-${config.version}.tar.xz"; + sha256 = "rppXieI0WeWWBuZxRyPy0//DHAMXQZHvDQFb3wYAdFA="; + }; + + deps = { + build = { + only = { + inherit (packages.foundation) + diffutils + findutils + gawk + gnugrep + gnumake + gnupatch + gnused + gnutar + xz; + }; + + host = { + binutils = if isFullyBootstrapped then + packages.foundation.binutils.versions."2.41-bootstrap" + else if isStage4 then + packages.foundation.binutils.versions."2.41".extend { + platform = { + build = lib.modules.force "i686-linux"; + }; + } + else if isStage3 then + packages.foundation.binutils.versions."2.41".extend { + platform = { + build = lib.modules.force "i686-linux"; + host = lib.modules.force "i686-linux"; + }; + } + else if isStage2 then + packages.foundation.binutils.versions."2.41".extend { + platform = { + build = lib.modules.force "i686-linux"; + host = lib.modules.force "i686-linux"; + }; + } + else if isStage1 then + packages.foundation.binutils.versions."2.41".extend { + platform = { + build = lib.modules.force "i686-linux"; + host = lib.modules.force "i686-linux"; + }; + } + else + builtins.throw "Unsupported stage for binutils: build=${config.platform.build.double}, host=${config.platform.host.double}, target=${config.platform.target.double}"; + + gcc = + if isFullyBootstrapped then + if config.platform.target.double == config.platform.host.double then + packages.foundation.gcc.versions."13.2.0-bootstrap" + else + packages.foundation.gcc.versions."13.2.0-stage1" + else + packages.foundation.gcc.versions."13.2.0"; + }; + }; + }; + + env = { + CFLAGS = "-O2 -static -fno-pie"; + LDFLAGS = "--static -no-pie"; + }; + + phases = { + unpack = '' + tar xf ${config.src} + cd binutils-${config.version} + ''; + + patch = '' + ${lib.strings.concatMapSep "\n" (file: "patch -Np1 -i ${file}") patches} + ''; + + configure = '' + echo "build: ${config.platform.build.double} host: ${config.platform.host.double} target: ${config.platform.target.double}" + + echo "int main() { return 0; }" > dummy.c + gcc -o dummy dummy.c + readelf -l ./dummy | sed -n '/INTERP/,+2p' + ./dummy + + bash ./configure ${builtins.concatStringsSep " " configureFlags} + ''; + + build = '' + make -j $NIX_BUILD_CORES + ''; + + install = '' + make -j $NIX_BUILD_CORES install-strip + ''; + }; + }; +} diff --git a/tidepool/src/packages/foundation/default.nix b/tidepool/src/packages/foundation/default.nix index 676d0cb..cecab3a 100644 --- a/tidepool/src/packages/foundation/default.nix +++ b/tidepool/src/packages/foundation/default.nix @@ -19,6 +19,7 @@ ./gnutar ./gzip ./linux-headers + ./musl ./patchelf ./python ./xz diff --git a/tidepool/src/packages/foundation/gcc/default.nix b/tidepool/src/packages/foundation/gcc/default.nix index 754a7da..d161a5c 100644 --- a/tidepool/src/packages/foundation/gcc/default.nix +++ b/tidepool/src/packages/foundation/gcc/default.nix @@ -2,8 +2,11 @@ { config.packages.foundation.gcc = { stable = config.packages.foundation.gcc.versions."13.2.0-bootstrap"; + latest = config.packages.foundation.gcc.versions."13.2.0-stage2"; versions = { + "13.2.0-stage2" = ./versions/13.2.0-stage2.nix; + "13.2.0-stage1" = ./versions/13.2.0-stage1.nix; "13.2.0-bootstrap" = ./versions/13.2.0-bootstrap.nix; }; }; diff --git a/tidepool/src/packages/foundation/gcc/patches/libstdc++-target.patch b/tidepool/src/packages/foundation/gcc/patches/libstdc++-target.patch new file mode 100644 index 0000000..2fa8883 --- /dev/null +++ b/tidepool/src/packages/foundation/gcc/patches/libstdc++-target.patch @@ -0,0 +1,33 @@ +# From https://github.com/NixOS/nixpkgs/blob/nixos-24.05/pkgs/development/compilers/gcc/patches/libstdc%2B%2B-target.patch +Patch to make the target libraries 'configure' scripts find the proper CPP. +I noticed that building the mingw32 cross compiler. +Looking at the build script for mingw in archlinux, I think that only nixos +needs this patch. I don't know why. +diff --git a/Makefile.in b/Makefile.in +index 93f66b6..d691917 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -266,6 +266,7 @@ BASE_TARGET_EXPORTS = \ + AR="$(AR_FOR_TARGET)"; export AR; \ + AS="$(COMPILER_AS_FOR_TARGET)"; export AS; \ + CC="$(CC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CC; \ ++ CPP="$(CC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS -E"; export CC; \ + CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \ + CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \ + CPPFLAGS="$(CPPFLAGS_FOR_TARGET)"; export CPPFLAGS; \ +@@ -291,11 +292,13 @@ BASE_TARGET_EXPORTS = \ + RAW_CXX_TARGET_EXPORTS = \ + $(BASE_TARGET_EXPORTS) \ + CXX_FOR_TARGET="$(RAW_CXX_FOR_TARGET)"; export CXX_FOR_TARGET; \ +- CXX="$(RAW_CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; ++ CXX="$(RAW_CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; \ ++ CXXCPP="$(RAW_CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS -E"; export CXX; + + NORMAL_TARGET_EXPORTS = \ + $(BASE_TARGET_EXPORTS) \ +- CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; ++ CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; \ ++ CXXCPP="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS -E"; export CXX; + + # Where to find GMP + HOST_GMPLIBS = @gmplibs@ \ No newline at end of file diff --git a/tidepool/src/packages/foundation/gcc/versions/13.2.0-bootstrap.nix b/tidepool/src/packages/foundation/gcc/versions/13.2.0-bootstrap.nix index 333b03f..c386e4b 100644 --- a/tidepool/src/packages/foundation/gcc/versions/13.2.0-bootstrap.nix +++ b/tidepool/src/packages/foundation/gcc/versions/13.2.0-bootstrap.nix @@ -1,7 +1,7 @@ { config, global }: let - inherit (global) lib packages builders; + inherit (global) lib packages builders mirrors; inherit (global.internal.packages) foundation; in { config = { diff --git a/tidepool/src/packages/foundation/gcc/versions/13.2.0-stage1.nix b/tidepool/src/packages/foundation/gcc/versions/13.2.0-stage1.nix new file mode 100644 index 0000000..9aef380 --- /dev/null +++ b/tidepool/src/packages/foundation/gcc/versions/13.2.0-stage1.nix @@ -0,0 +1,274 @@ +{ config, global }: + +let + inherit (global) lib packages builders mirrors; + inherit (global.internal.packages) foundation; + + isBuildBootstrapped = config.platform.build.double == "i686-linux"; + isHostBootstrapped = config.platform.host.double == "i686-linux"; + + isFullyBootstrapped = isBuildBootstrapped && isHostBootstrapped; + + version = lib.strings.removeSuffix "-stage1" config.version; + + prefix = if config.platform.build.triple != config.platform.target.triple + then "${config.platform.target.triple}-" + else ""; + + patches = [ + ../patches/libstdc++-target.patch + ]; + + gccFlags = [ + "-Wl,-dynamic-linker" + "-Wl,${config.deps.build.host.glibc.package}/lib/ld-linux${ + lib.strings.when ( + (lib.systems.withBuildInfo config.platform.target).isx86 + && (lib.systems.withBuildInfo config.platform.target).is64bit + ) "-x86-64" + }.so.2" + "-B${config.deps.build.host.glibc.package}/lib" + "-static" + "-no-pie" + ]; + + configureFlags = [ + "--prefix=${builtins.placeholder "out"}" + "--build=${config.platform.build.triple}" + "--host=${config.platform.host.triple}" + "--target=${config.platform.target.triple}" + "--with-native-system-header-dir=/include" + "--with-sysroot=${foundation.stage1-musl}" + "--enable-languages=c,c++" + "--disable-bootstrap" + "--disable-libsanitizer" + "--disable-lto" + "--disable-multilib" + "--disable-plugin" + "CFLAGS=-static" + "CXXFLAGS=-static" + "LDFLAGS=-static" + ]; +in +{ + options = { + cc = { + src = lib.options.create { + type = lib.types.derivation; + description = "The cc source for the package."; + }; + }; + + gmp = { + src = lib.options.create { + type = lib.types.derivation; + description = "The gmp source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of gmp."; + }; + }; + + mpfr = { + src = lib.options.create { + type = lib.types.derivation; + description = "The mpfr source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of mpfr."; + }; + }; + + mpc = { + src = lib.options.create { + type = lib.types.derivation; + description = "The mpc source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of mpc."; + }; + }; + + isl = { + src = lib.options.create { + type = lib.types.derivation; + description = "The isl source for the package."; + }; + version = lib.options.create { + type = lib.types.string; + description = "Version of isl."; + }; + }; + }; + + config = { + meta = { + description = "GNU Compiler Collection."; + homepage = "https://gcc.gnu.org"; + license = lib.licenses.gpl3Plus; + }; + + platforms = [ + { build = "i686-linux"; host = "i686-linux"; target = "x86_64-linux"; } + ]; + + builder = builders.basic; + + src = builtins.fetchurl { + url = "${mirrors.gnu}/gcc/gcc-${version}/gcc-${version}.tar.xz"; + sha256 = "4nXnZEKmBnNBon8Exca4PYYTFEAEwEE1KIY9xrXHQ9o="; + }; + + gmp = { + version = "6.3.0"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/gmp/gmp-${config.gmp.version}.tar.xz"; + sha256 = "o8K4AgG4nmhhb0rTC8Zq7kknw85Q4zkpyoGdXENTiJg="; + }; + }; + + mpfr = { + version = "4.2.1"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/mpfr/mpfr-${config.mpfr.version}.tar.xz"; + sha256 = "J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I="; + }; + }; + + mpc = { + version = "1.3.1"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/mpc/mpc-${config.mpc.version}.tar.gz"; + sha256 = "q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg="; + }; + }; + + isl = { + version = "0.24"; + src = builtins.fetchurl { + url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${config.isl.version}.tar.bz2"; + sha256 = "/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA="; + }; + }; + + deps = { + build = { + only = { + inherit (packages.foundation) + bzip2 + diffutils + findutils + gawk + gnugrep + gnumake + gnupatch + gnused + gnutar + gzip + xz; + + binutilsBuild = packages.foundation.binutils.versions."2.41".extend { + platform = { + target = lib.modules.overrides.force config.platform.build; + }; + }; + + binutilsTarget = packages.foundation.binutils.versions."2.41".extend { + platform = { + target = lib.modules.overrides.force config.platform.target; + }; + }; + + gcc = + if isFullyBootstrapped then + packages.foundation.gcc.versions."13.2.0-bootstrap" + else + packages.foundation.gcc.versions."13.2.0".extend { + platform = { + build = lib.modules.overrides.force "i686-linux"; + host = lib.modules.overrides.force "i686-linux"; + }; + }; + }; + + host = { + glibc = packages.foundation.glibc.versions."2.38".extend { + platform = { + build = lib.modules.overrides.force config.platform.build; + host = lib.modules.overrides.force config.platform.build; + target = lib.modules.overrides.force config.platform.target; + }; + }; + }; + }; + }; + + env = { + CC = "gcc -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so"; + CXX = "g++ -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so"; + CFLAGS_FOR_TARGET = "-Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so"; + LIBRARY_PATH = "${foundation.stage1-musl}/lib"; + }; + + hooks = context: { + "aux:gcc:env" = lib.dag.entry.between [ "unpack" ] [ "configure" ] '' + export CC='${config.package}/bin/${prefix}gcc ${builtins.concatStringsSep " " gccFlags}' + export CXX='${config.package}/bin/${prefix}g++ ${builtins.concatStringsSep " " gccFlags}' + export CC_FOR_TARGET=$CC + export CXX_FOR_TARGET=$CXX + export CC_FOR_BUILD=$CC + export CXX_FOR_BUILD=$CXX + alias gcc='$CC' + alias g++='$CXX' + ''; + }; + + phases = { + unpack = '' + # Unpack + tar xf ${config.src} + tar xf ${config.gmp.src} + tar xf ${config.mpfr.src} + tar xf ${config.mpc.src} + tar xf ${config.isl.src} + cd gcc-${version} + + ln -s ../gmp-${config.gmp.version} gmp + ln -s ../mpfr-${config.mpfr.version} mpfr + ln -s ../mpc-${config.mpc.version} mpc + ln -s ../isl-${config.isl.version} isl + ''; + + patch = '' + ${lib.strings.concatMapSep "\n" (file: "patch -Np1 -i ${file}") patches} + + # force musl even if host triple is gnu + sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host + ''; + + configure = '' + # Configure + bash ./configure ${builtins.concatStringsSep " " configureFlags} + ''; + + build = '' + # Build + make -j $NIX_BUILD_CORES V=1 all-gcc + ''; + + install = '' + # Install + ${lib.strings.when ((lib.systems.withBuildInfo config.platform.host).is64bit) '' + ln -s lib $out/lib64 + ''} + make -j $NIX_BUILD_CORES install-gcc + ''; + }; + }; +} diff --git a/tidepool/src/packages/foundation/gcc/versions/13.2.0-stage2.nix b/tidepool/src/packages/foundation/gcc/versions/13.2.0-stage2.nix new file mode 100644 index 0000000..9a6056f --- /dev/null +++ b/tidepool/src/packages/foundation/gcc/versions/13.2.0-stage2.nix @@ -0,0 +1,267 @@ +{ config, global }: + +let + inherit (global) lib packages builders mirrors; + inherit (global.internal.packages) foundation; + + isBuildBootstrapped = config.platform.build.double == "i686-linux"; + isHostBootstrapped = config.platform.host.double == "i686-linux"; + + isFullyBootstrapped = isBuildBootstrapped && isHostBootstrapped; + + version = lib.strings.removeSuffix "-stage2" config.version; + + patches = [ + ../patches/libstdc++-target.patch + ]; + + gccFlags = [ + # "-Wl,-dynamic-linker" + # "-Wl,${config.deps.build.host.glibc.package}/lib/ld-linux${ + # lib.strings.when ( + # (lib.systems.withBuildInfo config.platform.target).isx86 + # && (lib.systems.withBuildInfo config.platform.target).is64bit + # ) "-x86-64" + # }.so.2" + # "-B${config.deps.build.host.glibc.package}/lib" + # "-static" + # "-no-pie" + ]; + + configureFlags = [ + "--prefix=${builtins.placeholder "out"}" + "--build=${config.platform.build.triple}" + "--host=${config.platform.host.triple}" + "--target=${config.platform.target.triple}" + "--with-native-system-header-dir=/include" + "--with-sysroot=${foundation.stage1-musl}" + "--enable-languages=c,c++" + "--disable-bootstrap" + "--disable-libsanitizer" + "--disable-lto" + "--disable-multilib" + "--disable-plugin" + "CFLAGS=-static" + "CXXFLAGS=-static" + "LDFLAGS=-static" + ]; +in +{ + options = { + cc = { + src = lib.options.create { + type = lib.types.derivation; + description = "The cc source for the package."; + }; + }; + + gmp = { + src = lib.options.create { + type = lib.types.derivation; + description = "The gmp source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of gmp."; + }; + }; + + mpfr = { + src = lib.options.create { + type = lib.types.derivation; + description = "The mpfr source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of mpfr."; + }; + }; + + mpc = { + src = lib.options.create { + type = lib.types.derivation; + description = "The mpc source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of mpc."; + }; + }; + + isl = { + src = lib.options.create { + type = lib.types.derivation; + description = "The isl source for the package."; + }; + version = lib.options.create { + type = lib.types.string; + description = "Version of isl."; + }; + }; + }; + + config = { + meta = { + description = "GNU Compiler Collection."; + homepage = "https://gcc.gnu.org"; + license = lib.licenses.gpl3Plus; + }; + + platforms = [ + { build = "i686-linux"; host = "x86_64-linux"; target = "x86_64-linux"; } + ]; + + builder = builders.basic; + + src = builtins.fetchurl { + url = "${mirrors.gnu}/gcc/gcc-${version}/gcc-${version}.tar.xz"; + sha256 = "4nXnZEKmBnNBon8Exca4PYYTFEAEwEE1KIY9xrXHQ9o="; + }; + + gmp = { + version = "6.3.0"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/gmp/gmp-${config.gmp.version}.tar.xz"; + sha256 = "o8K4AgG4nmhhb0rTC8Zq7kknw85Q4zkpyoGdXENTiJg="; + }; + }; + + mpfr = { + version = "4.2.1"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/mpfr/mpfr-${config.mpfr.version}.tar.xz"; + sha256 = "J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I="; + }; + }; + + mpc = { + version = "1.3.1"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/mpc/mpc-${config.mpc.version}.tar.gz"; + sha256 = "q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg="; + }; + }; + + isl = { + version = "0.24"; + src = builtins.fetchurl { + url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${config.isl.version}.tar.bz2"; + sha256 = "/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA="; + }; + }; + + deps = { + build = { + only = { + inherit (packages.foundation) + bzip2 + diffutils + findutils + gawk + gnugrep + gnumake + gnupatch + gnused + gnutar + gzip + xz; + + # binutilsBuild = packages.foundation.binutils.versions."2.41".extend { + # platform = { + # target = lib.modules.overrides.force config.platform.build; + # }; + # }; + + binutilsHost = packages.foundation.binutils.versions."2.41".extend { + platform = { + target = lib.modules.overrides.force config.platform.host; + }; + }; + + gcc = packages.foundation.gcc.versions."13.2.0-stage1".extend { + platform = { + build = lib.modules.overrides.force "i686-linux"; + host = lib.modules.overrides.force "i686-linux"; + target = lib.modules.overrides.force config.platform.host; + }; + }; + }; + }; + }; + + env = { + CC = "gcc -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so"; + CXX = "g++ -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so"; + CFLAGS_FOR_TARGET = "-Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so"; + LIBRARY_PATH = "${foundation.stage1-musl}/lib"; + + PATH = "${config.deps.build.only.binutilsHost.package}/${config.platform.host.triple}/bin"; + }; + + hooks = context: { + "aux:gcc:env" = lib.dag.entry.between [ "unpack" ] [ "configure" ] '' + export CC='${config.package}/bin/gcc ${builtins.concatStringsSep " " gccFlags}' + export CXX='${config.package}/bin/g++ ${builtins.concatStringsSep " " gccFlags}' + export CC_FOR_TARGET=$CC + export CXX_FOR_TARGET=$CXX + export CC_FOR_BUILD=$CC + export CXX_FOR_BUILD=$CXX + alias gcc='$CC' + alias g++='$CXX' + ''; + }; + + phases = { + unpack = '' + # Unpack + tar xf ${config.src} + tar xf ${config.gmp.src} + tar xf ${config.mpfr.src} + tar xf ${config.mpc.src} + tar xf ${config.isl.src} + cd gcc-${version} + + ln -s ../gmp-${config.gmp.version} gmp + ln -s ../mpfr-${config.mpfr.version} mpfr + ln -s ../mpc-${config.mpc.version} mpc + ln -s ../isl-${config.isl.version} isl + ''; + + patch = '' + ${lib.strings.concatMapSep "\n" (file: "patch -Np1 -i ${file}") patches} + + # force musl even if host triple is gnu + sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host + ''; + + configure = '' + echo $PATH + ls -la ${config.deps.build.only.gcc.package}/bin + echo "int main() { return 0; }" > dummy.c + + gcc -o dummy dummy.c + ls -l dummy + exit 1 + + # Configure + bash ./configure ${builtins.concatStringsSep " " configureFlags} + ''; + + build = '' + # Build + make -j $NIX_BUILD_CORES V=1 all-gcc + ''; + + install = '' + # Install + ${lib.strings.when ((lib.systems.withBuildInfo config.platform.host).is64bit) '' + ln -s lib $out/lib64 + ''} + make -j $NIX_BUILD_CORES install-gcc + ''; + }; + }; +} diff --git a/tidepool/src/packages/foundation/glibc/default.nix b/tidepool/src/packages/foundation/glibc/default.nix index 5ccbe90..8f9c6be 100644 --- a/tidepool/src/packages/foundation/glibc/default.nix +++ b/tidepool/src/packages/foundation/glibc/default.nix @@ -4,6 +4,7 @@ stable = config.packages.foundation.glibc.versions."2.38-bootstrap"; versions = { + "2.38" = ./versions/2.38.nix; "2.38-bootstrap" = ./versions/2.38-bootstrap.nix; }; }; diff --git a/tidepool/src/packages/foundation/glibc/versions/2.38.nix b/tidepool/src/packages/foundation/glibc/versions/2.38.nix new file mode 100644 index 0000000..eb65406 --- /dev/null +++ b/tidepool/src/packages/foundation/glibc/versions/2.38.nix @@ -0,0 +1,109 @@ +{ config, global }: + +let + inherit (global) lib packages builders mirrors; + inherit (global.internal.packages) foundation; + + isBuildBootstrapped = config.platform.build.double == "i686-linux"; + isHostBootstrapped = config.platform.host.double == "i686-linux"; + + isFullyBootstrapped = isBuildBootstrapped && isHostBootstrapped; + + isCross = config.platform.build.double != config.platform.host.double; +in +{ + config = { + meta = { + description = "The GNU C Library."; + homepage = "https://www.gnu.org/software/libc"; + license = lib.licenses.lgpl2Plus; + }; + + platforms = [ + { build = "i686-linux"; host = "i686-linux"; target = "i686-linux"; } + { build = "i686-linux"; host = "i686-linux"; target = "x86_64-linux"; } + ]; + + builder = builders.basic; + + src = builtins.fetchurl { + url = "${mirrors.gnu}/libc/glibc-${config.version}.tar.xz"; + sha256 = "+4KZiZiyspllRnvBtp0VLpwwfSzzAcnq+0VVt3DvP9I="; + }; + + deps = { + build = { + only = { + inherit (packages.foundation) + bison + diffutils + findutils + gawk + gnugrep + gnumake + gnupatch + gnused + gnutar + gzip + python + xz; + }; + + host = { + inherit (packages.foundation) linux-headers; + + binutils = + if isFullyBootstrapped then + packages.foundation.binutils.versions."2.41-bootstrap" + else + packages.foundation.binutils.versions."2.41"; + + gcc = + if isFullyBootstrapped then + packages.foundation.gcc.versions."13.2.0-bootstrap" + else if config.platform.build.double == "i686-linux" then + packages.foundation.gcc.versions."13.2.0-stage1" + else + packages.foundation.gcc.versions."13.2.0"; + }; + }; + }; + + phases = { + unpack = '' + tar xf ${config.src} + cd glibc-${config.version} + ''; + + configure = '' + mkdir build + cd build + + bash ../configure \ + --prefix=$out \ + --build=${config.platform.build.triple} \ + --host=${config.platform.host.triple} \ + --with-headers=${config.deps.build.host.linux-headers.package}/include \ + --with-binutils=${ + if isFullyBootstrapped then + foundation.stage2-binutils + else if isCross then + config.deps.build.host.binutils.package + else + config.deps.build.only.binutils.package + }${lib.strings.when (isCross) "/${config.platform.target.triple}"}/bin + ''; + + build = '' + # Build + make -j $NIX_BUILD_CORES + ''; + + install = '' + # Install + make -j $NIX_BUILD_CORES install + ln -sv $(ls -d ${config.deps.build.host.linux-headers.package}/include/* | grep -v scsi\$) $out/include/ + ''; + }; + }; +} diff --git a/tidepool/src/packages/foundation/musl/default.nix b/tidepool/src/packages/foundation/musl/default.nix new file mode 100644 index 0000000..a25d78d --- /dev/null +++ b/tidepool/src/packages/foundation/musl/default.nix @@ -0,0 +1,11 @@ +{ config }: +{ + config.packages.foundation.musl = { + stable = config.packages.foundation.musl.versions."1.2.4-bootstrap"; + + versions = { + "1.2.4" = ./versions/1.2.4.nix; + "1.2.4-bootstrap" = ./versions/1.2.4-bootstrap.nix; + }; + }; +} diff --git a/tidepool/src/packages/foundation/musl/patches/1.2.4-always-flush.patch b/tidepool/src/packages/foundation/musl/patches/1.2.4-always-flush.patch new file mode 100644 index 0000000..fcbaae1 --- /dev/null +++ b/tidepool/src/packages/foundation/musl/patches/1.2.4-always-flush.patch @@ -0,0 +1,12 @@ +diff --git src/env/__libc_start_main.c src/env/__libc_start_main.c +index 8fbe526..9476c22 100644 +--- src/env/__libc_start_main.c ++++ src/env/__libc_start_main.c +@@ -91,6 +91,7 @@ static int libc_start_main_stage2(int (*main)(int,char **,char **), int argc, ch + __libc_start_init(); + + /* Pass control to the application */ ++ setbuf(stdout, NULL); + exit(main(argc, argv, envp)); + return 0; + } diff --git a/tidepool/src/packages/foundation/musl/versions/1.2.4-bootstrap.nix b/tidepool/src/packages/foundation/musl/versions/1.2.4-bootstrap.nix new file mode 100644 index 0000000..43393a5 --- /dev/null +++ b/tidepool/src/packages/foundation/musl/versions/1.2.4-bootstrap.nix @@ -0,0 +1,25 @@ +{ config, global }: + +let + inherit (global) lib packages builders; + inherit (global.internal.packages) foundation; +in +{ + config = { + meta = { + description = "An efficient, small, quality libc implementation."; + homepage = "https://musl.libc.org"; + license = lib.licenses.mit; + }; + + platforms = [ + { build = "i686-linux"; host = "i686-linux"; target = "i686-linux"; } + ]; + + builder = builders.passthrough // { + settings = { + derivation = foundation.stage1-musl; + }; + }; + }; +} diff --git a/tidepool/src/packages/foundation/musl/versions/1.2.4.nix b/tidepool/src/packages/foundation/musl/versions/1.2.4.nix new file mode 100644 index 0000000..6e14f1b --- /dev/null +++ b/tidepool/src/packages/foundation/musl/versions/1.2.4.nix @@ -0,0 +1,89 @@ +{ config, global }: + +let + inherit (global) lib packages builders; + inherit (global.internal.packages) foundation; +in +{ + config = { + meta = { + description = "An efficient, small, quality libc implementation."; + homepage = "https://musl.libc.org"; + license = lib.licenses.mit; + }; + + platforms = [ + { build = "i686-linux"; host = "i686-linux"; target = "i686-linux"; } + { build = "i686-linux"; host = "i686-linux"; target = "x86_64-linux"; } + ]; + + builder = builders.basic; + + src = builtins.fetchurl { + url = "https://musl.libc.org/releases/musl-${config.version}.tar.gz"; + sha256 = "ejXq4z1TcqfA2hGI3nmHJvaIJVE7euPr6XqqpSEU8Dk="; + }; + + deps = { + build = { + only = { + inherit (packages.foundation) + gcc + binutils + gnumake + gnused + gnugrep + gnutar + gzip; + }; + + host = { + inherit (packages.foundation) + bash; + }; + }; + }; + + phases = { + unpack = '' + # Unpack + tar xzf ${config.src} + cd musl-${config.version} + ''; + + patch = '' + # Patch + # https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a3-intermediate-musl.nix + sed -i 's|/bin/sh|${config.deps.build.host.bash.package}/bin/bash|' \ + tools/*.sh + # patch popen/system to search in PATH instead of hardcoding /bin/sh + sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \ + src/stdio/popen.c src/process/system.c + sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\ + src/misc/wordexp.c + ''; + + configure = '' + # Configure + bash ./configure \ + --prefix=$out \ + --build=${config.platform.build.triple} \ + --host=${config.platform.host.triple} \ + --syslibdir=$out/lib \ + --enable-wrapper + ''; + + build = '' + # Build + make -j $NIX_BUILD_CORES + ''; + + install = '' + # Install + make -j $NIX_BUILD_CORES install + sed -i 's|/bin/sh|${config.deps.build.host.bash.package}/bin/bash|' $out/bin/* + ln -s ../lib/libc.so $out/bin/ldd + ''; + }; + }; +}