Last active
October 5, 2024 19:56
-
-
Save maurges/8ef2fc5183a313a226c473c15c42c9ab to your computer and use it in GitHub Desktop.
Use fish as nix shell. Works with other shells too
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ system, nixpkgs ? <nixpkgs> }: | |
let pkgs = import nixpkgs {inherit system;}; | |
in pkgs.stdenvNoCC.mkDerivation { | |
name = "fshell"; | |
script = pkgs.substituteAll { | |
src = ./fshell.bash; | |
bashInteractive = pkgs.bashInteractive; | |
}; | |
phases = ["installPhase"]; | |
installPhase = "mkdir -p $out/bin; install $script $out/bin/fshell"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "A very basic flake"; | |
inputs = { | |
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | |
}; | |
outputs = { self, nixpkgs }: { | |
packages.aarch64-darwin.fshell = import ./default.nix { system = "aarch64-darwin"; inherit nixpkgs; }; | |
packages.aarch64-darwin.default = self.packages.aarch64-darwin.fshell; | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!@bashInteractive@/bin/bash | |
# Taken from: https://ianthehenry.com/posts/how-to-learn-nix/nix-zshell/ | |
# Modified to use fish, and modified derivation to be able to be installed with flakes | |
# To use: EXPORT NIX_BUILD_SHELL=fshell | |
# when using nix-shell, we will be invoked like this: | |
# | |
# /path/to/result --rcfile /path/to/file | |
# | |
# When using nix-shell -i, we will be invoked like this: | |
# | |
# /path/to/result /path/to/file | |
# | |
# We use the presence of --rcfile to decide if we're supposed | |
# to be run interactively or not. | |
if [[ "$1" = "--rcfile" ]]; then | |
save_shell="$SHELL" | |
rcfile="$2" | |
source "$rcfile" | |
export SHELL="$save_shell" | |
exec $(which fish) | |
else | |
exec @bashInteractive@/bin/bash "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment