Merge pull request 'get rid of impure test' (#323) from Mic92-docs into main
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
# just some example options. Can be removed later
|
# just some example options. Can be removed later
|
||||||
./bloatware
|
./bloatware
|
||||||
./vm.nix
|
./vm.nix
|
||||||
|
./options.nix
|
||||||
];
|
];
|
||||||
options.clanSchema = lib.mkOption {
|
options.clanSchema = lib.mkOption {
|
||||||
type = lib.types.attrs;
|
type = lib.types.attrs;
|
||||||
|
|||||||
12
nixosModules/clanCore/options.nix
Normal file
12
nixosModules/clanCore/options.nix
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{ pkgs, options, lib, ... }: {
|
||||||
|
options.clanCore.optionsNix = lib.mkOption {
|
||||||
|
type = lib.types.raw;
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
default = (pkgs.nixosOptionsDoc { inherit options; }).optionsNix;
|
||||||
|
defaultText = "optionsNix";
|
||||||
|
description = ''
|
||||||
|
This is to export nixos options used for `clan config`
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -95,42 +96,25 @@ def cast(value: Any, type: Type, opt_description: str) -> Any:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def options_for_machine(machine_name: str, flake: Optional[Path] = None) -> dict:
|
def options_for_machine(machine_name: str) -> dict:
|
||||||
if flake is None:
|
clan_dir = get_clan_flake_toplevel()
|
||||||
flake = get_clan_flake_toplevel()
|
|
||||||
# use nix eval to lib.evalModules .#clanModules.machine-{machine_name}
|
# use nix eval to lib.evalModules .#clanModules.machine-{machine_name}
|
||||||
|
cmd = nix_eval(
|
||||||
|
flags=[
|
||||||
|
"--show-trace",
|
||||||
|
f"{clan_dir}#flake.nixosConfigurations.{machine_name}.config.clanCore.optionsNix",
|
||||||
|
],
|
||||||
|
)
|
||||||
proc = subprocess.run(
|
proc = subprocess.run(
|
||||||
nix_eval(
|
cmd,
|
||||||
flags=[
|
|
||||||
"--show-trace",
|
|
||||||
"--impure",
|
|
||||||
"--expr",
|
|
||||||
f"""
|
|
||||||
let
|
|
||||||
flake = builtins.getFlake (toString {flake});
|
|
||||||
lib = flake.inputs.nixpkgs.lib;
|
|
||||||
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 options;
|
|
||||||
}};
|
|
||||||
opts = builtins.fromJSON (builtins.readFile docs.optionsJSON.options);
|
|
||||||
in
|
|
||||||
opts
|
|
||||||
""",
|
|
||||||
],
|
|
||||||
),
|
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
)
|
)
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
print(proc.stderr, file=sys.stderr)
|
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"Failed to read options for machine {machine_name}:\n{proc.stderr}"
|
f"Failed to read options for machine {machine_name}:\n{shlex.join(cmd)} returned:\n{proc.stderr}"
|
||||||
)
|
)
|
||||||
options = json.loads(proc.stdout)
|
return json.loads(proc.stdout)
|
||||||
return options
|
|
||||||
|
|
||||||
|
|
||||||
def read_machine_option_value(machine_name: str, option: str) -> str:
|
def read_machine_option_value(machine_name: str, option: str) -> str:
|
||||||
|
|||||||
@@ -9,12 +9,24 @@
|
|||||||
(if builtins.pathExists ./machines/machine1/settings.json
|
(if builtins.pathExists ./machines/machine1/settings.json
|
||||||
then builtins.fromJSON (builtins.readFile ./machines/machine1/settings.json)
|
then builtins.fromJSON (builtins.readFile ./machines/machine1/settings.json)
|
||||||
else { })
|
else { })
|
||||||
{
|
({ lib, options, pkgs, ... }: {
|
||||||
nixpkgs.hostPlatform = "x86_64-linux";
|
config = {
|
||||||
# speed up by not instantiating nixpkgs twice and disable documentation
|
nixpkgs.hostPlatform = "x86_64-linux";
|
||||||
nixpkgs.pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
|
# speed up by not instantiating nixpkgs twice and disable documentation
|
||||||
documentation.enable = false;
|
nixpkgs.pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
|
||||||
}
|
documentation.enable = false;
|
||||||
|
};
|
||||||
|
options.clanCore.optionsNix = lib.mkOption {
|
||||||
|
type = lib.types.raw;
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
default = (pkgs.nixosOptionsDoc { inherit options; }).optionsNix;
|
||||||
|
defaultText = "optionsNix";
|
||||||
|
description = ''
|
||||||
|
This is to export nixos options used for `clan config`
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user