Skip to content

Commit 629672a

Browse files
committed
feat: patch nix repl command
1 parent 69f3a3f commit 629672a

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
imports = [
55
modules/nix-conf.nix
66
modules/snmp
7+
modules/nix-cli
78
];
89

910
system.primaryUser = "aiotter";

flake.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
inputs = {
55
determinate.url = "https://flakehub.com/f/DeterminateSystems/determinate/3";
66
nixpkgs.follows = "determinate/nixpkgs";
7+
nix-src.follows = "determinate/nix";
78
darwin = {
89
url = "github:lnl7/nix-darwin/master";
910
inputs.nixpkgs.follows = "nixpkgs";
@@ -17,7 +18,7 @@
1718
};
1819

1920
outputs =
20-
flakeInputs@{ self, nixpkgs, darwin, determinate, mac-app-util }:
21+
flakeInputs@{ self, nixpkgs, nix-src, darwin, determinate, mac-app-util }:
2122
let
2223
inherit (nixpkgs) lib;
2324
darwinSystems = lib.systems.doubles.darwin;
@@ -35,7 +36,7 @@
3536
mac-app-util.darwinModules.default
3637
./.
3738
];
38-
specialArgs = { inherit flakeInputs; };
39+
specialArgs = { inherit flakeInputs system; };
3940
};
4041
in
4142
{

modules/nix-cli/default.nix

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
lib,
3+
flakeInputs,
4+
system,
5+
...
6+
}:
7+
8+
let
9+
patchNixCmd =
10+
dep:
11+
if lib.hasSuffix "nix-cmd" dep.pname then
12+
dep.overrideAttrs (
13+
prev:
14+
assert !(prev ? patches);
15+
{
16+
patches = [ ./nix-repl-prebind-pkgs.patch ];
17+
patchFlags = [ "-p1" "-d" "../.." ];
18+
}
19+
)
20+
else
21+
dep;
22+
23+
patchDeps = deps: builtins.map patchNixCmd deps;
24+
25+
nix-cli = flakeInputs.nix-src.packages.${system}.nix-cli.overrideAttrs (prev: {
26+
buildInputs = patchDeps (prev.buildInputs or [ ]);
27+
nativeBuildInputs = patchDeps (prev.nativeBuildInputs or [ ]);
28+
propagatedBuildInputs = patchDeps (prev.propagatedBuildInputs or [ ]);
29+
});
30+
in
31+
32+
{
33+
environment.systemPackages = [ nix-cli ];
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/src/libcmd/repl.cc b/src/libcmd/repl.cc
2+
index 841c75737..82a51838a 100644
3+
--- a/src/libcmd/repl.cc
4+
+++ b/src/libcmd/repl.cc
5+
@@ -770,6 +770,17 @@ void NixRepl::initEnv()
6+
varNames.clear();
7+
for (auto & i : state->staticBaseEnv->vars)
8+
varNames.emplace(state->symbols[i.first]);
9+
+
10+
+ // Pre-bind pkgs for convenience (best-effort).
11+
+ // Keep the REPL usable even if <nixpkgs> is missing.
12+
+ notice("Binding pkgs...");
13+
+ try {
14+
+ processLine("pkgs = import <nixpkgs> {}");
15+
+ } catch (const Error &e) {
16+
+ warn("failed to initialize pkgs: %s", e.what());
17+
+ } catch (...) {
18+
+ warn("failed to initialize pkgs (unknown error)");
19+
+ }
20+
}
21+
22+
void NixRepl::showLastLoaded()

0 commit comments

Comments
 (0)