Files
nix-stuff/common/sourceTree.nix
Shelvacu 9bad53f188 nix fmt
2025-04-19 13:17:36 -07:00

63 lines
1.6 KiB
Nix

{
inputs,
pkgs,
lib,
config,
vacuModuleType,
...
}:
let
inherit (builtins) isString isAttrs;
inherit (lib) mkOption types;
inputsOf =
flake:
assert isAttrs flake;
let
inputs = removeAttrs (flake.inputs or { }) [ "self" ];
# inputTrees = lib.mapAttrs (_: val: inputsOf val) inputs;
in
pkgs.linkFarm "inputs-tree" (inputs // { self = flake; });
# traverseInputs =
# linkDir: unfilteredInputs:
# assert isString linkDir;
# assert isAttrs unfilteredInputs;
# let
# inputs = removeAttrs unfilteredInputs [ "self" ];
# in
# lib.concatStringsSep "\n" (
# lib.mapAttrsToList (
# inputName: inputAttrs:
# let
# thisDir = linkDir + "/" + inputName;
# in
# assert isAttrs inputAttrs;
# assert isAttrs (inputAttrs.inputs or { });
# ''
# mkdir -p ${thisDir}
# ln -s ${inputAttrs} ${thisDir}/self
# ${traverseInputs thisDir (inputAttrs.inputs or { })}
# ''
# ) inputs
# );
in
{
options.vacu.sourceTree = mkOption {
readOnly = true;
type = types.package;
};
config =
{
vacu.sourceTree = inputsOf inputs.self // {
inherit inputs;
};
# vacu.sourceTree = pkgs.runCommand "inputs-tree" { } ''
# mkdir -p $out
# ln -s ${inputs.self} $out/self
# ${traverseInputs "$out" inputs}
# '';
}
// (lib.optionalAttrs (vacuModuleType == "nixos" || vacuModuleType == "nix-on-droid") {
environment.etc."vacu/sources".source = "${config.vacu.sourceTree}";
});
}