Last active
December 14, 2019 22:02
Simple wrapper to add packages declaratively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env nix-shell | |
#!nix-shell -p jq -i bash | |
# Usage: | |
# | |
# nix-install vim | |
set -e | |
registry=~/.config/nix/my_packages.json | |
profile=~/.config/nix/my_profile.nix | |
pkg="$1" | |
filter=".packages = (.packages + [\"$pkg\"] | unique)" | |
if [[ ! $(jq '.packages' "$registry") ]]; then | |
echo "initializing registry at $registry" | |
echo '{"packages": []}' > "$registry" | |
fi | |
# if [[ ! -f "$profile" ]]; then | |
# | |
echo "initializing profile $profile" | |
cat << NIX > "$profile" | |
{ pkgs ? import <nixpkgs> {}, name ? "simple-nix" }: | |
pkgs.buildEnv { | |
inherit name; | |
extraOutputsToInstall = ["out" "bin" "lib"]; | |
paths = map (name: | |
let path = pkgs.lib.splitString "." name; | |
in pkgs.lib.getAttrFromPath path pkgs | |
) ( | |
builtins.fromJSON ( | |
builtins.readFile ${registry} | |
) | |
).packages; | |
} | |
NIX | |
# fi | |
echo "adding $pkg to $registry" | |
updated="$(jq "$filter" "$registry")" | |
echo "$updated" > "$registry" | |
nix-env --set -f "$profile" --argstr name "$(whoami)-user-env-$(date -I)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment