PortValhalla/scripts/lib/nix.fish

41 lines
1.2 KiB
Fish
Raw Normal View History

2024-11-01 13:13:41 +00:00
begin
set -l dir (status dirname)
set -l config "$dir/config.fish"
2024-11-29 00:13:58 +00:00
set nixPkgsDir /nix/var/nix/profiles/per-user/root/channels/nixpkgs
2024-11-01 13:13:41 +00:00
2024-11-25 14:19:13 +00:00
function __isNixModule -a path
nix-instantiate --eval --expr "{ path }: import path" --argstr path "$path" &>/dev/null
end
2024-11-01 13:13:41 +00:00
function downloadNixPkgs -V config
source "$config"
2024-11-25 14:19:13 +00:00
if ! __isNixModule "$nixPkgsCache"
2024-12-05 17:19:18 +00:00
rm -rf "$nixPkgsCache"
and mkdir -p "$nixPkgsCache"
and git -C "$nixPkgsCache" init
and git -C "$nixPkgsCache" remote add origin https://github.com/NixOS/nixpkgs.git
and git -C "$nixPkgsCache" fetch --depth=1 origin "$nixPkgsVersion"
and git -C "$nixPkgsCache" reset --hard FETCH_HEAD
2024-11-01 13:13:41 +00:00
end
end
function installNixPkgs -V config -V nixPkgsDir
source "$config"
2024-11-02 23:39:23 +00:00
2024-11-25 14:19:13 +00:00
if ! __isNixModule "$nixPkgsDir"
if ! __isNixModule "$nixPkgsCache"
2024-11-03 21:37:33 +00:00
downloadNixPkgs
end
2024-12-05 18:40:41 +00:00
sudo rm -rf "$nixPkgsDir"
sudo mkdir -p (dirname "$nixPkgsDir")
2024-12-05 18:40:41 +00:00
sudo cp -r "$nixPkgsCache" "$nixPkgsDir"
2024-11-02 23:39:23 +00:00
end
2024-11-01 13:13:41 +00:00
end
function uninstallNixPkgs -V nixPkgsDir
2024-11-03 21:37:22 +00:00
sudo rm -rf (dirname "$nixPkgsDir")
2024-11-01 13:13:41 +00:00
end
end