forked from clan/clan-core
clan-cli: use dependency flake instead of registry
This commit is contained in:
parent
c9bfd0a5b5
commit
fcbc3ec899
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -30,12 +31,15 @@ def module_root() -> Path:
|
|||||||
return Path(__file__).parent
|
return Path(__file__).parent
|
||||||
|
|
||||||
|
|
||||||
def flake_registry() -> Path:
|
def deps_flake() -> Path:
|
||||||
return module_root() / "nixpkgs" / "flake-registry.json"
|
return module_root() / "deps_flake"
|
||||||
|
|
||||||
|
|
||||||
def nixpkgs() -> Path:
|
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:
|
def unfree_nixpkgs() -> Path:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from .dirs import flake_registry, unfree_nixpkgs
|
from .dirs import nixpkgs, unfree_nixpkgs
|
||||||
|
|
||||||
|
|
||||||
def nix_eval(flags: list[str]) -> list[str]:
|
def nix_eval(flags: list[str]) -> list[str]:
|
||||||
@ -13,8 +13,9 @@ def nix_eval(flags: list[str]) -> list[str]:
|
|||||||
"--show-trace",
|
"--show-trace",
|
||||||
"--extra-experimental-features",
|
"--extra-experimental-features",
|
||||||
"nix-command flakes",
|
"nix-command flakes",
|
||||||
"--flake-registry",
|
"--override-input",
|
||||||
str(flake_registry()),
|
"nixpkgs",
|
||||||
|
str(nixpkgs()),
|
||||||
# --store is required to prevent this error:
|
# --store is required to prevent this error:
|
||||||
# error: cannot unlink '/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh': Operation not permitted
|
# error: cannot unlink '/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh': Operation not permitted
|
||||||
"--store",
|
"--store",
|
||||||
@ -41,8 +42,8 @@ def nix_shell(packages: list[str], cmd: list[str]) -> list[str]:
|
|||||||
"shell",
|
"shell",
|
||||||
"--extra-experimental-features",
|
"--extra-experimental-features",
|
||||||
"nix-command flakes",
|
"nix-command flakes",
|
||||||
"--flake-registry",
|
"--inputs-from",
|
||||||
str(flake_registry()),
|
".#",
|
||||||
]
|
]
|
||||||
+ wrapped_packages
|
+ wrapped_packages
|
||||||
+ ["-c"]
|
+ ["-c"]
|
||||||
|
@ -49,19 +49,17 @@ let
|
|||||||
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
|
||||||
ln -sTf ${nixpkgs} $out/clan_cli/nixpkgs
|
cp -r ${depsFlake} $out/clan_cli/deps_flake
|
||||||
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" { } ''
|
depsFlake = runCommand "deps-flake" { } ''
|
||||||
mkdir -p $out/unfree
|
mkdir $out
|
||||||
cat > $out/unfree/default.nix <<EOF
|
cp ${./deps-flake.nix} $out/flake.nix
|
||||||
import "${pkgs.path}" { config = { allowUnfree = true; overlays = []; }; }
|
${pkgs.nix}/bin/nix flake lock $out \
|
||||||
EOF
|
--store ./. \
|
||||||
cat > $out/flake-registry.json <<EOF
|
--experimental-features 'nix-command flakes' \
|
||||||
{ "flakes": [{"exact":true,"from":{"id":"nixpkgs", "type": "indirect"},"to": {"path":"${pkgs.path}", "type":"path"}}], "version": 2}
|
--override-input nixpkgs ${pkgs.path}
|
||||||
EOF
|
|
||||||
ln -s ${pkgs.path} $out/path
|
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
python3.pkgs.buildPythonPackage {
|
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
|
${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.depsFlake = depsFlake;
|
||||||
|
|
||||||
passthru.devDependencies = [
|
passthru.devDependencies = [
|
||||||
setuptools
|
setuptools
|
||||||
@ -106,7 +104,7 @@ python3.pkgs.buildPythonPackage {
|
|||||||
passthru.testDependencies = dependencies ++ testDependencies;
|
passthru.testDependencies = dependencies ++ testDependencies;
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
ln -sTf ${nixpkgs} $out/${python3.sitePackages}/clan_cli/nixpkgs
|
cp -r ${depsFlake} $out/${python3.sitePackages}/clan_cli/deps_flake
|
||||||
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 \
|
||||||
|
9
pkgs/clan-cli/deps-flake.nix
Normal file
9
pkgs/clan-cli/deps-flake.nix
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
description = "dependencies for the clan-cli";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "nixpkgs";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = _inputs: { };
|
||||||
|
}
|
@ -25,14 +25,14 @@ mkShell {
|
|||||||
PYTHONPATH = "${pythonWithDeps}/${pythonWithDeps.sitePackages}";
|
PYTHONPATH = "${pythonWithDeps}/${pythonWithDeps.sitePackages}";
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
tmp_path=$(realpath ./.direnv)
|
tmp_path=$(realpath ./.direnv)
|
||||||
|
|
||||||
rm -f clan_cli/nixpkgs clan_cli/assets
|
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
|
ln -sf ${ui-assets} clan_cli/webui/assets
|
||||||
|
|
||||||
export PATH="$tmp_path/bin:${checkScript}/bin:$PATH"
|
export PATH="$tmp_path/bin:${checkScript}/bin:$PATH"
|
||||||
export PYTHONPATH="$PYTHONPATH:$(pwd)"
|
export PYTHONPATH="$PYTHONPATH:$(pwd)"
|
||||||
|
|
||||||
export XDG_DATA_DIRS="$tmp_path/share''${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"
|
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}"
|
export fish_complete_path="$tmp_path/share/fish/vendor_completions.d''${fish_complete_path:+:$fish_complete_path}"
|
||||||
mkdir -p \
|
mkdir -p \
|
||||||
|
@ -7,7 +7,6 @@ import pytest_subprocess.fake_process
|
|||||||
from pytest_subprocess import utils
|
from pytest_subprocess import utils
|
||||||
|
|
||||||
import clan_cli
|
import clan_cli
|
||||||
from clan_cli.dirs import flake_registry
|
|
||||||
from clan_cli.ssh import cli
|
from clan_cli.ssh import cli
|
||||||
|
|
||||||
|
|
||||||
@ -34,10 +33,7 @@ def test_ssh_no_pass(
|
|||||||
"shell",
|
"shell",
|
||||||
"--extra-experimental-features",
|
"--extra-experimental-features",
|
||||||
"nix-command flakes",
|
"nix-command flakes",
|
||||||
"--flake-registry",
|
fp.any(),
|
||||||
str(flake_registry()),
|
|
||||||
"nixpkgs#tor",
|
|
||||||
"nixpkgs#openssh",
|
|
||||||
"-c",
|
"-c",
|
||||||
"torify",
|
"torify",
|
||||||
"ssh",
|
"ssh",
|
||||||
@ -68,11 +64,7 @@ def test_ssh_with_pass(
|
|||||||
"shell",
|
"shell",
|
||||||
"--extra-experimental-features",
|
"--extra-experimental-features",
|
||||||
"nix-command flakes",
|
"nix-command flakes",
|
||||||
"--flake-registry",
|
fp.any(),
|
||||||
str(flake_registry()),
|
|
||||||
"nixpkgs#tor",
|
|
||||||
"nixpkgs#openssh",
|
|
||||||
"nixpkgs#sshpass",
|
|
||||||
"-c",
|
"-c",
|
||||||
"torify",
|
"torify",
|
||||||
"sshpass",
|
"sshpass",
|
||||||
|
Loading…
Reference in New Issue
Block a user