nixos-configs/pkgs/repl/repl.nix

50 lines
1.2 KiB
Nix
Raw Normal View History

2023-12-02 14:32:48 -05:00
{
2023-12-02 14:33:22 -05:00
flakePath ? null,
2023-12-02 14:32:48 -05:00
hostnamePath ? "/etc/hostname",
registryPath ? /etc/nix/registry.json,
}: let
inherit (builtins) getFlake head match currentSystem readFile pathExists filter fromJSON;
selfFlake =
if pathExists registryPath
then filter (it: it.from.id == "self") (fromJSON (readFile registryPath)).flakes
else [];
flakePath' =
toString
(
if flakePath != null
then flakePath
else if selfFlake != []
then (head selfFlake).to.path
else "/etc/nixos"
);
flake =
if pathExists flakePath'
then getFlake flakePath'
else {};
hostname =
if pathExists hostnamePath
then head (match "([a-zA-Z0-9\\-]+)\n" (readFile hostnamePath))
else "";
nixpkgsFromInputsPath = flake.inputs.nixpkgs.outPath or "";
nixpkgs =
flake.pkgs.${currentSystem}.nixpkgs
or (
if nixpkgsFromInputsPath != ""
then import nixpkgsFromInputsPath {}
else {}
);
nixpkgsOutput = removeAttrs (nixpkgs // nixpkgs.lib or {}) ["options" "config"];
in
{inherit flake;}
// flake
// builtins
// (flake.nixosConfigurations or {})
// flake.nixosConfigurations.${hostname} or {}
// nixpkgsOutput
// {getFlake = path: getFlake (toString path);}