Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove workaround for interactive mode problems in CI #234

Closed
wants to merge 9 commits into from
Closed
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
34 changes: 11 additions & 23 deletions .github/workflows/ci-home.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ jobs:
home-manager-channel-ref:
- 729ab77f9e998e0989fa30140ecc91e738bc0cb1 # Pinned for current use
- master # unstable nixpkgs
include:
- os: ubuntu-22.04
cleanup-script: |
rm '/home/runner/.config/nix/nix.conf'
rm '/home/runner/.bashrc'
rm '/home/runner/.bash_logout'
- os: macos-13
# Latest macOS sets default shell as zsh, but having .bashrc except .bash_logout
cleanup-script: |
rm '/Users/runner/.config/nix/nix.conf'
rm '/Users/runner/.bashrc'

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -56,25 +45,24 @@ jobs:
- name: Print nixpkgs version after updating channels
run: nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'
- run: nix-shell '<home-manager>' -A install
- name: Clean up conflict files with applying by home-manager
run: |
${{ matrix.cleanup-script }}
- uses: actions/checkout@v3
- run: home-manager switch -f ./home-manager/user-github-actions.nix
- run: home-manager switch -b backup -f ./home-manager/user-github-actions.nix
- name: Print paths
run: |
which fish
which zsh
which bash # Be non nix shell
which bash
which ruby
which irb
# Do not use interactive mode here.
# Solutions as https://github.com/actions/runner/issues/241#issuecomment-924327172 will not fit with several problems
- name: Run customized dependencies
run: |
fish --command 'starship --version'
zsh -c 'which dprint'
zsh -c 'ruby --version'
zsh -c 'irb --version'
fish --interactive --command 'starship --version'
zsh --interactive -c 'which dprint'
zsh --interactive -c 'ruby --version'
bash -i -c 'irb --version'
shell: 'script --return --quiet --command "bash {0}"'
- name: Run homemade commands
run: zsh -c 'la'
run: |
fish --interactive --command 'bench_shells'
zsh --interactive -c 'la'
shell: 'script --return --quiet --command "bash {0}"'
4 changes: 4 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ command = 'home-manager'
args = [
'switch',
'-n', # dry-run
'-b',
'backup',
'-f',
'./home-manager/home.nix',
]
Expand All @@ -74,6 +76,8 @@ args = [
command = 'home-manager'
args = [
'switch',
'-b',
'backup',
'-f',
'./home-manager/home.nix',
]
Expand Down
4 changes: 2 additions & 2 deletions cmd/enable_nix_login_shells/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
log.Fatalln("used by root looks weird. You should run `sudo -E ...` instead of `sudo ...`")
}

loginAbles := []string{"zsh", "fish"}
loginableShells := []string{"bash", "zsh", "fish"}

