This is a small utility that defines a payload, that, when loaded in your nix repl session, will prepopulate useful variables from your NixOS configuration
The main function is under repl-setup
if imported as a flake.
It takes these arguments:
source
: A URL or file path to the system configurationisUrl
: Whethersource
is a flake URL
If this is unset, most URLs will failplainImport
: Whether to disregardflake.nix
and always use importpassExtra
: A list of attributes to pass through
This uses a special format to navigate attrsets. A string will be interpreted as an attribute, a list of attributes as an attribute path, and a list of a string and another list as a renamed attribute path.
If you’re using a flake this is with respect to the flake itself. If not, with respect to the configuration (calledsystem
).
By default, flakes passthroughinputs.nixpkgs
, andinputs.nixpkgs.lib
. By default, non-flakes passthroughpkgs.lib
. (pkgs
is always passed)
Flake-only arguments:
hostname
: What hostname the desired configuration is under. Otherwise it will select the first, alphabetically.
Save this as an easily accesible file (e.g. ~/repl.nix
):
let nixos-repl-setup = builtins.getFlake "github:schuelermine/nixos-repl-setup/ce5bc68652d489ebeccb6cd867b4a2c7ce669da3";
in nixos-repl-setup.repl-setup {
hostname = "GigueMowHeadGrape";
source = "git+file:///etc/nixos/";
isUrl = true;
passExtra = [ [ "l" [ "inputs" "nixpkgs" "lib" ] ] [ "inputs" "MyFlake" "fubar" "egg" ] ];
}
You can also clone the repository and use the folder directly.
For instance, I have this in ~/repl.nix
:
let repl-setup = import ./Code/nixos-repl-setup;
in repl-setup { source = "git+file:///etc/nixos"; isUrl = true; } // builtins