#! /usr/bin/env cached-nix-shell
#! nix-shell -i python3 -p python python3Packages.pexpect

import os
import sys
import pexpect

def main():
    prompt = ["nix-repl> "]
    child = pexpect.spawn("nix repl" + " ".join(sys.argv[2:]))
    child.logfile = sys.stdout.buffer

    child.expect(prompt)
    child.sendline(':a builtins.getFlake "github:nixos/nixpkgs"')
    child.expect(prompt)
    child.sendline(':a outputs.lib')
    child.expect(prompt)
    child.sendline(':a builtins')
    child.expect(prompt)
    child.sendline('pkgs = legacyPackages.x86_64-linux.pkgs')
    child.expect(prompt)
    child.logfile = None
    child.interact()

if __name__ == '__main__':
    main()
