cli: fix nixpkgs unfree import
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
|||||||
.direnv
|
.direnv
|
||||||
result*
|
result*
|
||||||
pkgs/clan-cli/clan_cli/deps_flake
|
pkgs/clan-cli/clan_cli/nixpkgs
|
||||||
pkgs/clan-cli/clan_cli/webui/assets
|
pkgs/clan-cli/clan_cli/webui/assets
|
||||||
|
|
||||||
# python
|
# python
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from typing import Optional
|
|||||||
|
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
|
||||||
from clan_cli.dirs import get_clan_flake_toplevel, nixpkgs
|
from clan_cli.dirs import get_clan_flake_toplevel, nixpkgs_source
|
||||||
from clan_cli.machines.folders import machine_folder, machine_settings_file
|
from clan_cli.machines.folders import machine_folder, machine_settings_file
|
||||||
from clan_cli.nix import nix_eval
|
from clan_cli.nix import nix_eval
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ def schema_for_machine(machine_name: str, flake: Optional[Path] = None) -> dict:
|
|||||||
f"""
|
f"""
|
||||||
let
|
let
|
||||||
flake = builtins.getFlake (toString {flake});
|
flake = builtins.getFlake (toString {flake});
|
||||||
lib = import {nixpkgs()}/lib;
|
lib = import {nixpkgs_source()}/lib;
|
||||||
options = flake.nixosConfigurations.{machine_name}.options;
|
options = flake.nixosConfigurations.{machine_name}.options;
|
||||||
clanOptions = options.clan;
|
clanOptions = options.clan;
|
||||||
jsonschemaLib = import {Path(__file__).parent / "jsonschema"} {{ inherit lib; }};
|
jsonschemaLib = import {Path(__file__).parent / "jsonschema"} {{ inherit lib; }};
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -31,15 +30,12 @@ def module_root() -> Path:
|
|||||||
return Path(__file__).parent
|
return Path(__file__).parent
|
||||||
|
|
||||||
|
|
||||||
def deps_flake() -> Path:
|
def nixpkgs_flake() -> Path:
|
||||||
return (module_root() / "deps_flake").resolve()
|
return (module_root() / "nixpkgs").resolve()
|
||||||
|
|
||||||
|
|
||||||
def nixpkgs() -> Path:
|
def nixpkgs_source() -> Path:
|
||||||
# load the flake.lock json file from the deps_flake and return nodes.nixpkgs.path
|
return (module_root() / "nixpkgs" / "path").resolve()
|
||||||
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 deps_flake, nixpkgs, unfree_nixpkgs
|
from .dirs import nixpkgs_flake, nixpkgs_source, unfree_nixpkgs
|
||||||
|
|
||||||
|
|
||||||
def nix_eval(flags: list[str]) -> list[str]:
|
def nix_eval(flags: list[str]) -> list[str]:
|
||||||
@@ -15,7 +15,7 @@ def nix_eval(flags: list[str]) -> list[str]:
|
|||||||
"nix-command flakes",
|
"nix-command flakes",
|
||||||
"--override-input",
|
"--override-input",
|
||||||
"nixpkgs",
|
"nixpkgs",
|
||||||
str(nixpkgs()),
|
str(nixpkgs_source()),
|
||||||
# --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",
|
||||||
@@ -43,7 +43,7 @@ def nix_shell(packages: list[str], cmd: list[str]) -> list[str]:
|
|||||||
"--extra-experimental-features",
|
"--extra-experimental-features",
|
||||||
"nix-command flakes",
|
"nix-command flakes",
|
||||||
"--inputs-from",
|
"--inputs-from",
|
||||||
f"{str(deps_flake())}",
|
f"{str(nixpkgs_flake())}",
|
||||||
]
|
]
|
||||||
+ wrapped_packages
|
+ wrapped_packages
|
||||||
+ ["-c"]
|
+ ["-c"]
|
||||||
|
|||||||
@@ -44,19 +44,33 @@ let
|
|||||||
checkPython = python3.withPackages (_ps: dependencies ++ testDependencies);
|
checkPython = python3.withPackages (_ps: dependencies ++ testDependencies);
|
||||||
|
|
||||||
# - vendor the jsonschema nix lib (copy instead of symlink).
|
# - vendor the jsonschema nix lib (copy instead of symlink).
|
||||||
# - lib.cleanSource prevents unnecessary rebuilds when `self` changes.
|
|
||||||
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 ${depsFlake} $out/clan_cli/deps_flake
|
cp -r ${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
|
||||||
'';
|
'';
|
||||||
depsFlake = runCommand "deps-flake" { } ''
|
nixpkgs = runCommand "nixpkgs" { nativeBuildInputs = [ pkgs.nix ]; } ''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
cp ${./deps-flake.nix} $out/flake.nix
|
mkdir -p $out/unfree
|
||||||
${pkgs.nix}/bin/nix flake lock $out \
|
cat > $out/unfree/default.nix <<EOF
|
||||||
|
import "${pkgs.path}" { config = { allowUnfree = true; overlays = []; }; }
|
||||||
|
EOF
|
||||||
|
cat > $out/flake.nix << EOF
|
||||||
|
{
|
||||||
|
description = "dependencies for the clan-cli";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "nixpkgs";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = _inputs: { };
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
ln -s ${pkgs.path} $out/path
|
||||||
|
nix flake lock $out \
|
||||||
--store ./. \
|
--store ./. \
|
||||||
--experimental-features 'nix-command flakes' \
|
--experimental-features 'nix-command flakes' \
|
||||||
--override-input nixpkgs ${pkgs.path}
|
--override-input nixpkgs ${pkgs.path}
|
||||||
@@ -94,7 +108,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.depsFlake = depsFlake;
|
passthru.nixpkgs = nixpkgs;
|
||||||
|
|
||||||
passthru.devDependencies = [
|
passthru.devDependencies = [
|
||||||
setuptools
|
setuptools
|
||||||
@@ -104,7 +118,7 @@ python3.pkgs.buildPythonPackage {
|
|||||||
passthru.testDependencies = dependencies ++ testDependencies;
|
passthru.testDependencies = dependencies ++ testDependencies;
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
cp -r ${depsFlake} $out/${python3.sitePackages}/clan_cli/deps_flake
|
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 \
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ mkShell {
|
|||||||
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.depsFlake} clan_cli/deps_flake
|
ln -sf ${clan-cli.nixpkgs} clan_cli/nixpkgs
|
||||||
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"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from typing import Generator
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from clan_cli.dirs import nixpkgs
|
from clan_cli.dirs import nixpkgs_source
|
||||||
|
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), "helpers"))
|
sys.path.append(os.path.join(os.path.dirname(__file__), "helpers"))
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ def machine_flake(monkeymodule: pytest.MonkeyPatch) -> Generator[Path, None, Non
|
|||||||
# provided by get_clan_flake_toplevel
|
# provided by get_clan_flake_toplevel
|
||||||
flake_nix = flake / "flake.nix"
|
flake_nix = flake / "flake.nix"
|
||||||
flake_nix.write_text(
|
flake_nix.write_text(
|
||||||
flake_nix.read_text().replace("__NIXPKGS__", str(nixpkgs()))
|
flake_nix.read_text().replace("__NIXPKGS__", str(nixpkgs_source()))
|
||||||
)
|
)
|
||||||
# check that an empty config is returned if no json file exists
|
# check that an empty config is returned if no json file exists
|
||||||
monkeymodule.chdir(flake)
|
monkeymodule.chdir(flake)
|
||||||
|
|||||||
Reference in New Issue
Block a user