diff --git a/.gitignore b/.gitignore index 296b9b39..7650c958 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .direnv result* -pkgs/clan-cli/clan_cli/deps_flake +pkgs/clan-cli/clan_cli/nixpkgs pkgs/clan-cli/clan_cli/webui/assets # python diff --git a/pkgs/clan-cli/clan_cli/config/machine.py b/pkgs/clan-cli/clan_cli/config/machine.py index 83c56be9..0dec9c13 100644 --- a/pkgs/clan-cli/clan_cli/config/machine.py +++ b/pkgs/clan-cli/clan_cli/config/machine.py @@ -6,7 +6,7 @@ from typing import Optional 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.nix import nix_eval @@ -54,7 +54,7 @@ def schema_for_machine(machine_name: str, flake: Optional[Path] = None) -> dict: f""" let flake = builtins.getFlake (toString {flake}); - lib = import {nixpkgs()}/lib; + lib = import {nixpkgs_source()}/lib; options = flake.nixosConfigurations.{machine_name}.options; clanOptions = options.clan; jsonschemaLib = import {Path(__file__).parent / "jsonschema"} {{ inherit lib; }}; diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index 7aeb33c9..064f52f0 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -1,4 +1,3 @@ -import json import os import sys from pathlib import Path @@ -31,15 +30,12 @@ def module_root() -> Path: return Path(__file__).parent -def deps_flake() -> Path: - return (module_root() / "deps_flake").resolve() +def nixpkgs_flake() -> Path: + return (module_root() / "nixpkgs").resolve() -def nixpkgs() -> Path: - # 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 nixpkgs_source() -> Path: + return (module_root() / "nixpkgs" / "path").resolve() def unfree_nixpkgs() -> Path: diff --git a/pkgs/clan-cli/clan_cli/nix.py b/pkgs/clan-cli/clan_cli/nix.py index 36e0265f..a90b29b1 100644 --- a/pkgs/clan-cli/clan_cli/nix.py +++ b/pkgs/clan-cli/clan_cli/nix.py @@ -1,7 +1,7 @@ import os 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]: @@ -15,7 +15,7 @@ def nix_eval(flags: list[str]) -> list[str]: "nix-command flakes", "--override-input", "nixpkgs", - str(nixpkgs()), + str(nixpkgs_source()), # --store is required to prevent this error: # error: cannot unlink '/nix/store/6xg259477c90a229xwmb53pdfkn6ig3g-default-builder.sh': Operation not permitted "--store", @@ -43,7 +43,7 @@ def nix_shell(packages: list[str], cmd: list[str]) -> list[str]: "--extra-experimental-features", "nix-command flakes", "--inputs-from", - f"{str(deps_flake())}", + f"{str(nixpkgs_flake())}", ] + wrapped_packages + ["-c"] diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index 890a2452..c73810b2 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -44,19 +44,33 @@ let checkPython = python3.withPackages (_ps: dependencies ++ testDependencies); # - vendor the jsonschema nix lib (copy instead of symlink). - # - lib.cleanSource prevents unnecessary rebuilds when `self` changes. source = runCommand "clan-cli-source" { } '' cp -r ${./.} $out chmod -R +w $out 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 ln -s ${ui-assets} $out/clan_cli/webui/assets ''; - depsFlake = runCommand "deps-flake" { } '' + nixpkgs = runCommand "nixpkgs" { nativeBuildInputs = [ pkgs.nix ]; } '' mkdir $out - cp ${./deps-flake.nix} $out/flake.nix - ${pkgs.nix}/bin/nix flake lock $out \ + mkdir -p $out/unfree + cat > $out/unfree/default.nix < $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 ./. \ --experimental-features 'nix-command flakes' \ --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 touch $out ''; - passthru.depsFlake = depsFlake; + passthru.nixpkgs = nixpkgs; passthru.devDependencies = [ setuptools @@ -104,7 +118,7 @@ python3.pkgs.buildPythonPackage { passthru.testDependencies = dependencies ++ testDependencies; postInstall = '' - cp -r ${depsFlake} $out/${python3.sitePackages}/clan_cli/deps_flake + 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/shell.nix b/pkgs/clan-cli/shell.nix index 0c9644ec..d3ebaab6 100644 --- a/pkgs/clan-cli/shell.nix +++ b/pkgs/clan-cli/shell.nix @@ -27,7 +27,7 @@ mkShell { tmp_path=$(realpath ./.direnv) 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 export PATH="$tmp_path/bin:${checkScript}/bin:$PATH" diff --git a/pkgs/clan-cli/tests/conftest.py b/pkgs/clan-cli/tests/conftest.py index f5db6eb2..70ebd827 100644 --- a/pkgs/clan-cli/tests/conftest.py +++ b/pkgs/clan-cli/tests/conftest.py @@ -6,7 +6,7 @@ from typing import Generator 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")) @@ -44,7 +44,7 @@ def machine_flake(monkeymodule: pytest.MonkeyPatch) -> Generator[Path, None, Non # provided by get_clan_flake_toplevel flake_nix = flake / "flake.nix" 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 monkeymodule.chdir(flake)