summaryrefslogtreecommitdiff
path: root/nixos/bnc.nix
blob: 46b69428c609c2d632f56afd1b6150ca973dc0cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{ 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 ];
}