From 6bc9fe42a2cadc771c178f289207b914e8ec37a1 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 6 Sep 2025 09:31:20 +0530 Subject: fix(os/common/nix): nix develop interactive shell --- os/common/configuration.nix | 2 +- os/common/modules/nix.nix | 33 ------------------------ os/common/modules/nix/default.nix | 51 +++++++++++++++++++++++++++++++++++++ os/common/modules/nix/nix.patch | 53 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 34 deletions(-) delete mode 100644 os/common/modules/nix.nix create mode 100644 os/common/modules/nix/default.nix create mode 100644 os/common/modules/nix/nix.patch (limited to 'os') diff --git a/os/common/configuration.nix b/os/common/configuration.nix index 7b6b956..afa5de2 100644 --- a/os/common/configuration.nix +++ b/os/common/configuration.nix @@ -12,7 +12,7 @@ in "services/networking/pppd.nix" ]; imports = [ - ./modules/nix.nix + ./modules/nix ./modules/user.nix ./modules/environment.nix ./modules/pppd.nix diff --git a/os/common/modules/nix.nix b/os/common/modules/nix.nix deleted file mode 100644 index 711ead4..0000000 --- a/os/common/modules/nix.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ config, ... }: -let - user = config.global.userdata.name; -in -{ - nix = { - gc = { - automatic = true; - dates = "weekly"; - options = "--delete-older-than 30d"; - }; - - settings = { - auto-optimise-store = true; - use-xdg-base-directories = true; - trusted-users = [ user ]; - - experimental-features = [ - "flakes" - "nix-command" - ]; - - substituters = [ - "https://nixbin.sinanmohd.com" - "https://nix-community.cachix.org" - ]; - trusted-public-keys = [ - "nixbin.sinanmohd.com:dXV3KDPVrm+cGJ2M1ZmTeQJqFGaEapqiVoWHgYDh03k=" - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - ]; - }; - }; -} diff --git a/os/common/modules/nix/default.nix b/os/common/modules/nix/default.nix new file mode 100644 index 0000000..bddf978 --- /dev/null +++ b/os/common/modules/nix/default.nix @@ -0,0 +1,51 @@ +{ + config, + pkgs, + determinate, + lib, + ... +}: +let + user = config.global.userdata.name; + + nixWithFix = determinate.inputs.nix.packages.${pkgs.stdenv.system}.nix-everything.override { + nix-cli = determinate.inputs.nix.packages.${pkgs.stdenv.system}.nix-cli.overrideAttrs (oldAttrs: { + patches = (oldAttrs.patches or [ ]) ++ [ + ./nix.patch + ]; + }); + }; +in +{ + imports = [ determinate.nixosModules.default ]; + + nix = { + package = lib.mkForce nixWithFix; + + gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 30d"; + }; + + settings = { + auto-optimise-store = true; + use-xdg-base-directories = true; + trusted-users = [ user ]; + + experimental-features = [ + "flakes" + "nix-command" + ]; + + substituters = [ + "https://nixbin.sinanmohd.com" + "https://nix-community.cachix.org" + ]; + trusted-public-keys = [ + "nixbin.sinanmohd.com:dXV3KDPVrm+cGJ2M1ZmTeQJqFGaEapqiVoWHgYDh03k=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + ]; + }; + }; +} diff --git a/os/common/modules/nix/nix.patch b/os/common/modules/nix/nix.patch new file mode 100644 index 0000000..4f565d8 --- /dev/null +++ b/os/common/modules/nix/nix.patch @@ -0,0 +1,53 @@ +diff --git a/develop.cc b/develop.cc +index ed25e655d8f..f78eee59abc 100644 +--- a/develop.cc ++++ b/develop.cc +@@ -627,13 +627,12 @@ struct CmdDevelop : Common, MixEnvironment + fmt("[ -n \"$PS1\" ] && PS1+=%s;\n", escapeShellArgAlways(developSettings.bashPromptSuffix.get())); + } + +- writeFull(rcFileFd.get(), script); +- + setEnviron(); + // prevent garbage collection until shell exits + setEnv("NIX_GCROOT", gcroot.c_str()); + + Path shell = "bash"; ++ bool foundInteractive = false; + + try { + auto state = getEvalState(); +@@ -656,19 +655,17 @@ struct CmdDevelop : Common, MixEnvironment + Strings{"legacyPackages." + settings.thisSystem.get() + "."}, + nixpkgsLockFlags); + +- bool found = false; +- + for (auto & path : Installable::toStorePathSet( + getEvalStore(), store, Realise::Outputs, OperateOn::Output, {bashInstallable})) { + auto s = store->printStorePath(path) + "/bin/bash"; + if (pathExists(s)) { + shell = s; +- found = true; ++ foundInteractive = true; + break; + } + } + +- if (!found) ++ if (!foundInteractive) + throw Error("package 'nixpkgs#bashInteractive' does not provide a 'bin/bash'"); + + } catch (Error &) { +@@ -678,6 +675,11 @@ struct CmdDevelop : Common, MixEnvironment + // Override SHELL with the one chosen for this environment. + // This is to make sure the system shell doesn't leak into the build environment. + setEnv("SHELL", shell.c_str()); ++ // https://github.com/NixOS/nix/issues/5873 ++ script += fmt("SHELL=\"%s\"\n", shell); ++ if (foundInteractive) ++ script += fmt("PATH=\"%s${PATH:+:$PATH}\"\n", std::filesystem::path(shell).parent_path()); ++ writeFull(rcFileFd.get(), script); + + #ifdef _WIN32 // TODO re-enable on Windows + throw UnimplementedError("Cannot yet spawn processes on Windows"); -- cgit v1.2.3