From 41f1b8a15adbc1efa6598626b1b0ca97eea505c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 22 Sep 2023 08:39:24 +0200 Subject: [PATCH] perf? make clan-cli evaluate waaayyy faster Before my small devshell to 7s. Now I am back to 2.6s --- pkgs/clan-cli/default.nix | 18 +++++++++--------- pkgs/clan-cli/flake-module.nix | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index 0bb83d7f..7aed0c22 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -19,7 +19,6 @@ , wheel , zerotierone , rsync -, pkgs , ui-assets , bash , sshpass @@ -27,6 +26,7 @@ , tor , git , ipdb +, nixpkgs }: let @@ -68,19 +68,20 @@ let checkPython = python3.withPackages (_ps: pytestDependencies); # - 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" { } '' cp -r ${./.} $out chmod -R +w $out 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 ln -s ${ui-assets} $out/clan_cli/webui/assets ''; - nixpkgs = runCommand "nixpkgs" { nativeBuildInputs = [ pkgs.nix ]; } '' + nixpkgs' = runCommand "nixpkgs" { nativeBuildInputs = [ nix ]; } '' mkdir $out mkdir -p $out/unfree cat > $out/unfree/default.nix < $out/flake.nix << EOF { @@ -93,13 +94,12 @@ let outputs = _inputs: { }; } EOF - ln -s ${pkgs.path} $out/path + ln -s ${nixpkgs} $out/path nix flake lock $out \ --store ./. \ --experimental-features 'nix-command flakes' \ - --override-input nixpkgs ${pkgs.path} + --override-input nixpkgs ${nixpkgs} ''; - in python3.pkgs.buildPythonPackage { 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 touch $out ''; - passthru.nixpkgs = nixpkgs; + passthru.nixpkgs = nixpkgs'; passthru.checkPython = checkPython; passthru.devDependencies = [ @@ -145,7 +145,7 @@ python3.pkgs.buildPythonPackage { passthru.runtimeDependencies = runtimeDependencies; postInstall = '' - cp -r ${nixpkgs} $out/${python3.sitePackages}/clan_cli/nixpkgs + cp -r ${nixpkgs'} $out/${python3.sitePackages}/clan_cli/nixpkgs installShellCompletion --bash --name clan \ <(${argcomplete}/bin/register-python-argcomplete --shell bash clan) installShellCompletion --fish --name clan.fish \ diff --git a/pkgs/clan-cli/flake-module.nix b/pkgs/clan-cli/flake-module.nix index 4712adc7..ff7aaee7 100644 --- a/pkgs/clan-cli/flake-module.nix +++ b/pkgs/clan-cli/flake-module.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib, inputs, ... }: { perSystem = { self', pkgs, ... }: { devShells.clan-cli = pkgs.callPackage ./shell.nix { @@ -7,6 +7,7 @@ packages = { clan-cli = pkgs.python3.pkgs.callPackage ./default.nix { inherit (self'.packages) ui-assets zerotierone; + inherit (inputs) nixpkgs; }; clan-openapi = self'.packages.clan-cli.clan-openapi; default = self'.packages.clan-cli;