Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
2.9 kB · 107 lines
Nix
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108{ ... }:let cacheServerName = "homelab"; cacheName = "main"; cacheUrl = "https://attic.internetfeno.men"; cachePublicKey = "9AeGSCEdFACRMznpA8b1LZtZ6cLkpdeTQ0Hqa0RmQAA="; # pragma: allowlist secret
sharedModule = { config, pkgs, ... }: { environment.systemPackages = with pkgs; [ attic-client ]; nix.settings = { substituters = [ "${cacheUrl}/${cacheName}" ];
trusted-public-keys = [ "${cacheName}:${cachePublicKey}" ];
netrc-file = config.sops.templates."nix-netrc".path; };
sops.secrets."attic/client_token" = { };
sops.templates."nix-netrc" = { content = '' machine attic.internetfeno.men password ${config.sops.placeholder."attic/client_token"} ''; }; };
in{ flake.modules.nixos.attic-client = { config, pkgs, ... }: { imports = [ sharedModule ];
systemd.services.attic-watch-store = let watchStoreScript = let atticBin = "${pkgs.attic-client}/bin/attic"; in pkgs.writeShellScript "attic-watch-store" '' ${atticBin} login --set-default ${cacheServerName} ${cacheUrl} $(cat ${ config.sops.secrets."attic/client_token".path }) || true ${atticBin} cache create ${cacheName} || true ${atticBin} cache info ${cacheName} ${atticBin} watch-store ${cacheName} ''; in { description = "Watch the Nix store and push new paths to Attic"; after = [ "network-online.target" ]; wants = [ "network-online.target" ]; wantedBy = [ "multi-user.target" ];
serviceConfig = { Type = "simple"; User = "root"; Restart = "always"; RestartSec = "5s"; ExecStart = watchStoreScript; }; }; }; flake.modules.darwin.attic-client = { config, pkgs, ... }: { imports = [ sharedModule ];
launchd.daemons.attic-watch-store = { script = let atticBin = "${pkgs.attic-client}/bin/attic"; in '' ${atticBin} login --set-default ${cacheServerName} ${cacheUrl} $(cat ${ config.sops.secrets."attic/client_token".path }) ${atticBin} cache create ${cacheName} || true ${atticBin} cache info ${cacheName} ${atticBin} watch-store ${cacheName} ''; serviceConfig = { KeepAlive = true; RunAtLoad = true; StandardOutPath = "/var/log/attic-watch-store.log"; StandardErrorPath = "/var/log/attic-watch-store.log"; }; }; };}