Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extra/git/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let
mkdir -p $out/bin

${lib.concatMapStringsSep "\n" (k: ''
cat <<'WRAPPER' > $out/bin/${k}
${pkgs.coreutils}/bin/cat <<'WRAPPER' > $out/bin/${k}
#!${pkgs.bash}/bin/bash
set -euo pipefail

Expand Down
13 changes: 7 additions & 6 deletions extra/language/c.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ in
};

config = {
devshell.packages =
[ cfg.compiler ]
++ (lib.optionals hasLibraries (map lib.getLib cfg.libraries))
++
# Assume we want pkg-config, because it's good
(lib.optionals hasIncludes ([ pkgs.pkg-config ] ++ (map lib.getDev cfg.includes)));
devshell.packages = [
cfg.compiler
]
++ (lib.optionals hasLibraries (map lib.getLib cfg.libraries))
++
# Assume we want pkg-config, because it's good
(lib.optionals hasIncludes ([ pkgs.pkg-config ] ++ (map lib.getDev cfg.includes)));

env =
(lib.optionals hasLibraries [
Expand Down
95 changes: 47 additions & 48 deletions extra/language/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,53 +37,52 @@ in
config = {
devshell.packages =
if cfg.enableDefaultToolchain then (map (tool: cfg.packageSet.${tool}) cfg.tools) else [ ];
env =
[
{
# On darwin for example enables finding of libiconv
name = "LIBRARY_PATH";
# append in case it needs to be modified
eval = "$DEVSHELL_DIR/lib";
}
{
# some *-sys crates require additional includes
name = "CFLAGS";
# append in case it needs to be modified
eval = "\"-I $DEVSHELL_DIR/include ${lib.optionalString pkgs.stdenv.isDarwin "-iframework $DEVSHELL_DIR/Library/Frameworks"}\"";
}
]
++ lib.optionals pkgs.stdenv.isDarwin [
{
# On darwin for example required for some *-sys crate compilation
name = "RUSTFLAGS";
# append in case it needs to be modified
eval = "\"-L framework=$DEVSHELL_DIR/Library/Frameworks\"";
}
{
# rustdoc uses a different set of flags
name = "RUSTDOCFLAGS";
# append in case it needs to be modified
eval = "\"-L framework=$DEVSHELL_DIR/Library/Frameworks\"";
}
{
name = "PATH";
prefix =
let
inherit (pkgs) xcbuild;
in
lib.makeBinPath [
xcbuild
"${xcbuild}/Toolchains/XcodeDefault.xctoolchain"
];
}
]
# fenix provides '.rust-src' in the 'complete' toolchain configuration
++ lib.optionals (cfg.enableDefaultToolchain && cfg.packageSet ? rust-src) [
{
# rust-analyzer may use this to quicker find the rust source
name = "RUST_SRC_PATH";
value = "${cfg.packageSet.rust-src}/lib/rustlib/src/rust/library";
}
];
env = [
{
# On darwin for example enables finding of libiconv
name = "LIBRARY_PATH";
# append in case it needs to be modified
eval = "$DEVSHELL_DIR/lib";
}
{
# some *-sys crates require additional includes
name = "CFLAGS";
# append in case it needs to be modified
eval = "\"-I $DEVSHELL_DIR/include ${lib.optionalString pkgs.stdenv.isDarwin "-iframework $DEVSHELL_DIR/Library/Frameworks"}\"";
}
]
++ lib.optionals pkgs.stdenv.isDarwin [
{
# On darwin for example required for some *-sys crate compilation
name = "RUSTFLAGS";
# append in case it needs to be modified
eval = "\"-L framework=$DEVSHELL_DIR/Library/Frameworks\"";
}
{
# rustdoc uses a different set of flags
name = "RUSTDOCFLAGS";
# append in case it needs to be modified
eval = "\"-L framework=$DEVSHELL_DIR/Library/Frameworks\"";
}
{
name = "PATH";
prefix =
let
inherit (pkgs) xcbuild;
in
lib.makeBinPath [
xcbuild
"${xcbuild}/Toolchains/XcodeDefault.xctoolchain"
];
}
]
# fenix provides '.rust-src' in the 'complete' toolchain configuration
++ lib.optionals (cfg.enableDefaultToolchain && cfg.packageSet ? rust-src) [
{
# rust-analyzer may use this to quicker find the rust source
name = "RUST_SRC_PATH";
value = "${cfg.packageSet.rust-src}/lib/rustlib/src/rust/library";
}
];
};
}
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{
docs = pkgs.writeShellApplication {
name = "docs";
meta.description = ''Run mdBook server at http://localhost:3000'';
meta.description = "Run mdBook server at http://localhost:3000";
runtimeInputs = [ pkgs.mdbook ];
text = ''
cd docs
Expand All @@ -46,7 +46,7 @@
};
bench = pkgs.writeShellApplication {
name = "benchmark";
meta.description = ''Run benchmark'';
meta.description = "Run benchmark";
runtimeInputs = [ pkgs.hyperfine ];
text = ''
cd benchmark
Expand Down
17 changes: 8 additions & 9 deletions modules/back-compat.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ in
};

# Copy the values over to the devshell module
config.devshell =
{
packages = config.packages;
packagesFrom = config.packagesFrom;
startup.bash_extra = noDepEntry config.bash.extra;
interactive.bash_interactive = noDepEntry config.bash.interactive;
}
// (lib.optionalAttrs (config.motd != null) { motd = config.motd; })
// (lib.optionalAttrs (config.name != null) { name = config.name; });
config.devshell = {
packages = config.packages;
packagesFrom = config.packagesFrom;
startup.bash_extra = noDepEntry config.bash.extra;
interactive.bash_interactive = noDepEntry config.bash.interactive;
}
// (lib.optionalAttrs (config.motd != null) { motd = config.motd; })
// (lib.optionalAttrs (config.name != null) { name = config.name; });
}
2 changes: 1 addition & 1 deletion modules/commands.nix
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ in
help = "prints this menu";
name = "menu";
command = ''
cat <<'DEVSHELL_MENU'
${pkgs.coreutils}/bin/cat <<'DEVSHELL_MENU'
${commandsToMenu config.commands}
DEVSHELL_MENU
'';
Expand Down
76 changes: 38 additions & 38 deletions modules/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ let
done

if [[ -n "''${help:-}" ]]; then
cat <<USAGE
${pkgs.coreutils}/bin/cat <<USAGE
Usage: ${cfg.name}
$0 -h | --help # show this help
$0 [--pure] # start a bash sub-shell
Expand Down Expand Up @@ -393,43 +393,42 @@ in

packages = lib.foldl' (sum: drv: sum ++ (inputsOf drv)) [ ] cfg.packagesFrom;

startup =
{
motd = lib.noDepEntry ''
__devshell-motd() {
cat <<DEVSHELL_PROMPT
${cfg.motd}
DEVSHELL_PROMPT
}

if [[ ''${DEVSHELL_NO_MOTD:-} = 1 ]]; then
# Skip if that env var is set
:
elif [[ ''${DIRENV_IN_ENVRC:-} = 1 ]]; then
# Print the motd in direnv
startup = {
motd = lib.noDepEntry ''
__devshell-motd() {
${pkgs.coreutils}/bin/cat <<DEVSHELL_PROMPT
${cfg.motd}
DEVSHELL_PROMPT
}

if [[ ''${DEVSHELL_NO_MOTD:-} = 1 ]]; then
# Skip if that env var is set
:
elif [[ ''${DIRENV_IN_ENVRC:-} = 1 ]]; then
# Print the motd in direnv
__devshell-motd
else
# Print information if the prompt is displayed. We have to make
# that distinction because `nix-shell -c "cmd"` is running in
# interactive mode.
__devshell-prompt() {
__devshell-motd
else
# Print information if the prompt is displayed. We have to make
# that distinction because `nix-shell -c "cmd"` is running in
# interactive mode.
__devshell-prompt() {
__devshell-motd
# Make it a noop
__devshell-prompt() { :; }
}
PROMPT_COMMAND=__devshell-prompt''${PROMPT_COMMAND+;$PROMPT_COMMAND}
fi
'';
}
// (lib.optionalAttrs cfg.load_profiles {
load_profiles = lib.noDepEntry ''
# Load installed profiles
for file in "$DEVSHELL_DIR/etc/profile.d/"*.sh; do
# If that folder doesn't exist, bash loves to return the whole glob
[[ -f "$file" ]] && source "$file"
done
'';
});
# Make it a noop
__devshell-prompt() { :; }
}
PROMPT_COMMAND=__devshell-prompt''${PROMPT_COMMAND+;$PROMPT_COMMAND}
fi
'';
}
// (lib.optionalAttrs cfg.load_profiles {
load_profiles = lib.noDepEntry ''
# Load installed profiles
for file in "$DEVSHELL_DIR/etc/profile.d/"*.sh; do
# If that folder doesn't exist, bash loves to return the whole glob
[[ -f "$file" ]] && source "$file"
done
'';
});

