blob: 766462cc9f52cfb9b4107ad7e70930afc554d7f4 [file] [log] [blame]
Skyler Greyf08a6192024-06-01 23:55:20 +00001# SPDX-FileCopyrightText: 2024 Auxolotl Infrastructure Contributors
2# SPDX-FileCopyrightText: 2024 Clicks Codes
3#
4# SPDX-License-Identifier: GPL-3.0-only
5
6{
7 options,
8 config,
9 pkgs,
10 lib,
11 inputs,
12 ...
13}:
14let
15 cfg = config.clicks.nix;
16
17 substituters-submodule = lib.types.submodule (
18 { name, ... }:
19 {
20 options = {
21 key = lib.mkOption {
22 type = lib.types.nullOr lib.types.str;
23 default = null;
24 description = "The trusted public key for this substituter.";
25 };
26 };
27 }
28 );
29in
30{
31 options.clicks.nix = {
32 enable = lib.mkEnableOption "Nix configuration";
Skyler Greyf08a6192024-06-01 23:55:20 +000033
34 default-substituter = {
35 url = lib.mkOption {
36 type = lib.types.str;
37 default = "https://cache.nixos.org";
38 description = "The url for the substituter.";
39 };
40 key = lib.mkOption {
41 type = lib.types.str;
42 default = "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=";
43 description = "The trusted public key for the substituter.";
44 };
45 };
46
47 extra-substituters = lib.mkOption {
48 type = lib.types.attrsOf substituters-submodule;
49 default = { };
50 description = "Extra substituters to configure.";
51 };
52 };
53
54 config = lib.mkIf cfg.enable {
55 assertions = lib.mapAttrsToList (name: value: {
56 assertion = value.key != null;
57 message = "auxolotl.nix.extra-substituters.${name}.key must be set";
58 }) cfg.extra-substituters;
59
60 nix =
61 let
62 users = [ "root" ];
63 in
Skyler Greyec13fbd2024-08-03 08:11:04 +000064 ({
Skyler Greyf08a6192024-06-01 23:55:20 +000065 settings = {
66 experimental-features = "nix-command flakes";
67 http-connections = 50;
68 log-lines = 50;
69 auto-optimise-store = true;
70
71 trusted-users = users;
72 allowed-users = users;
73
74 substituters = [
75 cfg.default-substituter.url
76 ] ++ (lib.mapAttrsToList (name: value: name) cfg.extra-substituters);
77
78 trusted-public-keys = [
79 cfg.default-substituter.key
80 ] ++ (lib.mapAttrsToList (name: value: value.key) cfg.extra-substituters);
81 };
82
83 gc = {
84 automatic = true;
85 dates = "weekly";
86 options = "--delete-older-than 30d";
87 };
88
89 # flake-utils-plus
Skyler Greyec13fbd2024-08-03 08:11:04 +000090 } // (lib.optionalAttrs cfg.enable {
Skyler Greyf08a6192024-06-01 23:55:20 +000091 generateRegistryFromInputs = true;
92 generateNixPathFromInputs = true;
93 linkInputs = true;
Skyler Greyec13fbd2024-08-03 08:11:04 +000094 }));
Skyler Greyf08a6192024-06-01 23:55:20 +000095 };
96}