Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colemickens/b56368072132e446331918352ecc8bdf to your computer and use it in GitHub Desktop.
Save colemickens/b56368072132e446331918352ecc8bdf to your computer and use it in GitHub Desktop.
# sadly, this is considerably faster than
# using nix and its usual remote building functionality
function remote() {
cache="colemickens"
cachixkey="$(set -e; gopass show "websites/cachix.org/apikey/${cache}")"
machine="${1}"; shift
remote="${1}"; shift
#drv="$(nix eval --pure-eval ".#nixosConfigurations.${machine}.config.system.build.toplevel")" # TODO: why????
drv="$(set -e; nix --experimental-features 'nix-command flakes' --pure-eval \
eval \
--override-input cmpkgs "/home/cole/code/nixpkgs/cmpkgs" --override-input pipkgs "/home/cole/code/nixpkgs/pipkgs" --override-input home "/home/cole/code/home-manager/cmhm" \
--raw ".#machines.${machine}")"
drv="$(set -e; nix --experimental-features 'nix-command flakes' --pure-eval \
show-derivation "${drv}" | jq -r 'to_entries[].key')"
out="$(set -e; nix --experimental-features 'nix-command flakes' --pure-eval \
show-derivation "${drv}" | jq -r 'to_entries[].value.outputs.out.path')" # TODO: must be a better way # (in v1, there's nix-store query that works)
## COPY->COMPRESS->RSYNC DRV TO BUILDER
t="/tmp/tmpnixpath"; #rm -rf "${t}"; trap "rm -rf $t" EXIT;
nix-shell -I nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz -p nix --command "nix copy --to file://${t} ${drv}" # see: https://github.com/NixOS/nix/issues/3696
rsync -ah "${t}/" "${remote}:${t}"
ssh "${remote}" \
"nix-shell -I nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz -p nix --command \
\"nix copy --from file://${t} ${drv}\""
## (ON BUILDER): BUILD
ssh "${remote}" \
"nix-shell -I nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz -p nixFlakes --command \
\"nix --experimental-features 'nix-command flakes' --pure-eval \
--option 'extra-binary-caches' 'https://cache.nixos.org' \
--option 'trusted-public-keys' 'cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=' \
--option 'build-cores' '0' \
--option 'narinfo-cache-negative-ttl' '0' \
build --keep-going ${drv}\""
if [[ "${1:-""}" == "push" ]]; then
shift
## (ON BUILDER): PUSH TO CACHE
ssh "${remote}" \
"nix-shell -I nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-20.03.tar.gz -p cachix --command \
\"echo ${out} | env CACHIX_SIGNING_KEY=${cachixkey} cachix push ${cache}\" >/dev/stderr"
fi
echo -e "${out}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment