diff options
author | Alex Auvolat <alex@adnab.me> | 2023-01-30 11:55:10 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-01-30 11:55:10 +0100 |
commit | fac325ee02142e4aa055dc25a42978a7d542a407 (patch) | |
tree | e666c065401c3f28b3468921c79c60685e1311c9 /nixos/bnc.nix | |
parent | e9a8c33b4d01c01b77fd32a9b2f605343aa2d65e (diff) | |
download | user-config-fac325ee02142e4aa055dc25a42978a7d542a407.tar.gz user-config-fac325ee02142e4aa055dc25a42978a7d542a407.zip |
add nix-index and bnc script
Diffstat (limited to 'nixos/bnc.nix')
-rw-r--r-- | nixos/bnc.nix | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/nixos/bnc.nix b/nixos/bnc.nix new file mode 100644 index 0000000..46b6942 --- /dev/null +++ b/nixos/bnc.nix @@ -0,0 +1,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®ion=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®ion=garage&secret-key=$NIXKEY" \ + "''${flake}" + fi + done + +''; +in +{ + environment.systemPackages = [ bnc ]; +} |