{ config, lib, pkgs, ... }:

let cfg = config.sydnix.nixpkgs;
in {
  options.sydnix.nixpkgs = {
    enable = lib.mkEnableOption "some default Nixpkgs settings" // {
      default = true;
    };
  };

  config = lib.mkIf cfg.enable {
    nixpkgs.config.allowUnfree = true;

    nix = {
      settings = {
        allow-import-from-derivation = true;
        trusted-users = [
          "@wheel"
        ];
        substituters = [
          "https://cache.deertopia.net"
          "https://nix-community.cachix.org"
          "https://cache.nixos.org"
          "https://cache.iog.io"
        ];
        trusted-public-keys = [
          (builtins.readFile ../../public-keys/deertopia-cache.pub.pem)
          "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
          "hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
        ];
      };
    };
  };
}
