Skip to content

Instantly share code, notes, and snippets.

@maurges
Last active October 5, 2024 19:56
Show Gist options
  • Save maurges/8ef2fc5183a313a226c473c15c42c9ab to your computer and use it in GitHub Desktop.
Save maurges/8ef2fc5183a313a226c473c15c42c9ab to your computer and use it in GitHub Desktop.
Use fish as nix shell. Works with other shells too
{ 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";
}
{
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;
};
}
#!@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