Skip to content

Commit

Permalink
nixos/binsh.nix: Extract module
Browse files Browse the repository at this point in the history
  • Loading branch information
roberth committed Dec 9, 2021
1 parent 6adab4c commit 25093d7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
40 changes: 40 additions & 0 deletions nixos/modules/config/binsh.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ config, lib, utils, pkgs, ... }:

with lib;

let

cfg = config.environment;
in
{
options = {
environment.binsh = mkOption {
default = "${config.system.build.binsh}/bin/sh";
defaultText = literalExpression ''"''${config.system.build.binsh}/bin/sh"'';
example = literalExpression ''"''${pkgs.dash}/bin/dash"'';
type = types.path;
visible = false;
description = ''
The shell executable that is linked system-wide to
<literal>/bin/sh</literal>. Please note that NixOS assumes all
over the place that shell to be Bash, so override the default
setting only if you know exactly what you're doing.
'';
};
};


config = {
system.build.binsh = pkgs.bashInteractive;

system.activationScripts.binsh = stringAfter [ "stdio" ]
''
# Create the required /bin/sh symlink; otherwise lots of things
# (notably the system() function) won't work.
mkdir -m 0755 -p /bin
ln -sfn "${cfg.binsh}" /bin/.sh.tmp
mv /bin/.sh.tmp /bin/sh # atomically replace /bin/sh
'';

};
}
25 changes: 0 additions & 25 deletions nixos/modules/config/shells-environment.nix
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,6 @@ in
type = types.bool;
};

environment.binsh = mkOption {
default = "${config.system.build.binsh}/bin/sh";
defaultText = literalExpression ''"''${config.system.build.binsh}/bin/sh"'';
example = literalExpression ''"''${pkgs.dash}/bin/dash"'';
type = types.path;
visible = false;
description = ''
The shell executable that is linked system-wide to
<literal>/bin/sh</literal>. Please note that NixOS assumes all
over the place that shell to be Bash, so override the default
setting only if you know exactly what you're doing.
'';
};

environment.shells = mkOption {
default = [];
example = literalExpression "[ pkgs.bashInteractive pkgs.zsh ]";
Expand All @@ -163,8 +149,6 @@ in

config = {

system.build.binsh = pkgs.bashInteractive;

# Set session variables in the shell as well. This is usually
# unnecessary, but it allows changes to session variables to take
# effect without restarting the session (e.g. by opening a new
Expand Down Expand Up @@ -210,15 +194,6 @@ in
''}
'';

system.activationScripts.binsh = stringAfter [ "stdio" ]
''
# Create the required /bin/sh symlink; otherwise lots of things
# (notably the system() function) won't work.
mkdir -m 0755 -p /bin
ln -sfn "${cfg.binsh}" /bin/.sh.tmp
mv /bin/.sh.tmp /bin/sh # atomically replace /bin/sh
'';

};

}
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
./config/binsh.nix
./config/debug-info.nix
./config/fonts/fontconfig.nix
./config/fonts/fontdir.nix
Expand Down

0 comments on commit 25093d7

Please sign in to comment.