forked from M-Labs/nix-scripts
nixops: use fish and fish-nix-shell consistently
This commit is contained in:
parent
9617de32f9
commit
6e8e2824a9
@ -31,6 +31,7 @@ in
|
||||
wireshark pavucontrol
|
||||
jq ark sublime3 rink qemu_kvm konsole
|
||||
tmux xc3sprog m-labs.openocd screen gdb minicom picocom
|
||||
(import ./fish-nix-shell)
|
||||
];
|
||||
programs.wireshark.enable = true;
|
||||
|
||||
@ -75,6 +76,9 @@ in
|
||||
hardware.bluetooth.enable = true;
|
||||
|
||||
programs.fish.enable = true;
|
||||
programs.fish.promptInit = ''
|
||||
fish-nix-shell --info-right | source
|
||||
'';
|
||||
users.defaultUserShell = pkgs.fish;
|
||||
users.extraGroups.plugdev = { };
|
||||
users.extraUsers.sb = {
|
||||
|
21
nixops/fish-nix-shell/LICENSE
Normal file
21
nixops/fish-nix-shell/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 haslersn
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
50
nixops/fish-nix-shell/README.md
Normal file
50
nixops/fish-nix-shell/README.md
Normal file
@ -0,0 +1,50 @@
|
||||
# fish-nix-shell
|
||||
fish support for the *nix-shell* environment of the Nix package manager.
|
||||
|
||||
## Installation
|
||||
|
||||
### Installation in the user environment
|
||||
|
||||
Execute
|
||||
|
||||
```
|
||||
nix-env -if https://github.com/haslersn/fish-nix-shell/archive/master.tar.gz
|
||||
```
|
||||
|
||||
and add the following to your *~/.config/fish/config.fish*. Create it if it doesn't exist.
|
||||
|
||||
```
|
||||
fish-nix-shell --info-right | source
|
||||
```
|
||||
|
||||
### System-wide installation
|
||||
|
||||
Add the package to your */etc/nixos/configuration.nix*:
|
||||
|
||||
```
|
||||
environment.systemPackages = with pkgs; [
|
||||
#
|
||||
# Other packages here ...
|
||||
#
|
||||
(import (fetchGit "https://github.com/haslersn/fish-nix-shell"))
|
||||
];
|
||||
```
|
||||
|
||||
and then execute: `sudo nixos-rebuild switch`
|
||||
|
||||
If you want to configure it system-wide, also add:
|
||||
|
||||
```
|
||||
programs.fish.enable = true;
|
||||
programs.fish.promptInit = ''
|
||||
fish-nix-shell --info-right | source
|
||||
'';
|
||||
```
|
||||
|
||||
## Flags
|
||||
|
||||
The `fish-nix-shell` command **optionally** takes the following flags:
|
||||
|
||||
| Flag | Meaning |
|
||||
| - | - |
|
||||
| `--info-right` | While in a *fish-nix-shell*, display information about the loaded packages at the right.
|
34
nixops/fish-nix-shell/bin/fish-nix-shell
Executable file
34
nixops/fish-nix-shell/bin/fish-nix-shell
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
|
||||
function init_fish () {
|
||||
cat <<EOF
|
||||
|
||||
# Overwrite the nix-shell command
|
||||
function nix-shell
|
||||
fish-nix-shell-wrapper \$argv
|
||||
set -gx FISH_NIX_SHELL_EXIT_STATUS \$status
|
||||
end
|
||||
EOF
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--info-right)
|
||||
cat <<EOF
|
||||
|
||||
# Print additional information inside a nix-shell environment
|
||||
function fish_right_prompt
|
||||
nix-shell-info
|
||||
set -e FISH_NIX_SHELL_EXIT_STATUS
|
||||
end
|
||||
EOF
|
||||
;;
|
||||
*) exit 1;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
cat <<EOF
|
||||
# If you see this output, you probably forgot to pipe this output into 'source':
|
||||
# fish-nix-shell $@ | source
|
||||
EOF
|
||||
|
||||
init_fish "$@"
|
22
nixops/fish-nix-shell/bin/fish-nix-shell-wrapper
Executable file
22
nixops/fish-nix-shell/bin/fish-nix-shell-wrapper
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
fns () {
|
||||
pkgs=$FISH_NIX_SHELL_PKGS
|
||||
for arg in "$@"; do
|
||||
if [[ $arg == -* ]]; then
|
||||
pkg=
|
||||
if [[ $arg == --pure ]] || [[ $arg == --command ]] || [[ $arg == --run ]]; then
|
||||
command nix-shell $@
|
||||
return
|
||||
elif [[ $arg == -p ]] || [[ $arg == --packages ]]; then
|
||||
pkg=1
|
||||
fi
|
||||
elif [[ $pkg == 1 ]]; then
|
||||
pkgs+=" "$arg
|
||||
fi
|
||||
done
|
||||
if [[ -n $name ]] && [[ $name != shell ]]; then
|
||||
pkgs+=" "$name
|
||||
fi
|
||||
env FISH_NIX_SHELL_PKGS="$pkgs" nix-shell "$@" --command fish
|
||||
}
|
||||
fns "$@"
|
21
nixops/fish-nix-shell/bin/nix-shell-info
Executable file
21
nixops/fish-nix-shell/bin/nix-shell-info
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
if [[ $IN_NIX_SHELL != "" ]]; then
|
||||
printf "\033[1;32m"
|
||||
output=$(echo $FISH_NIX_SHELL_PKGS | xargs)
|
||||
if [[ -n $name ]] && [[ $name != shell ]]; then
|
||||
output+=" "$name
|
||||
fi
|
||||
if [[ -n $output ]]; then
|
||||
output=$(echo $output $additional_pkgs | tr ' ' '\n' | sort -u | tr '\n' ' ' | xargs)
|
||||
printf "$output "
|
||||
else
|
||||
printf "[unknown nix-shell] "
|
||||
fi
|
||||
printf "\033[0m"
|
||||
elif [[ $FISH_NIX_SHELL_EXIT_STATUS ]]; then
|
||||
if [[ $FISH_NIX_SHELL_EXIT_STATUS == 0 ]]; then
|
||||
printf "\033[1;36mexited nix-shell \033[0m"
|
||||
else
|
||||
printf "\033[1;31mERROR \033[0m"
|
||||
fi
|
||||
fi
|
16
nixops/fish-nix-shell/default.nix
Normal file
16
nixops/fish-nix-shell/default.nix
Normal file
@ -0,0 +1,16 @@
|
||||
with import <nixpkgs> {}; stdenv.mkDerivation rec {
|
||||
name = "fish-nix-shell";
|
||||
src = fetchGit "https://github.com/haslersn/fish-nix-shell";
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
installPhase = ''
|
||||
mkdir -p $out
|
||||
cp LICENSE $out
|
||||
cp -r bin $out
|
||||
wrapProgram $out/bin/fish-nix-shell
|
||||
wrapProgram $out/bin/fish-nix-shell-wrapper --prefix PATH ":" ${fish}/bin
|
||||
wrapProgram $out/bin/nix-shell-info
|
||||
'';
|
||||
meta.description = "fish support for the nix-shell environment of the Nix package manager.";
|
||||
meta.license = "MIT";
|
||||
meta.homepage = https://github.com/haslersn/fish-nix-shell;
|
||||
}
|
@ -87,7 +87,13 @@ in
|
||||
documentation.enable = false;
|
||||
environment.systemPackages = with pkgs; [
|
||||
psmisc wget vim git usbutils lm_sensors file telnet mosh tmux xc3sprog m-labs.openocd screen gdb minicom picocom
|
||||
(import ./fish-nix-shell)
|
||||
];
|
||||
programs.fish.enable = true;
|
||||
programs.fish.promptInit = ''
|
||||
fish-nix-shell --info-right | source
|
||||
'';
|
||||
users.defaultUserShell = pkgs.fish;
|
||||
|
||||
nix.binaryCachePublicKeys = ["nixbld.m-labs.hk-1:5aSRVA5b320xbNvu30tqxVPXpld73bhtOeH6uAjRyHc="];
|
||||
nix.binaryCaches = ["https://cache.nixos.org" "https://nixbld.m-labs.hk"];
|
||||
|
Loading…
Reference in New Issue
Block a user