feat: Filter userdata.json input so we don't pass undefined items

This commit is contained in:
Inex Code 2024-12-15 03:45:46 +03:00
parent 8276d8c8ce
commit af2f0014c5
No known key found for this signature in database

View file

@ -25,9 +25,32 @@
deployment deployment
./configuration.nix ./configuration.nix
selfprivacy-api.nixosModules.default selfprivacy-api.nixosModules.default
{ (
let
deepFilter = ref: attrset:
builtins.foldl'
(acc: key:
if builtins.hasAttr key ref then
let
value = attrset.${key};
refValue = ref.${key};
in
acc // {
${key} =
if builtins.isAttrs value && builtins.isAttrs refValue then
deepFilter refValue value
else
value;
}
else
acc
)
{ }
(builtins.attrNames attrset);
in
{ options, ... }: {
# pass userdata (parsed from JSON) options to selfprivacy module # pass userdata (parsed from JSON) options to selfprivacy module
selfprivacy = userdata; selfprivacy = deepFilter options.selfprivacy userdata;
# embed top-level flake source folder into the build # embed top-level flake source folder into the build
environment.etc."selfprivacy/nixos-config-source".source = environment.etc."selfprivacy/nixos-config-source".source =
@ -47,6 +70,7 @@
cp -r --no-preserve=all ${top-level-flake}/ -T /etc/nixos/ cp -r --no-preserve=all ${top-level-flake}/ -T /etc/nixos/
''; '';
} }
)
] ]
++ ++
# add SP modules, but constrain available config attributes for each # add SP modules, but constrain available config attributes for each