This commit is contained in:
Dmitriy Kholkin 2023-06-16 02:30:19 +03:00
parent 20262fbd09
commit 5930c3233c
2 changed files with 44 additions and 9 deletions

View File

@ -27,7 +27,7 @@ jobs:
echo "machine cache.ataraxiadev.com" > /home/runner/.config/nix/netrc
echo "password ${{ secrets.ATTIC_TOKEN }}" >> /home/runner/.config/nix/netrc
nix run github:AtaraxiaSjel/attic#attic -- login dev https://cache.ataraxiadev.com/ ${{ secrets.ATTIC_TOKEN }}
- name: Build system and push to cache
run: |
nix develop .#ci -c nix-build-uncached ci.nix
nix develop .#ci -c attic push ataraxiadev ./result*
- name: Build system
run: nix develop .#ci -c nix-build-uncached ci.nix -A buildOutputs
- name: Push to cache
run: nix develop .#ci -c attic push ataraxiadev ./result*

45
ci.nix
View File

@ -1,7 +1,42 @@
with builtins;
let
outputs = builtins.getFlake (toString ./.);
system = "x86_64-linux";
pkgs = import outputs.inputs.nixpkgs { inherit system; };
host-workstation = (pkgs.callPackage ./scripts/force_cached.nix {}) outputs.packages.x86_64-linux.host-workstation;
host-hypervisor = (pkgs.callPackage ./scripts/force_cached.nix {}) outputs.packages.x86_64-linux.host-hypervisor;
in host-workstation // host-hypervisor
pkgs = outputs.inputs.nixpkgs;
isHost = n: pkgs.lib.strings.hasPrefix "host" n;
isDerivation = p: isAttrs p && p ? type && p.type == "derivation";
isBuildable = p: !(p.meta.broken or false);
isCacheable = p: !(p.preferLocalBuild or false);
shouldRecurseForDerivations = p:
isAttrs p && p.recurseForDerivations or false;
nameValuePair = n: v: {
name = n;
value = v;
};
concatMap = builtins.concatMap or (f: xs: concatLists (map f xs));
flattenPkgs = s:
let
f = p:
if shouldRecurseForDerivations p then
flattenPkgs p
else if isDerivation p then
[ p ]
else
[ ];
in concatMap f (attrValues s);
outputsOf = p: map (o: p.${o}) p.outputs;
hostAttrs = outputs.packages.x86_64-linux;
hostPkgs = flattenPkgs (listToAttrs (map (n: nameValuePair n hostAttrs.${n})
(filter (n: isHost n) (attrNames hostAttrs))));
in rec {
buildPkgs = filter isBuildable hostPkgs;
cachePkgs = filter isCacheable buildPkgs;
buildOutputs = concatMap outputsOf buildPkgs;
cacheOutputs = concatMap outputsOf cachePkgs;
}