Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache: init #7

Merged
merged 6 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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="
];
};
}
```
13 changes: 11 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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="
];
};
}
54 changes: 54 additions & 0 deletions shared/builder.nix
Original file line number Diff line number Diff line change
@@ -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}
''