nix/home/program/bash/module/Nix.nix

84 lines
2 KiB
Nix
Raw Normal View History

2024-11-04 04:37:29 +03:00
{ ... }: {
text = ''
# Spawn shell with specified nix environment.
# Uses flake.nix in current dir by default.
# Usage: shell [NAME]
function shell() {
local target="''${1}"
[[ "''${target}" = "" ]] && target="default"
2024-11-04 04:37:29 +03:00
SHELL_NAME="''${target}" nix develop ".#''${target}"
}
2024-11-04 04:37:29 +03:00
# Spawn temporary nix-shell with specified packages.
# Usage: tmpshell <PACKAGES>
function tmpshell() {
local IFS=$'\n'
local input=("''${@}")
local pkgs=()
local tag="''${1}"
2024-11-04 04:37:29 +03:00
if [[ "''${input}" = "" ]]; then
help tmpshell
return 2
fi
2024-11-04 04:37:29 +03:00
for pkg in ''${input[@]}; do
pkgs+=("nixpkgs#''${pkg}")
done
2024-11-04 04:37:29 +03:00
SHELL_NAME="''${tag}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure ''${pkgs[@]}
}
2024-11-04 04:37:29 +03:00
# Run stuff directrly from Nixpks.
# Usage: nixpkgs_run <REV> <PACKAGE> [COMMAND]
function nixpkgs_run() {
local rev="''${1}"
local pkg="''${2}"
local cmd="''${@:3}"
2024-11-04 04:37:29 +03:00
if [[ "''${pkg}" = "" ]]; then
help nixpkgs_run
return 2
fi
2024-11-04 04:37:29 +03:00
[[ "''${cmd}" = "" ]] && cmd="''${pkg}"
2024-11-04 04:37:29 +03:00
SHELL_NAME="''${pkg}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure github:NixOS/nixpkgs/''${rev}#''${pkg} -c ''${cmd}
}
2024-10-22 11:21:28 +03:00
2024-11-04 04:37:29 +03:00
# Prefetch to nix store.
# Usage: prefetch <URL>
function prefetch() {
local url="''${1}"
2024-10-22 11:21:28 +03:00
2024-11-04 04:37:29 +03:00
if [[ "''${url}" = "" ]]; then
help prefetch
return 2
fi
2024-10-22 11:21:28 +03:00
local result=$(nix hash convert to-sri --type sha256 $(nix-prefetch-url "''${url}"))
2024-11-06 04:26:44 +03:00
printf "%s" ''${result} | copy
printf "%s\n" ''${result}
2024-11-04 04:37:29 +03:00
}
2024-10-24 11:50:06 +03:00
2024-11-04 04:37:29 +03:00
# Run nix locally with no builders.
# Usage: nix_local <COMMAND>
function nix_local() {
nix --option max-jobs $(_core_count) --builders "" --substituters https://cache.nixos.org ''${@}
}
2024-10-24 16:14:34 +03:00
2024-11-04 04:37:29 +03:00
# Run test app from other people PRs.
# Usage: nix_test github:user/nixpkgs/<REV>#<PKG>
function nix_test() {
if [[ "''${@}" = "" ]]; then
help nix_test
return 2
fi
2024-10-24 16:14:34 +03:00
2024-11-04 04:37:29 +03:00
local name=''${*##*#}
SHELL_NAME="''${name}" NIXPKGS_ALLOW_UNFREE=1 nix --option max-jobs $(_core_count) --builders "" --substituters https://cache.nixos.org shell --impure ''${@}
}
'';
2024-04-06 03:03:58 +03:00
}