etcShellsBytes, err := os.ReadFile("/etc/shells")
if err != nil {
Expand All @@ -31,7 +31,7 @@ func main() {
dirty := strings.Clone(etcShells)
examplePath := ""

for _, sh := range loginAbles {
for _, sh := range loginableShells {
shellPath := homePath + "/.nix-profile/bin/" + sh
if strings.Contains(etcShells, shellPath) {
log.Printf("skip - %s is already registered in /etc/shells\n", shellPath)
Expand Down
3 changes: 3 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

pkgs.mkShell {
buildInputs = [
# https://github.com/NixOS/nix/issues/730#issuecomment-162323824
pkgs.bashInteractive

pkgs.dprint
pkgs.shellcheck
pkgs.shfmt
Expand Down
78 changes: 78 additions & 0 deletions home-manager/bash.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{ config, ... }:

{
programs.starship.enableBashIntegration = true;
programs.direnv.enableBashIntegration = true;
programs.zoxide.enableBashIntegration = true;
programs.fzf.enableBashIntegration = true;
programs.rtx.enableBashIntegration = true;

# Used only in bash - https://unix.stackexchange.com/a/689403
# https://github.com/nix-community/home-manager/blob/master/modules/programs/readline.nix
programs.readline = {
enable = true;
variables = {
# https://man.archlinux.org/man/readline.3#bell
# option: audible, visible, none
# https://unix.stackexchange.com/questions/73672/how-to-turn-off-the-beep-only-in-bash-tab-complete
# https://github.com/nix-community/home-manager/blob/0841242b94638fcd010f7f64e56b7b1cad50c697/modules/programs/readline.nix
bell-style = "none";

# https://wiki.archlinux.jp/index.php/Readline
# https://man.archlinux.org/man/readline.3
completion-ignore-case = true;
colored-stats = true;
colored-completion-prefix = true;
visible-stats = true;
show-mode-in-prompt = false;
show-all-if-ambiguous = true;
echo-control-characters = false;
};
};

# https://github.com/nix-community/home-manager/blob/master/modules/programs/bash.nix
programs.bash = {
enable = true;

sessionVariables = {
# Cannot dynamically get from program.readline and cannot use XDG style in home-manager
# https://github.com/nix-community/home-manager/blob/0841242b94638fcd010f7f64e56b7b1cad50c697/modules/programs/readline.nix#L72
INPUTRC = "${config.home.homeDirectory}/.inputrc";
};

shellOptions = [
# Append to history file rather than replacing it.
"histappend"

# check the window size after each command and, if
# necessary, update the values of LINES and COLUMNS.
"checkwinsize"

# Extended globbing.
"extglob"
"globstar"

# Warn if closing shell with running jobs.
"checkjobs"
];

enableCompletion = true;

historySize = 100000;
historyFile = "${config.xdg.stateHome}/bash/history";
historyFileSize = 4200000;
historyControl = [ "erasedups" "ignoredups" "ignorespace" ];
historyIgnore = [ "ls" "cd" "z" ];

# Extracting because embedded here requires complex escape with nix multiline.
initExtra = builtins.readFile ./initExtra.bash;

logoutExtra = ''
# when leaving the console clear the screen to increase privacy

if [ "$SHLVL" = 1 ]; then
[ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
'';
};
}
15 changes: 1 addition & 14 deletions home-manager/home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{
imports = [
./packages.nix
./bash.nix
./zsh.nix
./fish.nix
];
Expand All @@ -29,7 +30,6 @@

home = {
sessionVariables = {
INPUTRC = "${config.home.sessionVariables.XDG_CONFIG_HOME}/readline/inputrc";
EDITOR = "code -w";
VISUAL = "nano";
PAGER = "less";
Expand Down Expand Up @@ -73,15 +73,6 @@
package = pkgs.nix;
};

programs.readline = {
enable = true;
variables = {
# https://unix.stackexchange.com/questions/73672/how-to-turn-off-the-beep-only-in-bash-tab-complete
# https://github.com/nix-community/home-manager/blob/0841242b94638fcd010f7f64e56b7b1cad50c697/modules/programs/readline.nix
bell-style = "none";
};
};

programs.lesspipe.enable = true;

programs.direnv = {
Expand Down Expand Up @@ -114,10 +105,6 @@
# Not under "starship/starship.toml"
xdg.configFile."starship.toml".source = ../home/.config/starship.toml;

# basic shell dotfiles should be put in ~/ except part of zsh files
home.file.".bashrc".source = ../home/.bashrc;
home.file.".bash_logout".source = ../home/.bash_logout;

# - stack manager can not found in https://github.com/nix-community/home-manager/tree/8d243f7da13d6ee32f722a3f1afeced150b6d4da/modules/programs
# - https://github.com/kachick/dotfiles/issues/142
home.file.".stack/config.yaml".source = ../home/.stack/config.yaml;
Expand Down
54 changes: 54 additions & 0 deletions home-manager/initExtra.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# https://github.com/Bash-it/bash-it/blob/00062bfcb6c6a68cd2c9d2c76ed764e01e930e87/plugins/available/history-substring-search.plugin.bash
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then
bind '"\e[A":history-substring-search-backward'
bind '"\e[B":history-substring-search-forward'
fi

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color | *-256color) color_prompt=yes ;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi

if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm* | rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)} \w\a\]$PS1"
;;
*) ;;

esac

# https://github.com/starship/starship/blob/0d98c4c0b7999f5a8bd6e7db68fd27b0696b3bef/docs/uk-UA/advanced-config/README.md#change-window-title
function set_win_title() {
echo -ne "\033]0; $(basename "$PWD") \007"
}
# shellcheck disable=SC2034
starship_precmd_user_func="set_win_title"
55 changes: 30 additions & 25 deletions home-manager/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,43 @@

{
home.packages = [
# Use `bashInteractive`, don't `bash` - https://github.com/NixOS/nixpkgs/issues/29960, https://github.com/NixOS/nix/issues/730
# pkgs.bash
# https://github.com/NixOS/nix/issues/730#issuecomment-162323824
pkgs.bashInteractive
# pkgs.readline # needless and using it does not fix pkgs.bash problems
pkgs.zsh
pkgs.fish
pkgs.starship
pkgs.direnv
pkgs.zoxide
pkgs.fzf

# asdf/rtx
#
# Prefer rtx now
# pkgs.asdf-vm
pkgs.rtx
#
# Required in many asdf plugins
pkgs.unzip

pkgs.git
pkgs.tig
pkgs.gh

pkgs.dprint
pkgs.gitleaks
pkgs.shellcheck
pkgs.shfmt
pkgs.git
pkgs.nixpkgs-fmt

pkgs.coreutils
pkgs.tig
pkgs.tree
pkgs.exa
pkgs.curl
pkgs.wget
pkgs.zsh
# Don't include bash - https://github.com/NixOS/nixpkgs/issues/29960, https://github.com/NixOS/nix/issues/730
# pkgs.bash
pkgs.fish
pkgs.starship
pkgs.jq
pkgs.gh
pkgs.direnv
pkgs.ripgrep
pkgs.fzf
pkgs.exa
pkgs.bat
pkgs.duf
pkgs.fd
Expand All @@ -40,22 +56,10 @@
pkgs.bottom
pkgs.tig
pkgs.zellij
pkgs.nixpkgs-fmt
pkgs.nil
pkgs.typos
pkgs.hyperfine
pkgs.zoxide
pkgs.difftastic

# asdf/rtx
#
# Using rtx now
# pkgs.asdf-vm
pkgs.rtx
#
# Required in many asdf plugins
pkgs.unzip

# Includes follows in each repository if needed, not in global
# pkgs.deno
# pkgs.rustup
Expand All @@ -67,7 +71,8 @@
# pkgs.postgresql
# pkgs.gnumake
# pkgs.cargo-make

# pkgs.gitleaks
# pkgs.nil

# https://github.com/NixOS/nixpkgs/pull/218114
pkgs.ruby_3_2
Expand Down
9 changes: 9 additions & 0 deletions home-manager/zsh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
enableAutosuggestions = true;
enableCompletion = true;

# Setting bindkey
# https://github.com/nix-community/home-manager/blob/8c731978f0916b9a904d67a0e53744ceff47882c/modules/programs/zsh.nix#L28
# https://qiita.com/yoshikaw/items/fe4aca1110979e223f7e
defaultKeymap = "emacs";

# home-manager path will set in `programs.home-manager.enable = true`;
envExtra = ''
# https://wiki.archlinux.jp/index.php/XDG_Base_Directory
Expand All @@ -61,6 +66,10 @@
setopt hist_save_no_dups
setopt hist_no_store

# Needed in my env for `Ctrl + </>` https://unix.stackexchange.com/a/58871
bindkey ";5C" forward-word
bindkey ";5D" backward-word

case ''${OSTYPE} in
darwin*)
test -e "''${HOME}/.iterm2_shell_integration.zsh" && source "''${HOME}/.iterm2_shell_integration.zsh"
Expand Down
8 changes: 0 additions & 8 deletions home/.bash_logout

This file was deleted.

Loading
Loading