perf? make clan-cli evaluate waaayyy faster
All checks were successful
checks-impure / test (pull_request) Successful in 9s
checks / test (pull_request) Successful in 35s

Before my small devshell to 7s. Now I am back to 2.6s
This commit is contained in:
Jörg Thalheim 2023-09-22 08:39:24 +02:00
parent 4f3f7a4feb
commit 41f1b8a15a
2 changed files with 11 additions and 10 deletions

View File

@ -19,7 +19,6 @@
, wheel , wheel
, zerotierone , zerotierone
, rsync , rsync
, pkgs
, ui-assets , ui-assets
, bash , bash
, sshpass , sshpass
@ -27,6 +26,7 @@
, tor , tor
, git , git
, ipdb , ipdb
, nixpkgs
}: }:
let let
@ -68,19 +68,20 @@ let
checkPython = python3.withPackages (_ps: pytestDependencies); checkPython = python3.withPackages (_ps: pytestDependencies);
# - vendor the jsonschema nix lib (copy instead of symlink). # - vendor the jsonschema nix lib (copy instead of symlink).
# Interesting fact: using nixpkgs from flakes instead of nixpkgs.path is reduces evaluation time by 5s.
source = runCommand "clan-cli-source" { } '' source = runCommand "clan-cli-source" { } ''
cp -r ${./.} $out cp -r ${./.} $out
chmod -R +w $out chmod -R +w $out
rm $out/clan_cli/config/jsonschema rm $out/clan_cli/config/jsonschema
cp -r ${nixpkgs} $out/clan_cli/nixpkgs ln -s ${nixpkgs'} $out/clan_cli/nixpkgs
cp -r ${../../lib/jsonschema} $out/clan_cli/config/jsonschema cp -r ${../../lib/jsonschema} $out/clan_cli/config/jsonschema
ln -s ${ui-assets} $out/clan_cli/webui/assets ln -s ${ui-assets} $out/clan_cli/webui/assets
''; '';
nixpkgs = runCommand "nixpkgs" { nativeBuildInputs = [ pkgs.nix ]; } '' nixpkgs' = runCommand "nixpkgs" { nativeBuildInputs = [ nix ]; } ''
mkdir $out mkdir $out
mkdir -p $out/unfree mkdir -p $out/unfree
cat > $out/unfree/default.nix <<EOF cat > $out/unfree/default.nix <<EOF
import "${pkgs.path}" { config = { allowUnfree = true; overlays = []; }; } import "${nixpkgs}" { config = { allowUnfree = true; overlays = []; }; }
EOF EOF
cat > $out/flake.nix << EOF cat > $out/flake.nix << EOF
{ {
@ -93,13 +94,12 @@ let
outputs = _inputs: { }; outputs = _inputs: { };
} }
EOF EOF
ln -s ${pkgs.path} $out/path ln -s ${nixpkgs} $out/path
nix flake lock $out \ nix flake lock $out \
--store ./. \ --store ./. \
--experimental-features 'nix-command flakes' \ --experimental-features 'nix-command flakes' \
--override-input nixpkgs ${pkgs.path} --override-input nixpkgs ${nixpkgs}
''; '';
in in
python3.pkgs.buildPythonPackage { python3.pkgs.buildPythonPackage {
name = "clan-cli"; name = "clan-cli";
@ -133,7 +133,7 @@ python3.pkgs.buildPythonPackage {
${checkPython}/bin/python ./bin/gen-openapi --out $out/openapi.json --app-dir . clan_cli.webui.app:app ${checkPython}/bin/python ./bin/gen-openapi --out $out/openapi.json --app-dir . clan_cli.webui.app:app
touch $out touch $out
''; '';
passthru.nixpkgs = nixpkgs; passthru.nixpkgs = nixpkgs';
passthru.checkPython = checkPython; passthru.checkPython = checkPython;
passthru.devDependencies = [ passthru.devDependencies = [
@ -145,7 +145,7 @@ python3.pkgs.buildPythonPackage {
passthru.runtimeDependencies = runtimeDependencies; passthru.runtimeDependencies = runtimeDependencies;
postInstall = '' postInstall = ''
cp -r ${nixpkgs} $out/${python3.sitePackages}/clan_cli/nixpkgs cp -r ${nixpkgs'} $out/${python3.sitePackages}/clan_cli/nixpkgs
installShellCompletion --bash --name clan \ installShellCompletion --bash --name clan \
<(${argcomplete}/bin/register-python-argcomplete --shell bash clan) <(${argcomplete}/bin/register-python-argcomplete --shell bash clan)
installShellCompletion --fish --name clan.fish \ installShellCompletion --fish --name clan.fish \

View File

@ -1,4 +1,4 @@
{ lib, ... }: { lib, inputs, ... }:
{ {
perSystem = { self', pkgs, ... }: { perSystem = { self', pkgs, ... }: {
devShells.clan-cli = pkgs.callPackage ./shell.nix { devShells.clan-cli = pkgs.callPackage ./shell.nix {
@ -7,6 +7,7 @@
packages = { packages = {
clan-cli = pkgs.python3.pkgs.callPackage ./default.nix { clan-cli = pkgs.python3.pkgs.callPackage ./default.nix {
inherit (self'.packages) ui-assets zerotierone; inherit (self'.packages) ui-assets zerotierone;
inherit (inputs) nixpkgs;
}; };
clan-openapi = self'.packages.clan-cli.clan-openapi; clan-openapi = self'.packages.clan-cli.clan-openapi;
default = self'.packages.clan-cli; default = self'.packages.clan-cli;