genco::lang::nix

Function variable

Source
pub fn variable<M, N>(name: M, value: N) -> Import
where M: Into<ItemStr>, N: Into<Tokens>,
Expand description
use genco::prelude::*;

let nixpkgs = &nix::inherit("inputs", "nixpkgs");

let pkgs = nix::variable("pkgs", quote! {
    import $nixpkgs {
        inherit ($nixpkgs) system;
        config.allowUnfree = true;
    }
});

let toks = quote! {
    $pkgs
};

assert_eq!(
    vec![
        "{",
        "    inputs,",
        "    ...",
        "}:",
        "",
        "let",
        "    inherit (inputs) nixpkgs;",
        "    pkgs = import nixpkgs {",
        "        inherit (nixpkgs) system;",
        "        config.allowUnfree = true;",
        "    };",
        "in",
        "",
        "pkgs"
    ],
    toks.to_file_vec()?
);