Enhance nx and nsh to support unstable and git nixpkgs

This commit is contained in:
Natsu Kagami 2024-10-10 16:59:52 +02:00
parent 600ba660c9
commit 267f135972
Signed by: nki
GPG key ID: 55A032EB38B49ADB

View file

@ -61,19 +61,18 @@ in
# Simplify nix usage! # Simplify nix usage!
nx = { nx = {
body = '' body = ''
set impure argparse -s 'h/help' 'impure' 'u/unstable' 'g/git' -- $argv
if test $argv[1] = "--impure" if set -q _flag_help || test (count $argv) -eq 0
set impure "--impure" echo "nx [--impure] [-u/--unstable/-g/--git] {package} [args...]"
set argv $argv[2..]
end
if test (count $argv) -gt 0
nix run $impure nixpkgs#$argv[1] -- $argv[2..]
else
echo "nx [--impure] {package} [args...]"
return 1 return 1
else
set -q _flag_impure && set impure "--impure"
set nixpkgs "nixpkgs"
set -q _flag_unstable && set nixpkgs "nixpkgs-unstable"
set -q _flag_git && set nixpkgs "github:nixOS/nixpkgs/nixpkgs-unstable"
nix run $impure $nixpkgs"#"$argv[1] -- $argv[2..]
end end
''; '';
wraps = "nix run";
description = "Runs an app from the nixpkgs store."; description = "Runs an app from the nixpkgs store.";
}; };
@ -81,25 +80,35 @@ in
description = "Spawns a shell from the given nixpkgs packages"; description = "Spawns a shell from the given nixpkgs packages";
wraps = "nix shell"; wraps = "nix shell";
body = '' body = ''
set impure function help
if test $argv[1] = "--impure" echo "nsh [--impure] [--impure] [-u/--unstable/-g/--git] {package}* [-c command args...]"
set impure "--impure"
set argv $argv[2..]
end end
if test (count $argv) -gt 0 argparse -s 'h/help' 'impure' 'u/unstable' 'g/git' -- $argv
if set -q _flag_help || test (count $argv) -eq 0
help
return 0
end
set packages $argv
set minusc (contains -i -- "-c" $argv) set minusc (contains -i -- "-c" $argv)
if test -z $minusc if test -n "$minusc"
nix shell $impure nixpkgs#$argv -c fish if test $minusc -eq 1
else if test $minusc -eq (count $argv) help
echo "nsh [--impure] {packages} [-c command args...]"
return 1
else
nix shell $impure nixpkgs#$argv[..(math $minusc - 1)] $argv[$minusc..]
end
else
echo "nsh [--impure] {packages} [-c command args...]"
return 1 return 1
end end
set packages $argv[..(math $minusc - 1)]
set argv $argv[(math $minusc + 1)..]
else
set argv "fish" "-i"
end
if test (count $packages) -eq 0
help
return 1
end
set -q _flag_impure && set impure "--impure"
set nixpkgs "nixpkgs"
set -q _flag_unstable && set nixpkgs "nixpkgs-unstable"
set -q _flag_git && set nixpkgs "github:nixOS/nixpkgs/nixpkgs-unstable"
nix shell $impure $nixpkgs"#"$packages --command $argv
''; '';
}; };
# Grep stuff # Grep stuff