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