juspay / omnix

🚧 A Nix wrapper to improve developer experience
https://omnix.page
GNU Affero General Public License v3.0
70 stars 5 forks source link

refactor: Initial decoupling of devour-flake interface #223

Closed srid closed 3 weeks ago

srid commented 3 weeks ago

Turns out that https://github.com/srid/devour-flake is just a specific example of a more general idea wherein we define a cross-language function: the function body defined in Nix (as derivation), with flake inputs being "arguments" to it, and the outPath of that derivation as the "return" of the function.

In devour-flake, the input arguments are "flake" (flake to be built) and "systems". We can represent this in Rust as:

pub struct DevourFlakeInput {
    /// The flake devour-flake will build
    pub flake: FlakeUrl,
    /// The systems it will build for. An empty list means all allowed systems.
    pub systems: FlakeUrl,
}

Likewise, the return of the function is a file containing all built paths, which in Rust is:

pub struct DevourFlakeOutput(pub HashSet<StorePath>);

This PR prepares the ground of creating this more generation mechanism, where the entirety of nixci's devour_flake.rs can be generalized so that it can be used for any such function (for example, #51). The result is also simpler to reason about code.