From 021d5314701b18e145be50f7f602e2d9771d80b1 Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Fri, 7 Jun 2024 18:32:47 -0700 Subject: [PATCH] feat: stage2 gnugrep, gnupatch, update naming --- foundation/src/stages/stage1/gcc/default.nix | 2 +- .../src/stages/stage1/gnugrep/default.nix | 2 +- foundation/src/stages/stage1/gzip/default.nix | 2 +- foundation/src/stages/stage2/default.nix | 4 + .../src/stages/stage2/gnugrep/default.nix | 113 ++++++++++++++++++ .../src/stages/stage2/gnupatch/default.nix | 107 +++++++++++++++++ 6 files changed, 227 insertions(+), 3 deletions(-) create mode 100644 foundation/src/stages/stage2/gnugrep/default.nix create mode 100644 foundation/src/stages/stage2/gnupatch/default.nix diff --git a/foundation/src/stages/stage1/gcc/default.nix b/foundation/src/stages/stage1/gcc/default.nix index 26ba8d7..3dd17e2 100644 --- a/foundation/src/stages/stage1/gcc/default.nix +++ b/foundation/src/stages/stage1/gcc/default.nix @@ -18,7 +18,7 @@ in { options.aux.foundation.stages.stage1.gcc = { package = lib.options.create { type = lib.types.package; - description = "The package to use for gcc-cxx."; + description = "The package to use for gcc."; }; version = lib.options.create { diff --git a/foundation/src/stages/stage1/gnugrep/default.nix b/foundation/src/stages/stage1/gnugrep/default.nix index 5e14b3f..8aa3b5d 100644 --- a/foundation/src/stages/stage1/gnugrep/default.nix +++ b/foundation/src/stages/stage1/gnugrep/default.nix @@ -76,7 +76,7 @@ in { }; in builders.bash.boot.build { - name = "gnused-boot-${cfg.version}"; + name = "gnugrep-${cfg.version}"; meta = cfg.meta; deps.build.host = [ diff --git a/foundation/src/stages/stage1/gzip/default.nix b/foundation/src/stages/stage1/gzip/default.nix index e596d8b..7a8b840 100644 --- a/foundation/src/stages/stage1/gzip/default.nix +++ b/foundation/src/stages/stage1/gzip/default.nix @@ -64,7 +64,7 @@ in { package = let in builders.bash.boot.build { - name = "gnused-boot-${cfg.version}"; + name = "gzip-${cfg.version}"; meta = cfg.meta; deps.build.host = [ diff --git a/foundation/src/stages/stage2/default.nix b/foundation/src/stages/stage2/default.nix index c9768fe..9cbf8b0 100644 --- a/foundation/src/stages/stage2/default.nix +++ b/foundation/src/stages/stage2/default.nix @@ -13,6 +13,8 @@ in { ./diffutils ./findutils ./gawk + ./gnugrep + ./gnupatch ]; config = { @@ -26,6 +28,8 @@ in { stage2-diffutils = stage2.diffutils.package; stage2-findutils = stage2.findutils.package; stage2-gawk = stage2.gawk.package; + stage2-gnugrep = stage2.gnugrep.package; + stage2-gnupatch = stage2.gnupatch.package; }; }; }; diff --git a/foundation/src/stages/stage2/gnugrep/default.nix b/foundation/src/stages/stage2/gnugrep/default.nix new file mode 100644 index 0000000..c3b6c02 --- /dev/null +++ b/foundation/src/stages/stage2/gnugrep/default.nix @@ -0,0 +1,113 @@ +{ + lib, + config, +}: let + cfg = config.aux.foundation.stages.stage2.gnugrep; + + platform = config.aux.platform; + builders = config.aux.foundation.builders; + + stage1 = config.aux.foundation.stages.stage1; +in { + options.aux.foundation.stages.stage2.gnugrep = { + package = lib.options.create { + type = lib.types.package; + description = "The package to use for gnugrep."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of the package."; + }; + + src = lib.options.create { + type = lib.types.package; + description = "Source for the package."; + }; + + meta = { + description = lib.options.create { + type = lib.types.string; + description = "Description for the package."; + default.value = "GNU implementation of the Unix grep command"; + }; + + homepage = lib.options.create { + type = lib.types.string; + description = "Homepage for the package."; + default.value = "https://www.gnu.org/software/grep"; + }; + + license = lib.options.create { + # TODO: Add a proper type for licenses. + type = lib.types.attrs.any; + description = "License for the package."; + default.value = lib.licenses.gpl3Plus; + }; + + platforms = lib.options.create { + type = lib.types.list.of lib.types.string; + description = "Platforms the package supports."; + default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"]; + }; + + mainProgram = lib.options.create { + type = lib.types.string; + description = "The main program of the package."; + default.value = "grep"; + }; + }; + }; + + config = { + aux.foundation.stages.stage2.gnugrep = { + version = "3.11"; + + src = builtins.fetchurl { + url = "https://ftpmirror.gnu.org/grep/grep-${cfg.version}.tar.xz"; + sha256 = "HbKu3eidDepCsW2VKPiUyNFdrk4ZC1muzHj1qVEnbqs="; + }; + + package = builders.bash.build { + name = "gnugrep-static-${cfg.version}"; + meta = cfg.meta; + + deps.build.host = [ + stage1.gcc.package + stage1.musl.package + stage1.binutils.package + stage1.gnumake.package + stage1.gnused.package + stage1.gnugrep.package + stage1.gawk.package + stage1.diffutils.package + stage1.findutils.package + stage1.gnutar.package + stage1.xz.package + ]; + + script = '' + # Unpack + tar xf ${cfg.src} + cd grep-${cfg.version} + + # Configure + bash ./configure \ + --prefix=$out \ + --build=${platform.build} \ + --host=${platform.host} \ + CC=musl-gcc \ + CFLAGS=-static + + # Build + make -j $NIX_BUILD_CORES + + # Install + make -j $NIX_BUILD_CORES install + rm $out/bin/{egrep,fgrep} + + ''; + }; + }; + }; +} diff --git a/foundation/src/stages/stage2/gnupatch/default.nix b/foundation/src/stages/stage2/gnupatch/default.nix new file mode 100644 index 0000000..2042ec4 --- /dev/null +++ b/foundation/src/stages/stage2/gnupatch/default.nix @@ -0,0 +1,107 @@ +{ + lib, + config, +}: let + cfg = config.aux.foundation.stages.stage2.gnupatch; + + platform = config.aux.platform; + builders = config.aux.foundation.builders; + + stage1 = config.aux.foundation.stages.stage1; +in { + options.aux.foundation.stages.stage2.gnupatch = { + package = lib.options.create { + type = lib.types.package; + description = "The package to use for gnupatch."; + }; + + meta = { + description = lib.options.create { + type = lib.types.string; + description = "Description for the package."; + default.value = "GNU Patch, a program to apply differences to files."; + }; + + homepage = lib.options.create { + type = lib.types.string; + description = "Homepage for the package."; + default.value = "https://www.gnu.org/software/patch"; + }; + + license = lib.options.create { + # TODO: Add a proper type for licenses. + type = lib.types.attrs.any; + description = "License for the package."; + default.value = lib.licenses.gpl3Plus; + }; + + platforms = lib.options.create { + type = lib.types.list.of lib.types.string; + description = "Platforms the package supports."; + default.value = ["x86_64-linux" "aarch64-linux" "i686-linux"]; + }; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of the package."; + }; + + src = lib.options.create { + type = lib.types.package; + description = "Source for the package."; + }; + }; + + config = { + aux.foundation.stages.stage2.gnupatch = { + version = "2.7"; + + src = builtins.fetchurl { + url = "https://ftpmirror.gnu.org/patch/patch-${cfg.version}.tar.xz"; + sha256 = "XCyR/kFUKWISbwvhUKpPo0lIXPLtwMfqfbwky4FxEa4="; + }; + + package = builders.bash.build { + name = "gnupatch-static-${cfg.version}"; + + meta = cfg.meta; + src = cfg.src; + + deps.build.host = [ + stage1.gcc.package + stage1.musl.package + stage1.binutils.package + stage1.gnumake.package + stage1.gnused.package + stage1.gnugrep.package + stage1.gawk.package + stage1.diffutils.package + stage1.findutils.package + stage1.gnutar.package + stage1.xz.package + ]; + + script = '' + # Unpack + tar xf ${cfg.src} + cd patch-${cfg.version} + + # Configure + bash ./configure \ + --prefix=$out \ + --build=${platform.build} \ + --host=${platform.host} \ + CC=musl-gcc \ + CFLAGS=-static + + # Build + make -j $NIX_BUILD_CORES + + # Install + make -j $NIX_BUILD_CORES install + ''; + }; + }; + }; +}