clan-cli: use dependency flake instead of registry
All checks were successful
checks / test (pull_request) Successful in 1m53s
checks-impure / test (pull_request) Successful in 25s

This commit is contained in:
DavHau 2023-09-06 14:40:00 +02:00
parent c9bfd0a5b5
commit fcbc3ec899
6 changed files with 38 additions and 34 deletions

View File

@ -1,3 +1,4 @@
import json
import os
import sys
from pathlib import Path
@ -30,12 +31,15 @@ def module_root() -> Path:
return Path(__file__).parent
def flake_registry() -> Path:
return module_root() / "nixpkgs" / "flake-registry.json"
def deps_flake() -> Path:
return module_root() / "deps_flake"
def nixpkgs() -> Path:
return (module_root() / "nixpkgs" / "path").resolve()
# load the flake.lock json file from the deps_flake and return nodes.nixpkgs.path
with open(deps_flake() / "flake.lock") as f:
flake_lock = json.load(f)
return Path(flake_lock["nodes"]["nixpkgs"]["locked"]["path"])
def unfree_nixpkgs() -> Path:

View File

@ -1,7 +1,7 @@
import os
import tempfile
from .dirs import flake_registry, unfree_nixpkgs
from .dirs import nixpkgs, unfree_nixpkgs
def nix_eval(flags: list[str]) -> list[str]:
@ -13,8 +13,9 @@ def nix_eval(flags: list[str]) -> list[str]:
"--show-trace",
"--extra-experimental-features",
"nix-command flakes",
"--flake-registry",
str(flake_registry()),
"--override-input",
"nixpkgs",
str(nixpkgs()),
# --store is required to prevent this error:
# error: cannot unlink '/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh': Operation not permitted
"--store",
@ -41,8 +42,8 @@ def nix_shell(packages: list[str], cmd: list[str]) -> list[str]:
"shell",
"--extra-experimental-features",
"nix-command flakes",
"--flake-registry",
str(flake_registry()),
"--inputs-from",
".#",
]
+ wrapped_packages
+ ["-c"]

View File

@ -49,19 +49,17 @@ let
cp -r ${./.} $out
chmod -R +w $out
rm $out/clan_cli/config/jsonschema
ln -sTf ${nixpkgs} $out/clan_cli/nixpkgs
cp -r ${depsFlake} $out/clan_cli/deps_flake
cp -r ${../../lib/jsonschema} $out/clan_cli/config/jsonschema
ln -s ${ui-assets} $out/clan_cli/webui/assets
'';
nixpkgs = runCommand "nixpkgs" { } ''
mkdir -p $out/unfree
cat > $out/unfree/default.nix <<EOF
import "${pkgs.path}" { config = { allowUnfree = true; overlays = []; }; }
EOF
cat > $out/flake-registry.json <<EOF
{ "flakes": [{"exact":true,"from":{"id":"nixpkgs", "type": "indirect"},"to": {"path":"${pkgs.path}", "type":"path"}}], "version": 2}
EOF
ln -s ${pkgs.path} $out/path
depsFlake = runCommand "deps-flake" { } ''
mkdir $out
cp ${./deps-flake.nix} $out/flake.nix
${pkgs.nix}/bin/nix flake lock $out \
--store ./. \
--experimental-features 'nix-command flakes' \
--override-input nixpkgs ${pkgs.path}
'';
in
python3.pkgs.buildPythonPackage {
@ -96,7 +94,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.depsFlake = depsFlake;
passthru.devDependencies = [
setuptools
@ -106,7 +104,7 @@ python3.pkgs.buildPythonPackage {
passthru.testDependencies = dependencies ++ testDependencies;
postInstall = ''
ln -sTf ${nixpkgs} $out/${python3.sitePackages}/clan_cli/nixpkgs
cp -r ${depsFlake} $out/${python3.sitePackages}/clan_cli/deps_flake
installShellCompletion --bash --name clan \
<(${argcomplete}/bin/register-python-argcomplete --shell bash clan)
installShellCompletion --fish --name clan.fish \

View File

@ -0,0 +1,9 @@
{
description = "dependencies for the clan-cli";
inputs = {
nixpkgs.url = "nixpkgs";
};
outputs = _inputs: { };
}

View File

@ -25,14 +25,14 @@ mkShell {
PYTHONPATH = "${pythonWithDeps}/${pythonWithDeps.sitePackages}";
shellHook = ''
tmp_path=$(realpath ./.direnv)
rm -f clan_cli/nixpkgs clan_cli/assets
ln -sf ${clan-cli.nixpkgs} clan_cli/nixpkgs
ln -sf ${clan-cli.depsFlake} clan_cli/deps_flake
ln -sf ${ui-assets} clan_cli/webui/assets
export PATH="$tmp_path/bin:${checkScript}/bin:$PATH"
export PYTHONPATH="$PYTHONPATH:$(pwd)"
export XDG_DATA_DIRS="$tmp_path/share''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"
export fish_complete_path="$tmp_path/share/fish/vendor_completions.d''${fish_complete_path:+:$fish_complete_path}"
mkdir -p \

View File

@ -7,7 +7,6 @@ import pytest_subprocess.fake_process
from pytest_subprocess import utils
import clan_cli
from clan_cli.dirs import flake_registry
from clan_cli.ssh import cli
@ -34,10 +33,7 @@ def test_ssh_no_pass(
"shell",
"--extra-experimental-features",
"nix-command flakes",
"--flake-registry",
str(flake_registry()),
"nixpkgs#tor",
"nixpkgs#openssh",
fp.any(),
"-c",
"torify",
"ssh",
@ -68,11 +64,7 @@ def test_ssh_with_pass(
"shell",
"--extra-experimental-features",
"nix-command flakes",
"--flake-registry",
str(flake_registry()),
"nixpkgs#tor",
"nixpkgs#openssh",
"nixpkgs#sshpass",
fp.any(),
"-c",
"torify",
"sshpass",