-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
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);} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
systems = ["x86_64-linux"]; | ||
|
||
perSystem = {pkgs, ...}: { | ||
packages = { | ||
# instant repl with automatic flake loading | ||
repl = pkgs.callPackage ./repl {}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# modified from https://github.com/gytis-ivaskevicius/flake-utils/plus | ||
{ | ||
coreutils, | ||
gnused, | ||
writeShellScriptBin, | ||
}: let | ||
repl = ../../lib/repl.nix; | ||
example = command: desc: ''\n\u001b[33m ${command}\u001b[0m - ${desc}''; | ||
in | ||
writeShellScriptBin "repl" '' | ||
case "$1" in | ||
"-h"|"--help"|"help") | ||
printf "%b\n\e[4mUsage\e[0m: \ | ||
${example "repl" "Loads system flake if available."} \ | ||
${example "repl /path/to/flake.nix" "Loads specified flake."}\n" | ||
;; | ||
*) | ||
if [ -z "$1" ]; then | ||
nix repl ${repl} | ||
else | ||
nix repl --arg flakePath $(${coreutils}/bin/readlink -f $1 | ${gnused}/bin/sed 's|/flake.nix||') ${repl} | ||
fi | ||
;; | ||
esac | ||
'' |