Here’s a module do this in a NixOS configuration, in the same way /usr/bin/env works. Perhaps we should consider it for NixOS?
{ config, lib, pkgs, ... }:
with lib;
{
options = {
environment.binbash = mkOption {
default = null;
type = types.nullOr types.path;
description = ''
Include a /bin/bash in the system.
'';
};
};
config = {
system.activationScripts.binbash = if config.environment.binbash != null
then ''
mkdir -m 0755 -p /bin
ln -sfn ${config.environment.usrbinenv} /bin/.bash.tmp
mv /bin/.bash.tmp /usr/bin/bash # atomically replace /usr/bin/env
''
else ''
rm -f /bin/bash
rmdir -p /bin || true
'';
};
}