.files/default.nix
2025-06-22 18:39:26 +02:00

82 lines
2.3 KiB
Nix

{sources ? import ./nix/sources.nix}: rec {
lib = import (sources.nixpkgs + "/lib");
nixosConfigurations = builtins.mapAttrs (_: import (sources.nixpkgs + "/nixos/lib/eval-config.nix")) {
vanadium = {
system = "x86_64-linux";
modules = [./nix/configurations/vanadium.nix];
};
tungsten = {
system = "x86_64-linux";
modules = [./nix/configurations/tungsten.nix];
};
installer = {
system = "x86_64-linux";
modules = [./nix/configurations/installer.nix];
};
};
inherit (nixosConfigurations.vanadium) options;
/*
Idea:
We only have filepath based information on where an option is set.
The oniginal goal was to be able to tell by flipping on which option, which other option(s) will be impacted.
This is hence not possible because not all options are guarded by a `enable` option, for example.
We could draw out file -> option, and cluster each option in a file rectangle
*/
# Drop those that fail to eval
filtered = let
drop = path: {
inherit path;
update = _: {};
};
in
lib.updateManyAttrsByPath
(map drop [
["_module"]
["services" "immich"] # caused by option referencing a config value
["services" "nagios"]
["hardware" "nvidia"]
])
options;
# Transform each option to its path and call site
mapped =
lib.mapAttrsRecursiveCond
(as: !(as ? _type && as._type == "option"))
(
_: v: let
definedBy = builtins.tryEval (map (x: x.file) v.definitionsWithLocations);
in
lib.optionalAttrs definedBy.success {
_type = "result";
optionPath = v.loc;
definedBy = definedBy.value;
declaredAt = map (x: x.file) v.declarationPositions;
}
)
filtered;
attrValuesRecursiveCond = cond: attrs:
if lib.isAttrs attrs && cond attrs
then
lib.flatten (
map (attrValuesRecursiveCond cond) (builtins.attrValues attrs)
)
else [attrs];
# Run `nix eval --json -f ./. 'asList' | jq >asList.json` to generate
asList = let
untag = map (lib.flip lib.removeAttrs ["_type"]);
in
untag (
attrValuesRecursiveCond
(as: !(as ? _type && as._type == "result"))
mapped
);
packages = import ./nix/packages {inherit sources;};
}