This commit is contained in:
2025-08-29 15:25:40 +02:00
parent 26440bfeee
commit f3821f0dfa
201 changed files with 2461 additions and 1546 deletions

58
lib/repl/default.nix Normal file
View File

@@ -0,0 +1,58 @@
# yanked from @fufexan
{
flakePath ? null,
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);
}