nixos-configs/pkgs/repl/repl.nix
matt1432 fe7b03dd4a
All checks were successful
Discord / discord commits (push) Has been skipped
refactor: move customPkgs to self.packages
2024-06-08 22:21:04 -04:00

49 lines
1.2 KiB
Nix

{
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);}