Plugin to add Pijul support to the Nix package manager
#ifndef NIX_PLUGIN_PIJUL_COMPAT_H
#define NIX_PLUGIN_PIJUL_COMPAT_H

#ifdef NIX_VERSION
#include <error.hh>
#include <types.hh>
#else
#include <filesystem>
#include <string>
#include <vector>
#endif

#include <variant>

namespace nixpluginpijul
{

#ifdef NIX_VERSION
using StringList = nix::Strings;
using Path = nix::Path;
#else
using StringList = std::vector<std::string>;
using Path = std::filesystem::path;
#endif

struct OutputMode final {
    enum Units {
        Standard,
        Interactive,
    };

    struct WithOutput {
        std::string &output;
    };

    OutputMode(Units data)
        : m_data(data)
    {
    }

    OutputMode(WithOutput data)
        : m_data(data)
    {
    }

    bool interactive()
    {
        if (auto *t = get_if<Units>(&m_data)) {
            return *t == Interactive;
        } else {
            return false;
        }
    }

    std::string *output()
    {
        if (auto *t = get_if<WithOutput>(&m_data)) {
            return &t->output;
        } else {
            return nullptr;
        }
    }

private:
    std::variant<Units, WithOutput> m_data;
};

void runProcess(const char *path, const StringList &args, const char *chdir = nullptr, OutputMode mode = OutputMode::Standard);

[[noreturn]] void fatal(const char *text);

}

#endif // NIX_PLUGIN_PIJUL_COMPAT_H