From 41c56eb788abfbfe3b0ab63236517696b04c60e8 Mon Sep 17 00:00:00 2001 From: DavHau Date: Sun, 26 Mar 2023 16:35:40 +0800 Subject: [PATCH] feat(legacy): make translator, builder, etc.. configurable --- src/modules/flake-parts/makeOutputsArgs.nix | 2 +- .../drv-parts/dream2nix-legacy/default.nix | 10 ++++--- .../drv-parts/dream2nix-legacy/interface.nix | 27 +++++++++++++++++++ v1/nix/modules/drvs/ripgrep/default.nix | 10 ++++--- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/modules/flake-parts/makeOutputsArgs.nix b/src/modules/flake-parts/makeOutputsArgs.nix index bbcdb642..4f919a52 100644 --- a/src/modules/flake-parts/makeOutputsArgs.nix +++ b/src/modules/flake-parts/makeOutputsArgs.nix @@ -25,7 +25,7 @@ # TODO(antotocar34) make a smart enum of all available translators conditional on the given the subsystem? Is this possible? translator = mkOption { - description = "Translators to use"; + description = "Translator to use"; example = ["yarn-lock" "package-json"]; type = t.str; }; diff --git a/v1/nix/modules/drv-parts/dream2nix-legacy/default.nix b/v1/nix/modules/drv-parts/dream2nix-legacy/default.nix index 674a74bc..95930d67 100644 --- a/v1/nix/modules/drv-parts/dream2nix-legacy/default.nix +++ b/v1/nix/modules/drv-parts/dream2nix-legacy/default.nix @@ -8,6 +8,8 @@ }: let l = lib // builtins; + cfg = config.legacy; + pkgs = drv-parts.inputs.nixpkgs.legacyPackages.x86_64-linux; dlib = @@ -77,7 +79,7 @@ config.pkgs = pkgs; }; - buildersBySubsystem.rust.default = import ../../../../../src/subsystems/rust/builders/build-rust-package/default.nix { + buildersBySubsystem.${cfg.subsystem}.default = import (../../../../.. + "/src/subsystems/${cfg.subsystem}/builders/${cfg.builder}/default.nix") { inherit lib pkgs utils; dlib = {}; }; @@ -86,7 +88,7 @@ (l.evalModules { modules = [ ../../../../../src/modules/interfaces.translator/interface.nix - ../../../../../src/subsystems/rust/translators/cargo-lock + (../../../../.. + "/src/subsystems/${cfg.subsystem}/translators/${cfg.translator}") ]; specialArgs = { inherit dlib; @@ -97,8 +99,8 @@ tree = dlib.prepareSourceTree {source = config.mkDerivation.src;}; project = { - relPath = ""; - subsystemInfo = {}; + relPath = cfg.relPath; + subsystemInfo = cfg.subsystemInfo; }; result = translator.translate { diff --git a/v1/nix/modules/drv-parts/dream2nix-legacy/interface.nix b/v1/nix/modules/drv-parts/dream2nix-legacy/interface.nix index f324a895..71a888f9 100644 --- a/v1/nix/modules/drv-parts/dream2nix-legacy/interface.nix +++ b/v1/nix/modules/drv-parts/dream2nix-legacy/interface.nix @@ -6,4 +6,31 @@ l = lib // builtins; t = l.types; in { + options.legacy = { + builder = l.mkOption { + description = "Builder to use"; + example = ["build-rust-package"]; + type = t.str; + }; + relPath = l.mkOption { + default = ""; + description = "Relative path to project tree from source"; + type = t.str; + }; + subsystem = l.mkOption { + description = ''Name of subsystem to use. Examples: rust, python, nodejs''; + example = "nodejs"; + type = t.str; + }; + subsystemInfo = l.mkOption { + default = {}; + description = "Translator specific arguments"; + type = t.lazyAttrsOf (t.anything); + }; + translator = l.mkOption { + description = "Translator to use"; + example = ["yarn-lock" "package-json"]; + type = t.str; + }; + }; } diff --git a/v1/nix/modules/drvs/ripgrep/default.nix b/v1/nix/modules/drvs/ripgrep/default.nix index f5cec7a5..d9354d29 100644 --- a/v1/nix/modules/drvs/ripgrep/default.nix +++ b/v1/nix/modules/drvs/ripgrep/default.nix @@ -8,18 +8,22 @@ in { imports = [ drv-parts.modules.drv-parts.mkDerivation - ../../drv-parts/rust-cargo-lock-legacy + ../../drv-parts/dream2nix-legacy ]; + legacy = { + subsystem = "rust"; + translator = "cargo-lock"; + builder = "build-rust-package"; + }; + deps = {nixpkgs, ...}: { inherit (nixpkgs) fetchFromGitHub; inherit (nixpkgs) stdenv; }; - # public = { name = l.mkForce "ripgrep"; version = l.mkForce "13.0.0"; - # }; mkDerivation = { src = config.deps.fetchFromGitHub {