-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.nix
51 lines (45 loc) · 1.31 KB
/
repl.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ 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\-]+)
''
(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.darwinConfigurations or { })
// flake.nixosConfigurations.${hostname} or { }
// flake.darwinConfigurations.${hostname} or { } // nixpkgsOutput // {
getFlake = path: getFlake (toString path);
}