interactive = {
PS1_util = lib.noDepEntry ''
Expand Down Expand Up @@ -472,7 +471,8 @@ in
# `lib.getExe`, `nix run`, `nix bundle`, etc.
{
mainProgram = cfg.package.meta.mainProgram;
} // cfg.meta;
}
// cfg.meta;
profile = cfg.package;
passthru = {
inherit config;
Expand Down
4 changes: 2 additions & 2 deletions modules/env.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ let
else if valType == "prefix" then
''export ${name}=$(${pkgs.coreutils}/bin/realpath --canonicalize-missing "${prefix}")''${${name}+:''${${name}}}''
else if valType == "unset" then
''unset ${name}''
"unset ${name}"
else
throw "BUG in the env.nix module. This should never be reached.";
in
Expand Down Expand Up @@ -143,7 +143,7 @@ in
# This is used by bash-completions to find new completions on demand
{
name = "XDG_DATA_DIRS";
eval = ''$DEVSHELL_DIR/share:''${XDG_DATA_DIRS:-/usr/local/share:/usr/share}'';
eval = "$DEVSHELL_DIR/share:\${XDG_DATA_DIRS:-/usr/local/share:/usr/share}";
}

# A per-project data directory for runtime information.
Expand Down
3 changes: 2 additions & 1 deletion modules/eval-args.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ in
specialArgs = {
modulesPath = builtins.toString ./.;
extraModulesPath = builtins.toString ../extra;
} // extraSpecialArgs;
}
// extraSpecialArgs;
}
2 changes: 1 addition & 1 deletion modules/services.nix
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ let
command =
(pkgs.writeShellScript "${gName}-services-stop" ''
if [ -e "$PRJ_DATA_DIR/pids/${gName}.pid" ]; then
pid=$(cat "$PRJ_DATA_DIR/pids/${gName}.pid")
pid=$(${pkgs.coreutils}/bin/cat "$PRJ_DATA_DIR/pids/${gName}.pid")
kill -TERM $pid
rm "$PRJ_DATA_DIR/pids/${gName}.pid"
fi
Expand Down
12 changes: 12 additions & 0 deletions nix/mkNakedShell.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
{
lib,
runCommand,
bashInteractive,
coreutils,
stdenv,
writeTextFile,
}:
let
bashPath = "${bashInteractive}/bin/bash";
rmCommand = runCommand "coreutils-rm" { } ''
mkdir -p $out/bin
ln -s ${coreutils}/bin/rm $out/bin/rm
'';
Comment on lines +11 to +14
Copy link
Contributor Author

@phanirithvij phanirithvij Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this to avoid adding all of coreutils to the naked shell.

nakedStdenv = writeTextFile {
name = "naked-stdenv";
destination = "/setup";
text = ''
# Fix for `nix develop`
: ''${outputs:=out}
# Fix for `nix-shell --pure` line 1: rm: command not found
# occurs at `_nix_shell_clean_tmpdir` in `nixos/nix`
${lib.optionalString (builtins.getEnv "IN_NIX_SHELL" == "pure") ''
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

builtins.getEnv "IN_NIX_SHELL" doesn't seems to be problematic from my cursory running of nix develop --ignore-environment --pure-eval nix-shell nix-shell --pure etc.

This issue occurs only for nix-shell --pure and I fixed it only for that case.

export PATH=${rmCommand}/bin:$PATH
''}
runHook() {
eval "$shellHook"
unset runHook
Expand Down
Loading