summaryrefslogblamecommitdiff
path: root/nixos/bnc.nix
blob: 46b69428c609c2d632f56afd1b6150ca973dc0cf (plain) (tree)









































                                                                                              
{ config, pkgs, ... }:

let bnc = pkgs.writeScriptBin "bnc" ''
  #!${pkgs.bash}/bin/bash

  FULLMODE=0
  if [ "$1" == "-f" ]; then
      FULLMODE=1
      shift 1
  fi

  source $HOME/.awsrc

  NIXKEY=$(mktemp)

  _cleanup() {
    echo "---- Cleaning up ----"
    rm $NIXKEY
  }
  trap _cleanup EXIT

  ${pkgs.pass}/bin/pass show deuxfleurs/nix_priv_key > $NIXKEY

  for flake in "$@"; do
      echo "---- Updating cache for flake ''${flake} ----"
      if [ "$FULLMODE" = "1" ]; then
          derivation=$(${pkgs.nix}/bin/nix path-info --derivation "''${flake}")
          ${pkgs.nix}/bin/nix copy -j8 \
            --to "s3://nix?endpoint=garage.deuxfleurs.fr&region=garage&secret-key=$NIXKEY" \
            $(${pkgs.nix}/bin/nix-store -qR ''${derivation})
      else
          ${pkgs.nix}/bin/nix copy -j8 \
              --to "s3://nix?endpoint=garage.deuxfleurs.fr&region=garage&secret-key=$NIXKEY" \
              "''${flake}"
      fi
  done

'';
in
{
  environment.systemPackages = [ bnc ];
}