From 45d63bce1728589836079ecbce83c08f8220845a Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 15 Nov 2019 23:25:41 +0000 Subject: [PATCH] feat(nix): Filter projects that should be built by CI Instead of specifying CI projects manually, this filters them to move the CI configuration into the derivations `meta` attributes. --- default.nix | 33 ++++++++++++-------- services/tazblog/default.nix | 1 + tools/blog_cli/default.nix | 2 ++ tools/{kms_pass/default.nix => kms_pass.nix} | 4 +-- 4 files changed, 25 insertions(+), 15 deletions(-) rename tools/{kms_pass/default.nix => kms_pass.nix} (95%) diff --git a/default.nix b/default.nix index 789098667..d7ef5b72b 100644 --- a/default.nix +++ b/default.nix @@ -16,7 +16,16 @@ let }; readTree = import ./read-tree.nix; - localPkgs = self: super: + # Derivations that have `meta.enableCI` set to `true` should be + # built by the CI system on every commit. This code implements + # filtering of all derivations in the local sets against this + # condition. + filterCI = lib: pkgs: let + inherit (lib) collect isDerivation filterAttrsRecursive; + ciCondition = _: x: (!isDerivation x) || ((x ? meta.enableCI) && (x.meta.enableCI)); + in collect isDerivation (filterAttrsRecursive ciCondition pkgs); + + repoPkgs = self: super: let config = { pkgs = self; upstream = super; @@ -32,19 +41,17 @@ let services = readTree ./services config; tools = readTree ./tools config; third_party = readTree ./third_party config; - } // (readTree ./overrides config); - - # # All projects that should be built by CI should be added here: - # ciProjects = [ - # self.kontemplate - # self.nixery - # self.ormolu - # self.terraform-gcp - # ] ++ filter (d: d ? meta.broken && !d.meta.broken) (attrValues self.tazjin); - # }; - + } + # Load overrides into the top-level: + // (readTree ./overrides config) + # Collect all projects that should be built by CI + // { + ciProjects = (filterCI super.lib self.services) + ++ (filterCI super.lib self.tools) + ++ (filterCI super.lib self.third_party); + }; in { ... } @ args: import stableSrc (args // { - overlays = [ localPkgs ]; + overlays = [ repoPkgs ]; config.allowUnfree = true; config.allowBroken = true; }) diff --git a/services/tazblog/default.nix b/services/tazblog/default.nix index 2e75c3c2d..4d9608838 100644 --- a/services/tazblog/default.nix +++ b/services/tazblog/default.nix @@ -14,4 +14,5 @@ let ''; in wrapper.overrideAttrs(_: { allowSubstitutes = true; + meta.enableCI = true; }) diff --git a/tools/blog_cli/default.nix b/tools/blog_cli/default.nix index 8113c9336..717daec86 100644 --- a/tools/blog_cli/default.nix +++ b/tools/blog_cli/default.nix @@ -5,4 +5,6 @@ pkgs.buildGoPackage { goPackagePath = "github.com/tazjin/personal/blog_cli"; src = ./.; goDeps = ./deps.nix; + + meta.enableCI = true; } diff --git a/tools/kms_pass/default.nix b/tools/kms_pass.nix similarity index 95% rename from tools/kms_pass/default.nix rename to tools/kms_pass.nix index 113db3022..7005697da 100644 --- a/tools/kms_pass/default.nix +++ b/tools/kms_pass.nix @@ -9,7 +9,7 @@ { pkgs, kms, ... }: let inherit (pkgs) google-cloud-sdk tree writeShellScriptBin; -in writeShellScriptBin "pass" '' +in (writeShellScriptBin "pass" '' set -eo pipefail CMD="$1" @@ -57,4 +57,4 @@ in writeShellScriptBin "pass" '' exit 1 ;; esac -'' +'') // { meta.enableCI = true; }