nix_build/
exprs.rs

1use std::path::Path;
2
3const GITHUB_LOCKED_NIXPKGS: &str = std::include_str!("exprs/github_locked_nixpkgs.nix");
4
5/// Returns an expression that will evaluate to the nixpkgs set specified by the given flake lock file
6///
7/// `nixpkgs_name` will default to "nixpkgs", but should match the flake input name that is to be used
8pub fn nixpkgs_from_flake(lockfile: impl AsRef<Path>, nixpkgs_name: Option<&str>) -> String {
9    let path = lockfile.as_ref().display();
10    let nixpkgs = nixpkgs_name.unwrap_or("nixpkgs");
11
12    format!(
13        r##"
14let
15    lock = builtins.fromJSON (builtins.readFile {path});
16    nixpkgs_node = lock.nodes.{nixpkgs}.locked;
17    nixpkgs = ({GITHUB_LOCKED_NIXPKGS}) {{ rev = nixpkgs_node.rev; sha256 = nixpkgs_node.narHash; }};
18in
19    import nixpkgs {{}}
20"##
21    )
22}