blob: 742980d7a267ff3c9cdb79e9603391e87559ae9e [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";
33 package = lib.mkOption {
34 type = lib.types.package;
35 default = pkgs.nix;
36 defaultText = "pkgs.nix";
37 description = "Which Nix package to use.";
38 };
39
40 default-substituter = {
41 url = lib.mkOption {
42 type = lib.types.str;
43 default = "https://cache.nixos.org";
44 description = "The url for the substituter.";
45 };
46 key = lib.mkOption {
47 type = lib.types.str;
48 default = "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=";
49 description = "The trusted public key for the substituter.";
50 };
51 };
52
53 extra-substituters = lib.mkOption {
54 type = lib.types.attrsOf substituters-submodule;
55 default = { };
56 description = "Extra substituters to configure.";
57 };
58 };
59
60 config = lib.mkIf cfg.enable {
61 assertions = lib.mapAttrsToList (name: value: {
62 assertion = value.key != null;
63 message = "auxolotl.nix.extra-substituters.${name}.key must be set";
64 }) cfg.extra-substituters;
65
66 nix =
67 let
68 users = [ "root" ];
69 in
70 {
71 package = cfg.package;
72
73 settings = {
74 experimental-features = "nix-command flakes";
75 http-connections = 50;
76 log-lines = 50;
77 auto-optimise-store = true;
78
79 trusted-users = users;
80 allowed-users = users;
81
82 substituters = [
83 cfg.default-substituter.url
84 ] ++ (lib.mapAttrsToList (name: value: name) cfg.extra-substituters);
85
86 trusted-public-keys = [
87 cfg.default-substituter.key
88 ] ++ (lib.mapAttrsToList (name: value: value.key) cfg.extra-substituters);
89 };
90
91 gc = {
92 automatic = true;
93 dates = "weekly";
94 options = "--delete-older-than 30d";
95 };
96
97 # flake-utils-plus
98 generateRegistryFromInputs = true;
99 generateNixPathFromInputs = true;
100 linkInputs = true;
101 };
102 };
103}