Skip to content

Commit

Permalink
cache: init (#7)
Browse files Browse the repository at this point in the history
### 🐟 What?

- Adds a default package, that includes a script that builds and deploys
all other packages;
- Adds the cache URL to README.
- Adds the cache to the flake's `nixConf`.

### 🎣 Why?

- My laptop can't build the stuff my desktop builds.

### 🍥 Extra

- Needs bot to feed it;
- Usage:
  1. Set `CACHIX_SIGNING_KEY`;
  2. Run `nix shell -c build-chaotic-nyx`.
- We'll have both ours and cachix urls as trusted keys, I plan to keep
some stuff in cachix even when we have our cache running
  • Loading branch information
PedroHLC committed Apr 8, 2023
2 parents cd0d3e7 + f6c9d48 commit 80be1e0
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
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}
''

0 comments on commit 80be1e0

Please sign in to comment.