From f348abd9e5de83fda1a961e6e4b0a5455427221a Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sun, 25 Sep 2022 20:51:24 +0300 Subject: [PATCH 01/10] feat: use modules for builders --- src/default.nix | 6 ++-- src/modules/builders/builder/default.nix | 5 +++ src/modules/builders/builder/interface.nix | 37 ++++++++++++++++++++++ src/modules/builders/default.nix | 6 ++++ src/modules/builders/implementation.nix | 22 +++++++++++++ src/modules/builders/interface.nix | 25 +++++++++++++++ src/modules/top-level.nix | 1 + 7 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 src/modules/builders/builder/default.nix create mode 100644 src/modules/builders/builder/interface.nix create mode 100644 src/modules/builders/default.nix create mode 100644 src/modules/builders/implementation.nix create mode 100644 src/modules/builders/interface.nix diff --git a/src/default.nix b/src/default.nix index 1b08a20b..9c730e28 100644 --- a/src/default.nix +++ b/src/default.nix @@ -242,9 +242,9 @@ in let findBuilder = dreamLock: let subsystem = dreamLock._generic.subsystem; in - if ! subsystems."${subsystem}" ? builders + if ! framework.buildersBySubsystem.${subsystem} ? default then throw "Could not find any builder for subsystem '${subsystem}'" - else subsystems."${subsystem}".builders.default; + else framework.buildersBySubsystem.${subsystem}.default; # detect if granular or combined fetching must be used findFetcher = dreamLock: @@ -394,7 +394,7 @@ in let if builder == null then findBuilder dreamLock else if l.isString builder - then subsystems.${dreamLock._generic.subsystem}.builders.${builder} + then framework.buildersBySubsystem.${dreamLock._generic.subsystem}.${builder} else builder; fetcher' = diff --git a/src/modules/builders/builder/default.nix b/src/modules/builders/builder/default.nix new file mode 100644 index 00000000..bd4ca0b5 --- /dev/null +++ b/src/modules/builders/builder/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./interface.nix + ]; +} diff --git a/src/modules/builders/builder/interface.nix b/src/modules/builders/builder/interface.nix new file mode 100644 index 00000000..81abe944 --- /dev/null +++ b/src/modules/builders/builder/interface.nix @@ -0,0 +1,37 @@ +{ + config, + lib, + ... +}: let + t = lib.types; +in { + options = { + disabled = lib.mkOption { + type = t.bool; + default = false; + description = "Whether to disable the builder, if disabled it can't be used."; + }; + name = lib.mkOption { + type = t.str; + description = "Name of the builder."; + }; + subsystem = lib.mkOption { + type = t.str; + description = "Subsystem of the builder."; + }; + build = lib.mkOption { + type = t.function (t.functionTo t.attrs); + default = _: _: {}; + }; + type = lib.mkOption { + type = t.enum [ + "pure" + "ifd" + ]; + }; + version = lib.mkOption { + type = t.int; + default = 2; + }; + }; +} diff --git a/src/modules/builders/default.nix b/src/modules/builders/default.nix new file mode 100644 index 00000000..e0a7730f --- /dev/null +++ b/src/modules/builders/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./implementation.nix + ./interface.nix + ]; +} diff --git a/src/modules/builders/implementation.nix b/src/modules/builders/implementation.nix new file mode 100644 index 00000000..26b3921c --- /dev/null +++ b/src/modules/builders/implementation.nix @@ -0,0 +1,22 @@ +{ + config, + callPackageDream, + ... +}: let + loader = b: b // {build = callPackageDream b.build;}; + funcs = config.functions.subsystem-loading; + collectedModules = funcs.collect "builders"; +in { + config = { + # The user can add more translators by extending this attribute + builders = funcs.import_ collectedModules; + + /* + translators wrapped with extra logic to add extra attributes, + like .translateBin for pure translators + */ + builderInstances = funcs.instantiate config.builders loader; + + buildersBySubsystem = funcs.structureBySubsystem config.builderInstances; + }; +} diff --git a/src/modules/builders/interface.nix b/src/modules/builders/interface.nix new file mode 100644 index 00000000..aa333324 --- /dev/null +++ b/src/modules/builders/interface.nix @@ -0,0 +1,25 @@ +{ + lib, + specialArgs, + ... +}: let + t = lib.types; +in { + options = { + builders = lib.mkOption { + type = t.attrsOf (t.submoduleWith { + modules = [./builder/default.nix]; + inherit specialArgs; + }); + description = '' + builder module definitions + ''; + }; + builderInstances = lib.mkOption { + type = t.attrsOf t.anything; + }; + buildersBySubsystem = lib.mkOption { + type = t.attrsOf (t.attrsOf t.anything); + }; + }; +} diff --git a/src/modules/top-level.nix b/src/modules/top-level.nix index eae9abdd..ffbde1fa 100644 --- a/src/modules/top-level.nix +++ b/src/modules/top-level.nix @@ -9,6 +9,7 @@ in { ./functions.subsystem-loading ./functions.translators ./translators + ./builders ]; options = { lib = lib.mkOption { From c17eb68e522fb46aa9b9d376c401b605086b33e6 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sun, 25 Sep 2022 20:54:04 +0300 Subject: [PATCH 02/10] fix: correct type --- src/modules/builders/builder/interface.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/builders/builder/interface.nix b/src/modules/builders/builder/interface.nix index 81abe944..46b6f39e 100644 --- a/src/modules/builders/builder/interface.nix +++ b/src/modules/builders/builder/interface.nix @@ -20,7 +20,7 @@ in { description = "Subsystem of the builder."; }; build = lib.mkOption { - type = t.function (t.functionTo t.attrs); + type = t.functionTo (t.functionTo t.attrs); default = _: _: {}; }; type = lib.mkOption { From 8ff108db36110c40eb8d22302ed82b776c5b046d Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sun, 25 Sep 2022 20:57:02 +0300 Subject: [PATCH 03/10] fix: use callPackageDream correctly --- src/modules/builders/implementation.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/builders/implementation.nix b/src/modules/builders/implementation.nix index 26b3921c..7b0a3261 100644 --- a/src/modules/builders/implementation.nix +++ b/src/modules/builders/implementation.nix @@ -3,7 +3,7 @@ callPackageDream, ... }: let - loader = b: b // {build = callPackageDream b.build;}; + loader = b: b // {build = callPackageDream b.build {};}; funcs = config.functions.subsystem-loading; collectedModules = funcs.collect "builders"; in { From 7432b27e1347bf83a6f4abb6407b710e86440f1b Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sun, 25 Sep 2022 21:01:43 +0300 Subject: [PATCH 04/10] tests: fix new-subsystem test --- examples/_d2n-extended-new-subsystem/builders.nix | 11 +++++++++++ examples/_d2n-extended-new-subsystem/extra.nix | 7 ------- examples/_d2n-extended-new-subsystem/flake.nix | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 examples/_d2n-extended-new-subsystem/builders.nix diff --git a/examples/_d2n-extended-new-subsystem/builders.nix b/examples/_d2n-extended-new-subsystem/builders.nix new file mode 100644 index 00000000..445d7d02 --- /dev/null +++ b/examples/_d2n-extended-new-subsystem/builders.nix @@ -0,0 +1,11 @@ +{ + builders.dummy = {...}: { + name = "dummy"; + subsystem = "hello"; + type = "pure"; + build = {hello, ...}: {...}: { + packages.${hello.pname}.${hello.version} = + hello; + }; + }; +} diff --git a/examples/_d2n-extended-new-subsystem/extra.nix b/examples/_d2n-extended-new-subsystem/extra.nix index 124a84bb..5aa486a5 100644 --- a/examples/_d2n-extended-new-subsystem/extra.nix +++ b/examples/_d2n-extended-new-subsystem/extra.nix @@ -11,12 +11,5 @@ }) ]; }; - builders.dummy = {...}: { - type = "pure"; - build = {hello, ...}: {...}: { - packages.${hello.pname}.${hello.version} = - hello; - }; - }; }; } diff --git a/examples/_d2n-extended-new-subsystem/flake.nix b/examples/_d2n-extended-new-subsystem/flake.nix index 6c1c77d8..baf9267f 100644 --- a/examples/_d2n-extended-new-subsystem/flake.nix +++ b/examples/_d2n-extended-new-subsystem/flake.nix @@ -13,6 +13,7 @@ config.extra = ./extra.nix; config.modules = [ ./translators.nix + ./builders.nix ]; source = ./.; settings = [ From c52d805408a719d11846e08d48618472132ee14e Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sun, 25 Sep 2022 22:07:17 +0300 Subject: [PATCH 05/10] fix: make builder names unique --- .../builders/{default => simple-builder-debian}/default.nix | 0 .../builders/{default => simple-builder-haskell}/default.nix | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/subsystems/debian/builders/{default => simple-builder-debian}/default.nix (100%) rename src/subsystems/haskell/builders/{default => simple-builder-haskell}/default.nix (100%) diff --git a/src/subsystems/debian/builders/default/default.nix b/src/subsystems/debian/builders/simple-builder-debian/default.nix similarity index 100% rename from src/subsystems/debian/builders/default/default.nix rename to src/subsystems/debian/builders/simple-builder-debian/default.nix diff --git a/src/subsystems/haskell/builders/default/default.nix b/src/subsystems/haskell/builders/simple-builder-haskell/default.nix similarity index 100% rename from src/subsystems/haskell/builders/default/default.nix rename to src/subsystems/haskell/builders/simple-builder-haskell/default.nix From b9e02b40498feb4fe7f7ae97b25c4909e5599931 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sun, 25 Sep 2022 22:19:59 +0300 Subject: [PATCH 06/10] fix: make builder names unique again --- src/modules/builders/implementation.nix | 18 +++++++++++++++++- .../{granular => granular-nodejs}/default.nix | 0 .../{granular => granular-nodejs}/devShell.nix | 0 .../fix-package.py | 0 .../install-deps.py | 0 .../{granular => granular-nodejs}/link-bins.py | 0 .../tsconfig-to-json.js | 0 .../{granular => granular-php}/default.nix | 0 .../{granular => granular-php}/devShell.nix | 0 .../{simple => simple-php}/default.nix | 0 .../{simple => simple-php}/devShell.nix | 0 .../default.nix | 0 12 files changed, 17 insertions(+), 1 deletion(-) rename src/subsystems/nodejs/builders/{granular => granular-nodejs}/default.nix (100%) rename src/subsystems/nodejs/builders/{granular => granular-nodejs}/devShell.nix (100%) rename src/subsystems/nodejs/builders/{granular => granular-nodejs}/fix-package.py (100%) rename src/subsystems/nodejs/builders/{granular => granular-nodejs}/install-deps.py (100%) rename src/subsystems/nodejs/builders/{granular => granular-nodejs}/link-bins.py (100%) rename src/subsystems/nodejs/builders/{granular => granular-nodejs}/tsconfig-to-json.js (100%) rename src/subsystems/php/builders/{granular => granular-php}/default.nix (100%) rename src/subsystems/php/builders/{granular => granular-php}/devShell.nix (100%) rename src/subsystems/php/builders/{simple => simple-php}/default.nix (100%) rename src/subsystems/php/builders/{simple => simple-php}/devShell.nix (100%) rename src/subsystems/python/builders/{simple-builder => simple-python}/default.nix (100%) diff --git a/src/modules/builders/implementation.nix b/src/modules/builders/implementation.nix index 7b0a3261..3246fad4 100644 --- a/src/modules/builders/implementation.nix +++ b/src/modules/builders/implementation.nix @@ -1,8 +1,15 @@ { config, callPackageDream, + lib, ... }: let + defaults = { + rust = "build-rust-package"; + nodejs = "granular-nodejs"; + python = "simple-python"; + php = "granular-php"; + }; loader = b: b // {build = callPackageDream b.build {};}; funcs = config.functions.subsystem-loading; collectedModules = funcs.collect "builders"; @@ -17,6 +24,15 @@ in { */ builderInstances = funcs.instantiate config.builders loader; - buildersBySubsystem = funcs.structureBySubsystem config.builderInstances; + buildersBySubsystem = + lib.mapAttrs + ( + subsystem: builders: + builders + // lib.optionalAttrs (lib.hasAttr subsystem defaults) { + default = builders.${defaults.${subsystem}}; + } + ) + (funcs.structureBySubsystem config.builderInstances); }; } diff --git a/src/subsystems/nodejs/builders/granular/default.nix b/src/subsystems/nodejs/builders/granular-nodejs/default.nix similarity index 100% rename from src/subsystems/nodejs/builders/granular/default.nix rename to src/subsystems/nodejs/builders/granular-nodejs/default.nix diff --git a/src/subsystems/nodejs/builders/granular/devShell.nix b/src/subsystems/nodejs/builders/granular-nodejs/devShell.nix similarity index 100% rename from src/subsystems/nodejs/builders/granular/devShell.nix rename to src/subsystems/nodejs/builders/granular-nodejs/devShell.nix diff --git a/src/subsystems/nodejs/builders/granular/fix-package.py b/src/subsystems/nodejs/builders/granular-nodejs/fix-package.py similarity index 100% rename from src/subsystems/nodejs/builders/granular/fix-package.py rename to src/subsystems/nodejs/builders/granular-nodejs/fix-package.py diff --git a/src/subsystems/nodejs/builders/granular/install-deps.py b/src/subsystems/nodejs/builders/granular-nodejs/install-deps.py similarity index 100% rename from src/subsystems/nodejs/builders/granular/install-deps.py rename to src/subsystems/nodejs/builders/granular-nodejs/install-deps.py diff --git a/src/subsystems/nodejs/builders/granular/link-bins.py b/src/subsystems/nodejs/builders/granular-nodejs/link-bins.py similarity index 100% rename from src/subsystems/nodejs/builders/granular/link-bins.py rename to src/subsystems/nodejs/builders/granular-nodejs/link-bins.py diff --git a/src/subsystems/nodejs/builders/granular/tsconfig-to-json.js b/src/subsystems/nodejs/builders/granular-nodejs/tsconfig-to-json.js similarity index 100% rename from src/subsystems/nodejs/builders/granular/tsconfig-to-json.js rename to src/subsystems/nodejs/builders/granular-nodejs/tsconfig-to-json.js diff --git a/src/subsystems/php/builders/granular/default.nix b/src/subsystems/php/builders/granular-php/default.nix similarity index 100% rename from src/subsystems/php/builders/granular/default.nix rename to src/subsystems/php/builders/granular-php/default.nix diff --git a/src/subsystems/php/builders/granular/devShell.nix b/src/subsystems/php/builders/granular-php/devShell.nix similarity index 100% rename from src/subsystems/php/builders/granular/devShell.nix rename to src/subsystems/php/builders/granular-php/devShell.nix diff --git a/src/subsystems/php/builders/simple/default.nix b/src/subsystems/php/builders/simple-php/default.nix similarity index 100% rename from src/subsystems/php/builders/simple/default.nix rename to src/subsystems/php/builders/simple-php/default.nix diff --git a/src/subsystems/php/builders/simple/devShell.nix b/src/subsystems/php/builders/simple-php/devShell.nix similarity index 100% rename from src/subsystems/php/builders/simple/devShell.nix rename to src/subsystems/php/builders/simple-php/devShell.nix diff --git a/src/subsystems/python/builders/simple-builder/default.nix b/src/subsystems/python/builders/simple-python/default.nix similarity index 100% rename from src/subsystems/python/builders/simple-builder/default.nix rename to src/subsystems/python/builders/simple-python/default.nix From 16d9dde731cc31d3c1cbc4f0151954fcfa89384a Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sun, 25 Sep 2022 22:28:17 +0300 Subject: [PATCH 07/10] fix: check if subsystem has builders properly --- src/default.nix | 2 +- src/modules/builders/implementation.nix | 1 + .../{simple-builder-haskell => simple-haskell}/default.nix | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename src/subsystems/haskell/builders/{simple-builder-haskell => simple-haskell}/default.nix (100%) diff --git a/src/default.nix b/src/default.nix index 9c730e28..c767a7b3 100644 --- a/src/default.nix +++ b/src/default.nix @@ -242,7 +242,7 @@ in let findBuilder = dreamLock: let subsystem = dreamLock._generic.subsystem; in - if ! framework.buildersBySubsystem.${subsystem} ? default + if ! framework.buildersBySubsystem ? ${subsystem} then throw "Could not find any builder for subsystem '${subsystem}'" else framework.buildersBySubsystem.${subsystem}.default; diff --git a/src/modules/builders/implementation.nix b/src/modules/builders/implementation.nix index 3246fad4..f5057902 100644 --- a/src/modules/builders/implementation.nix +++ b/src/modules/builders/implementation.nix @@ -9,6 +9,7 @@ nodejs = "granular-nodejs"; python = "simple-python"; php = "granular-php"; + haskell = "simple-haskell"; }; loader = b: b // {build = callPackageDream b.build {};}; funcs = config.functions.subsystem-loading; diff --git a/src/subsystems/haskell/builders/simple-builder-haskell/default.nix b/src/subsystems/haskell/builders/simple-haskell/default.nix similarity index 100% rename from src/subsystems/haskell/builders/simple-builder-haskell/default.nix rename to src/subsystems/haskell/builders/simple-haskell/default.nix From 3a6ebd75ef4a4894547aad8c7fb1731591f2bae4 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sun, 25 Sep 2022 22:41:56 +0300 Subject: [PATCH 08/10] feat: add a warning when collecting modules if two modules have same names --- src/modules/builders/implementation.nix | 1 + .../implementation.nix | 16 +++++++++++++++- .../default.nix | 0 3 files changed, 16 insertions(+), 1 deletion(-) rename src/subsystems/debian/builders/{simple-builder-debian => simple-debian}/default.nix (100%) diff --git a/src/modules/builders/implementation.nix b/src/modules/builders/implementation.nix index f5057902..8ffa6aef 100644 --- a/src/modules/builders/implementation.nix +++ b/src/modules/builders/implementation.nix @@ -10,6 +10,7 @@ python = "simple-python"; php = "granular-php"; haskell = "simple-haskell"; + debian = "simple-debian"; }; loader = b: b // {build = callPackageDream b.build {};}; funcs = config.functions.subsystem-loading; diff --git a/src/modules/functions.subsystem-loading/implementation.nix b/src/modules/functions.subsystem-loading/implementation.nix index e2a2ed0a..cdbbf01d 100644 --- a/src/modules/functions.subsystem-loading/implementation.nix +++ b/src/modules/functions.subsystem-loading/implementation.nix @@ -44,7 +44,21 @@ modules: (name: description: (import description.path {inherit dlib lib;}) // {inherit (description) name subsystem;}) - (lib.listToAttrs collectedModules); + ( + lib.foldl' + ( + all: el: + if lib.hasAttr el.name all + then + throw '' + module named ${el.name} in subsystem ${el.value.subsystem} conflicts + with a module with the same name from subsystem ${all.${el.name}.subsystem} + '' + else all // {${el.name} = el.value;} + ) + {} + collectedModules + ); instantiate = importedModules: loader: lib.mapAttrs diff --git a/src/subsystems/debian/builders/simple-builder-debian/default.nix b/src/subsystems/debian/builders/simple-debian/default.nix similarity index 100% rename from src/subsystems/debian/builders/simple-builder-debian/default.nix rename to src/subsystems/debian/builders/simple-debian/default.nix From 15b86216488742351e7bc6842a3cf3235a9e9716 Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Sun, 25 Sep 2022 22:54:05 +0300 Subject: [PATCH 09/10] tests: fix _d2n-extended test --- examples/_d2n-extended/flake.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/_d2n-extended/flake.nix b/examples/_d2n-extended/flake.nix index 69125bd4..18ed997d 100644 --- a/examples/_d2n-extended/flake.nix +++ b/examples/_d2n-extended/flake.nix @@ -23,10 +23,18 @@ }; } '') + (builtins.toFile "brp-new.nix" '' + { + builders.brp-new = { + imports = ["${inp.dream2nix}/src/subsystems/rust/builders/build-rust-package"]; + name = "brp-new"; + subsystem = "rust"; + }; + } + '') ]; config.extra = { subsystems.rust = { - builders.brp-new = "${inp.dream2nix}/src/subsystems/rust/builders/build-rust-package"; discoverers.default = "${inp.dream2nix}/src/subsystems/rust/discoverers/default"; }; fetchers.crates-io = "${inp.dream2nix}/src/fetchers/crates-io"; From 163bdcc60152e67835568817fa8fbde7310f369f Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Tue, 27 Sep 2022 15:29:55 +0300 Subject: [PATCH 10/10] refactor: remove version from builders --- src/modules/builders/builder/interface.nix | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/modules/builders/builder/interface.nix b/src/modules/builders/builder/interface.nix index 46b6f39e..e77c0d34 100644 --- a/src/modules/builders/builder/interface.nix +++ b/src/modules/builders/builder/interface.nix @@ -29,9 +29,5 @@ in { "ifd" ]; }; - version = lib.mkOption { - type = t.int; - default = 2; - }; }; }