feat(repl): make it work with onDroid
All checks were successful
Discord / discord commits (push) Has been skipped
All checks were successful
Discord / discord commits (push) Has been skipped
This commit is contained in:
parent
b5bc4a3002
commit
1b528a15d0
2 changed files with 53 additions and 56 deletions
|
@ -2,25 +2,40 @@
|
||||||
{
|
{
|
||||||
coreutils,
|
coreutils,
|
||||||
gnused,
|
gnused,
|
||||||
writeShellScriptBin,
|
ncurses,
|
||||||
|
writeShellApplication,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
repl = ./repl.nix;
|
repl = ./repl.nix;
|
||||||
example = command: desc: ''\n\u001b[33m ${command}\u001b[0m - ${desc}'';
|
example = command: desc: ''\n$(tput setaf 3) ${command}$(tput sgr0) - ${desc}'';
|
||||||
in
|
in
|
||||||
writeShellScriptBin "repl" ''
|
writeShellApplication {
|
||||||
case "$1" in
|
name = "repl";
|
||||||
|
|
||||||
|
runtimeInputs = [coreutils gnused ncurses];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
arg=''${1:-"."}
|
||||||
|
|
||||||
|
case "$arg" in
|
||||||
"-h"|"--help"|"help")
|
"-h"|"--help"|"help")
|
||||||
printf "%b\n\e[4mUsage\e[0m: \
|
# shellcheck disable=SC2059
|
||||||
${example "repl" "Loads system flake if available."} \
|
printf "\n\e[4mUsage\e[0m: \
|
||||||
${example "repl /path/to/flake.nix" "Loads specified flake."}\n"
|
${example "repl " "Loads system flake present at $(tput setaf 4)\\$FLAKE$(tput sgr0)."} \
|
||||||
|
${example "repl <flake path>" "Loads specified flake."}\n"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$arg" ]; then
|
||||||
nix repl --arg flakePath $(${coreutils}/bin/readlink -f "$FLAKE") --file ${repl}
|
nix repl \
|
||||||
|
--arg flakePath "$(realpath "$FLAKE")" \
|
||||||
|
--file ${repl}
|
||||||
else
|
else
|
||||||
nix repl --arg flakePath $(${coreutils}/bin/readlink -f $1 | ${gnused}/bin/sed 's|/flake.nix||') --file ${repl}
|
nix repl \
|
||||||
|
--arg flakePath "$(realpath "$arg" | sed 's|/flake.nix||')" \
|
||||||
|
--file ${repl}
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
''
|
'';
|
||||||
|
}
|
||||||
|
|
|
@ -1,49 +1,31 @@
|
||||||
{
|
{
|
||||||
flakePath ? null,
|
flakePath,
|
||||||
hostnamePath ? "/etc/hostname",
|
hostnamePath ? "/etc/hostname",
|
||||||
registryPath ? /etc/nix/registry.json,
|
|
||||||
}: let
|
}: let
|
||||||
inherit (builtins) getFlake head match currentSystem readFile pathExists filter fromJSON;
|
inherit (builtins) currentSystem getFlake head match pathExists readFile removeAttrs;
|
||||||
|
|
||||||
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 =
|
hostname =
|
||||||
if pathExists hostnamePath
|
if pathExists hostnamePath
|
||||||
then head (match "([a-zA-Z0-9\\-]+)\n" (readFile hostnamePath))
|
then head (match "([a-zA-Z0-9\\-]+)\n" (readFile hostnamePath))
|
||||||
else "";
|
else "";
|
||||||
|
|
||||||
nixpkgsFromInputsPath = flake.inputs.nixpkgs.outPath or "";
|
self =
|
||||||
nixpkgs =
|
if pathExists flakePath
|
||||||
flake.pkgs.${currentSystem}.nixpkgs
|
then
|
||||||
or (
|
removeAttrs (getFlake (toString flakePath)) [
|
||||||
if nixpkgsFromInputsPath != ""
|
# If you use flakegen, these take a lot of space
|
||||||
then import nixpkgsFromInputsPath {}
|
"nextFlake"
|
||||||
else {}
|
"nextFlakeSource"
|
||||||
);
|
]
|
||||||
|
else {};
|
||||||
|
|
||||||
nixpkgsOutput = removeAttrs (nixpkgs // nixpkgs.lib or {}) ["options" "config"];
|
pkgs = self.inputs.nixpkgs.legacyPackages.${currentSystem} or {};
|
||||||
|
lib =
|
||||||
|
if pkgs != {}
|
||||||
|
then {inherit (pkgs) lib;}
|
||||||
|
else {};
|
||||||
in
|
in
|
||||||
{inherit flake;}
|
{inherit lib pkgs self;}
|
||||||
// flake
|
// self.nixosConfigurations.${hostname}
|
||||||
// builtins
|
or self.nixOnDroidConfigurations.default
|
||||||
// (flake.nixosConfigurations or {})
|
or {}
|
||||||
// flake.nixosConfigurations.${hostname} or {}
|
|
||||||
// nixpkgsOutput
|
|
||||||
// {getFlake = path: getFlake (toString path);}
|
|
||||||
|
|
Loading…
Reference in a new issue