diff --git a/README.md b/README.md index 241e68988..89dd83ba6 100644 --- a/README.md +++ b/README.md @@ -70,4 +70,16 @@ nix run github:chaotic-aur/nyx#input-leap-git ## Cache -Soon... +```nix +{ + nix.settings = { + extra-substituters = [ + "https://nyx.chaotic.cx" + ]; + extra-trusted-public-keys = [ + "nyx.chaotic.cx-1:HfnXSw4pj95iI/n17rIDy40agHj12WfF+Gqk6SonIT8=" + "chaotic-nyx.cachix.org-1:HfnXSw4pj95iI/n17rIDy40agHj12WfF+Gqk6SonIT8=" + ]; + }; +} +``` diff --git a/flake.nix b/flake.nix index 83e221f94..c30d7d9c4 100644 --- a/flake.nix +++ b/flake.nix @@ -38,7 +38,7 @@ }; }; - outputs = { nixpkgs, ... }@inputs: rec { + outputs = { nixpkgs, self, ... }@inputs: rec { # I would prefer if we had something stricter, with attribute alphabetical # sorting, and optimized for git's diffing. But this is the closer we have. formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt; @@ -54,8 +54,9 @@ let overlayFinal = prev // final // { callPackage = prev.newScope final; }; final = overlays.default overlayFinal prev; + builder = overlayFinal.callPackage ./shared/builder.nix { all-packages = final; flakeSelf = self; }; in - final; + final // { default = builder; }; in { x86_64-linux = applyOverlay nixpkgs.legacyPackages.x86_64-linux; @@ -64,4 +65,12 @@ hydraJobs.default = packages; }; + + nixConfig = { + extra-substituters = [ "https://nyx.chaotic.cx" ]; + extra-trusted-public-keys = [ + "nyx.chaotic.cx-1:HfnXSw4pj95iI/n17rIDy40agHj12WfF+Gqk6SonIT8=" + "chaotic-nyx.cachix.org-1:HfnXSw4pj95iI/n17rIDy40agHj12WfF+Gqk6SonIT8=" + ]; + }; } diff --git a/shared/builder.nix b/shared/builder.nix new file mode 100644 index 000000000..30cb8cd39 --- /dev/null +++ b/shared/builder.nix @@ -0,0 +1,54 @@ +{ all-packages +, cachix +, jq +, lib +, nix +, flakeSelf +, writeShellScriptBin +}: +let + evalCommand = where: drvOutputs: + let + derivation = "${flakeSelf}#${where}"; + outputs = map (guide derivation) drvOutputs; + in + '' + echo "Building ${derivation}" + ${nix}/bin/nix build --json \ + ${lib.strings.concatStringsSep " \\\n " outputs} |\ + ${jq}/bin/jq -r '.[].outputs[]' |\ + ${cachix}/bin/cachix push chaotic-nyx --compression-method zstd + ''; + + guide = namespace: n: + if namespace != "" then + "${namespace}.${n}" + else + n + ; + packagesEval = namespace: n: v: + (if (builtins.tryEval v).success then + (if lib.attrsets.isDerivation v then + (if (v.meta.broken or true) then + "# broken: ${n}" + else if (v.meta.unfree or true) then + "# unfree: ${n}" + else + evalCommand (guide namespace n) v.outputs + ) + else if builtins.isAttrs v then + lib.strings.concatStringsSep "\n" + (lib.attrsets.mapAttrsToList (packagesEval (guide namespace n)) v) + else + "# unrelated: ${n}" + ) + else + "# not evaluating: ${n}" + ) + ; +in +writeShellScriptBin "build-chaotic-nyx" '' + cd "$(mktemp -d)" + + ${packagesEval "" "" all-packages} +''