clan-config: fix: read options from nixosConfigurations instead of nixosModules
This commit is contained in:
@@ -108,18 +108,15 @@ def options_for_machine(machine_name: str, flake: Optional[Path] = None) -> dict
|
||||
let
|
||||
flake = builtins.getFlake (toString {flake});
|
||||
lib = flake.inputs.nixpkgs.lib;
|
||||
module = flake.nixosModules.machine-{machine_name};
|
||||
evaled = lib.evalModules {{
|
||||
modules = [module];
|
||||
}};
|
||||
options = flake.nixosConfigurations.{machine_name}.options;
|
||||
|
||||
# this is actually system independent as it uses toFile
|
||||
docs = flake.inputs.nixpkgs.legacyPackages.x86_64-linux.nixosOptionsDoc {{
|
||||
inherit (evaled) options;
|
||||
inherit options;
|
||||
}};
|
||||
options = builtins.fromJSON (builtins.readFile docs.optionsJSON.options);
|
||||
opts = builtins.fromJSON (builtins.readFile docs.optionsJSON.options);
|
||||
in
|
||||
options
|
||||
opts
|
||||
""",
|
||||
],
|
||||
),
|
||||
|
||||
@@ -8,6 +8,7 @@ from fastapi import HTTPException
|
||||
|
||||
from clan_cli.dirs import get_clan_flake_toplevel, nixpkgs
|
||||
from clan_cli.machines.folders import machine_folder, machine_settings_file
|
||||
from clan_cli.nix import nix_eval
|
||||
|
||||
|
||||
def config_for_machine(machine_name: str) -> dict:
|
||||
@@ -42,30 +43,27 @@ def schema_for_machine(machine_name: str, flake: Optional[Path] = None) -> dict:
|
||||
flake = get_clan_flake_toplevel()
|
||||
# use nix eval to lib.evalModules .#nixosModules.machine-{machine_name}
|
||||
proc = subprocess.run(
|
||||
[
|
||||
"nix",
|
||||
"eval",
|
||||
"--json",
|
||||
"--impure",
|
||||
"--show-trace",
|
||||
"--extra-experimental-features",
|
||||
"nix-command flakes",
|
||||
"--expr",
|
||||
f"""
|
||||
let
|
||||
flake = builtins.getFlake (toString {flake});
|
||||
lib = import {nixpkgs()}/lib;
|
||||
module = flake.nixosModules.machine-{machine_name};
|
||||
evaled = lib.evalModules {{
|
||||
modules = [module];
|
||||
}};
|
||||
clanOptions = evaled.options.clan;
|
||||
jsonschemaLib = import {Path(__file__).parent / "jsonschema"} {{ inherit lib; }};
|
||||
jsonschema = jsonschemaLib.parseOptions clanOptions;
|
||||
in
|
||||
jsonschema
|
||||
""",
|
||||
],
|
||||
nix_eval(
|
||||
flags=[
|
||||
"--json",
|
||||
"--impure",
|
||||
"--show-trace",
|
||||
"--extra-experimental-features",
|
||||
"nix-command flakes",
|
||||
"--expr",
|
||||
f"""
|
||||
let
|
||||
flake = builtins.getFlake (toString {flake});
|
||||
lib = import {nixpkgs()}/lib;
|
||||
options = flake.nixosConfigurations.{machine_name}.options;
|
||||
clanOptions = options.clan;
|
||||
jsonschemaLib = import {Path(__file__).parent / "jsonschema"} {{ inherit lib; }};
|
||||
jsonschema = jsonschemaLib.parseOptions clanOptions;
|
||||
in
|
||||
jsonschema
|
||||
""",
|
||||
],
|
||||
),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
};
|
||||
|
||||
outputs = inputs: {
|
||||
nixosModules.machine-machine1 = ./nixosModules/machine1.nix;
|
||||
nixosConfigurations.machine1 = inputs.nixpkgs.lib.nixosSystem {
|
||||
modules = [
|
||||
inputs.self.nixosModules.machine-machine1
|
||||
(builtins.fromJSON (builtins.readFile ./machines/machine1.json))
|
||||
./nixosModules/machine1.nix
|
||||
(if builtins.pathExists ./machines/machine1.json
|
||||
then builtins.fromJSON (builtins.readFile ./machines/machine1.json)
|
||||
else { })
|
||||
{ nixpkgs.hostPlatform = "x86_64-linux"; }
|
||||
];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user