Files
clan-core/pkgs/clan-core-flake/flake-module.nix
DavHau 1e8864b9ec ci performance: add check to ensure nothing depends on the whole repo
Since this project is an ever growing monorepo, having derivations depending on the whole repo leads to bad CI performance, as the cache is busted on every commit.

-> We never want any derivations depend on the whole repo

...except: the test that tests that nothing depends on the whole repo, which is added by this commit.

For now only add this check to packages to allow contributors to build it locally.
We might want to add it to the CI later once all occurrences are fixed.
2025-04-30 13:17:33 +07:00

76 lines
2.4 KiB
Nix

{ self, inputs, ... }:
{
perSystem =
{
lib,
pkgs,
...
}:
let
# A flake lock for offline use.
# All flake inputs are locked to an existing store path
clanCoreLockFile =
clanCore:
let
flakeLock = lib.importJSON (clanCore + "/flake.lock");
flakeInputs = builtins.removeAttrs inputs [ "self" ];
flakeLockVendoredDeps =
flakeLock:
flakeLock
// {
nodes =
flakeLock.nodes
// (lib.flip lib.mapAttrs flakeInputs (
name: _:
# remove follows and let 'nix flake lock' re-compute it later
# (lib.removeAttrs flakeLock.nodes.${name} ["inputs"])
flakeLock.nodes.${name}
// {
locked = {
inherit (flakeLock.nodes.${name}.locked) narHash;
lastModified =
# lol, nixpkgs has a different timestamp on the fs???
if name == "nixpkgs" then 0 else 1;
path = "${inputs.${name}}";
type = "path";
};
}
));
};
clanCoreLock = flakeLockVendoredDeps flakeLock;
clanCoreLockFile = builtins.toFile "clan-core-flake.lock" (builtins.toJSON clanCoreLock);
in
clanCoreLockFile;
in
{
packages.clan-core-flake =
let
package =
{
clanCore,
}:
pkgs.runCommand "clan-core-flake"
{
buildInputs = [
pkgs.findutils
pkgs.git
pkgs.jq
pkgs.nix
];
}
''
set -e
export HOME=$(realpath .)
export NIX_STATE_DIR=$HOME
export NIX_STORE_DIR=$HOME
cp -r ${clanCore} $out
chmod +w -R $out
cp ${clanCoreLockFile clanCore} $out/flake.lock
nix flake lock $out --extra-experimental-features 'nix-command flakes'
clanCoreHash=$(nix hash path ${clanCore} --extra-experimental-features 'nix-command')
'';
in
pkgs.callPackage package { clanCore = self; };
};
}