compose2arion/convert.nix
2024-03-31 00:37:06 +01:00

26 lines
No EOL
773 B
Nix

let
pkgs = import <nixpkgs> {};
lib = pkgs.lib;
readData = builtins.fromJSON (builtins.readFile "/dev/stdin");
convertEnvsToStrings = envs: lib.mapAttrs (_: value:
if lib.isBool value then
if value then "true" else "false"
else
toString value) envs;
transformService = name: service:
let
serviceTransformed = lib.mapAttrs
(n: v: if n == "environment" then convertEnvsToStrings v else v)
service;
in
{ service = serviceTransformed; };
transformedConfig =
{ services = lib.mapAttrs transformService readData.services; }
// lib.optionalAttrs (readData ? networks) { networks = readData.networks; }
// lib.optionalAttrs (readData ? volumes) { volumes = readData.volumes; };
in transformedConfig