From 84633e1eb869f0299b3cf2f34fc16bd99817865d Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Wed, 5 Jun 2024 04:32:04 -0700 Subject: [PATCH] feat: add nyacc --- foundation/flake.lock | 2 +- foundation/src/builders/file/text/default.nix | 17 ++-- foundation/src/builders/kaem/default.nix | 2 +- foundation/src/default.nix | 1 + foundation/src/stages/stage1/default.nix | 4 +- .../src/stages/stage1/nyacc/default.nix | 78 +++++++++++++++++++ lib/src/strings/default.nix | 9 +++ 7 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 foundation/src/stages/stage1/nyacc/default.nix diff --git a/foundation/flake.lock b/foundation/flake.lock index 6272b7f..04cc7e5 100644 --- a/foundation/flake.lock +++ b/foundation/flake.lock @@ -3,7 +3,7 @@ "lib": { "locked": { "lastModified": 1, - "narHash": "sha256-wgO96O9ALMMXtfBKuh9rYo3KIVq4nk8V7Cke4dg0MOk=", + "narHash": "sha256-gJODnE6vuEI+ifNgmXywIpma4/uVfRayYknVQjDJN2c=", "path": "../lib", "type": "path" }, diff --git a/foundation/src/builders/file/text/default.nix b/foundation/src/builders/file/text/default.nix index 957f8ed..88f6e4c 100644 --- a/foundation/src/builders/file/text/default.nix +++ b/foundation/src/builders/file/text/default.nix @@ -3,6 +3,8 @@ config, }: let system = config.aux.system; + + stage0 = config.aux.foundation.stages.stage0; in { options.aux.foundation.builders.file.text = { build = lib.options.create { @@ -22,6 +24,7 @@ in { extras ? {}, ... }: let + source = builtins.toFile "source" contents; script = '' target=''${out}''${destination} @@ -30,20 +33,18 @@ in { mkdir -p ''${out}''${destinationDir} '' + '' - cp ''${contentPath} ''${target} + cp ${source} ''${target} '' + lib.strings.when isExecutable '' chmod 555 ''${target} ''; package = builtins.derivation ( - (builtins.removeAttrs settings ["meta" "extras" "executable" "isExecutable"]) + (builtins.removeAttrs settings ["meta" "extras" "contents" "executable" "isExecutable"]) // { - inherit name system contents destination; + inherit name system destination; destinationDir = builtins.dirOf destination; - passAsFile = ["contents"]; - - builder = "${config.aux.foundation.stages.stage0.kaem.package}/bin/kaem"; + builder = "${stage0.kaem.package}/bin/kaem"; args = [ "--verbose" @@ -51,6 +52,10 @@ in { "--file" (builtins.toFile "write-text-to-file.kaem" script) ]; + + PATH = lib.paths.bin [ + stage0.mescc-tools-extra.package + ]; } ); in diff --git a/foundation/src/builders/kaem/default.nix b/foundation/src/builders/kaem/default.nix index 36f3304..3ec36f9 100644 --- a/foundation/src/builders/kaem/default.nix +++ b/foundation/src/builders/kaem/default.nix @@ -27,7 +27,7 @@ in { }: let package = builtins.derivation ( (builtins.removeAttrs settings ["meta" "extras" "executable" "env" "deps" "script"]) - env + // env // { inherit name system; diff --git a/foundation/src/default.nix b/foundation/src/default.nix index 3c4458e..c8efde9 100644 --- a/foundation/src/default.nix +++ b/foundation/src/default.nix @@ -6,6 +6,7 @@ let exports = ./exports; platform = ./platform; stage0 = ./stages/stage0; + stage1 = ./stages/stage1; system = ./system; }; in diff --git a/foundation/src/stages/stage1/default.nix b/foundation/src/stages/stage1/default.nix index 7c18f8e..7157d33 100644 --- a/foundation/src/stages/stage1/default.nix +++ b/foundation/src/stages/stage1/default.nix @@ -5,12 +5,14 @@ cfg = config.aux.foundation.stages.stage1; in { includes = [ - ./mes + ./nyacc + # ./mes ]; config = { exports = { packages = { + stage1-nyacc = config.aux.foundation.stages.stage1.nyacc.package; }; }; }; diff --git a/foundation/src/stages/stage1/nyacc/default.nix b/foundation/src/stages/stage1/nyacc/default.nix new file mode 100644 index 0000000..df01438 --- /dev/null +++ b/foundation/src/stages/stage1/nyacc/default.nix @@ -0,0 +1,78 @@ +{ + lib, + config, +}: let + cfg = config.aux.foundation.stages.stage1.nyacc; + + builders = config.aux.foundation.builders; + + stage0 = config.aux.foundation.stages.stage0; + + pname = "nyacc"; + version = "1.00.2"; +in { + options.aux.foundation.stages.stage1.nyacc = { + package = lib.options.create { + type = lib.types.package; + description = "The package to use for nyacc."; + }; + + meta = { + description = lib.options.create { + type = lib.types.string; + description = "Description for the package."; + default.value = "Modules for generating parsers and lexical analyzers."; + }; + + homepage = lib.options.create { + type = lib.types.string; + description = "Homepage for the package."; + default.value = "https://savannah.nongnu.org/projects/nyacc"; + }; + + 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.lgpl3Plus; + }; + + 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"]; + }; + }; + + src = lib.options.create { + type = lib.types.string; + description = "Source for the package."; + }; + }; + + config = { + aux.foundation.stages.stage1.nyacc = { + src = builtins.fetchurl { + url = "https://mirror.easyname.at/nongnu/nyacc/nyacc-${version}.tar.gz"; + sha256 = "065ksalfllbdrzl12dz9d9dcxrv97wqxblslngsc6kajvnvlyvpk"; + }; + + package = builders.kaem.build { + name = "${pname}-${version}"; + meta = cfg.meta; + + script = '' + ungz --file ${cfg.src} --output nyacc.tar + mkdir -p ''${out}/share + cd ''${out}/share + untar --file ''${NIX_BUILD_TOP}/nyacc.tar + ''; + + extras = { + # + guileModule = "${cfg.package}/share/${pname}-${version}/module"; + }; + }; + }; + }; +} diff --git a/lib/src/strings/default.nix b/lib/src/strings/default.nix index bc58904..572c2b9 100644 --- a/lib/src/strings/default.nix +++ b/lib/src/strings/default.nix @@ -130,6 +130,15 @@ lib: { builtins.match "[ \t\n]*" value != null; }; + ## Return a given string if a condition is true, otherwise return + ## an empty string. + ## + ## @type Bool -> String -> String + when = condition: value: + if condition + then value + else ""; + ## A table of ASCII characters mapped to their integer character code. ## ## @type Attrs