From 0c5603ea2bc2e3034dcabc2eefe82986ecef363f Mon Sep 17 00:00:00 2001 From: Diego Restrepo Date: Mon, 20 Feb 2023 12:23:32 -0500 Subject: [PATCH] refac(back): #1007 redefine cache module - make the cache module generic - add more options --- .mailmap | 1 + .../modules/cache-with-attic/default.nix | 48 +++++++++++++++++++ src/evaluator/modules/cache/default.nix | 40 ++++++++++------ src/evaluator/modules/default.nix | 1 + 4 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 src/evaluator/modules/cache-with-attic/default.nix diff --git a/.mailmap b/.mailmap index 8af8430d..eaee2f81 100644 --- a/.mailmap +++ b/.mailmap @@ -7,6 +7,7 @@ David Acevedo David Acevedo David Arnold David Arnold David Arnold David Arnold Diego Restrepo Diego Restrepo Mesa <36453706+drestrepom@users.noreply.github.com> +Diego Restrepo Diego Restrepo Diego Restrepo Diego Restrepo Mesa <36453706+drestrepom@users.noreply.github.com> Fluid Attacks Fluid Attacks Github Dependabot <49699333+dependabot[bot]@users.noreply.github.com> dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> diff --git a/src/evaluator/modules/cache-with-attic/default.nix b/src/evaluator/modules/cache-with-attic/default.nix new file mode 100644 index 00000000..1d321981 --- /dev/null +++ b/src/evaluator/modules/cache-with-attic/default.nix @@ -0,0 +1,48 @@ +# SPDX-FileCopyrightText: 2022 Fluid Attacks and Makes contributors +# +# SPDX-License-Identifier: MIT +{listOptional, ...}: { + config, + lib, + ... +}: { + options = { + cacheWithAttic = { + readAndWrite = { + enable = lib.mkOption { + default = false; + type = lib.types.bool; + }; + name = lib.mkOption { + type = lib.types.str; + }; + url = lib.mkOption { + type = lib.types.str; + }; + token = lib.mkOption { + type = lib.types.str; + }; + pubKey = lib.mkOption { + type = lib.types.str; + }; + priority = lib.mkOption { + type = lib.type.int; + default = 10; + }; + }; + }; + }; + config = { + config = { + cacheWithAttic = builtins.concatLists [ + (listOptional config.cacheWithAttic.readAndWrite.enable { + name = config.cacheWithAttic.readAndWrite.name; + url = config.cacheWithAttic.readAndWrite.url; + token = config.cacheWithAttic.readAndWrite.token; + pubKey = config.cacheWithAttic.readAndWrite.pubKey; + type = "attic"; + }) + ]; + }; + }; +} diff --git a/src/evaluator/modules/cache/default.nix b/src/evaluator/modules/cache/default.nix index 60429ec4..76a1dcd0 100644 --- a/src/evaluator/modules/cache/default.nix +++ b/src/evaluator/modules/cache/default.nix @@ -5,28 +5,38 @@ }: { options = { cache = { - readAndWrite = { - enable = lib.mkOption { - default = false; - type = lib.types.bool; - }; - name = lib.mkOption { - type = lib.types.str; - }; - pubKey = lib.mkOption { - type = lib.types.str; - }; - }; - readExtra = lib.mkOption { - default = []; - type = lib.types.listOf (lib.types.submodule (_: { + extra = lib.mkOption { + default = {}; + type = lib.types.attrsOf (lib.types.submodule (_: { options = { + enable = lib.mkOption { + default = false; + type = lib.types.bool; + }; + name = lib.mkOption { + type = lib.types.str; + }; + token = lib.mkOption { + type = lib.types.str; + default = ""; + }; + priority = lib.mkOption { + type = lib.types.int; + }; pubKey = lib.mkOption { + default = ""; type = lib.types.str; }; + type = lib.mkOption { + type = lib.types.enum ["cachix" "attic"]; + }; url = lib.mkOption { type = lib.types.str; }; + write = lib.mkOption { + default = false; + type = lib.types.bool; + }; }; })); }; diff --git a/src/evaluator/modules/default.nix b/src/evaluator/modules/default.nix index 21a39e68..a753d332 100644 --- a/src/evaluator/modules/default.nix +++ b/src/evaluator/modules/default.nix @@ -10,6 +10,7 @@ } @ args: { imports = [ (import ./cache/default.nix args) + (import ./cache-with-attic/default.nix args) (import ./calculate-scorecard/default.nix args) (import ./compute-on-aws-batch/default.nix args) (import ./dev/default.nix args)