Skyler Grey | f08a619 | 2024-06-01 23:55:20 +0000 | [diff] [blame] | 1 | # 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 | }: |
| 14 | let |
| 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 | ); |
| 29 | in |
| 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 |
Skyler Grey | ec13fbd | 2024-08-03 08:11:04 +0000 | [diff] [blame^] | 70 | ({ |
Skyler Grey | f08a619 | 2024-06-01 23:55:20 +0000 | [diff] [blame] | 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 |
Skyler Grey | ec13fbd | 2024-08-03 08:11:04 +0000 | [diff] [blame^] | 98 | } // (lib.optionalAttrs cfg.enable { |
Skyler Grey | f08a619 | 2024-06-01 23:55:20 +0000 | [diff] [blame] | 99 | generateRegistryFromInputs = true; |
| 100 | generateNixPathFromInputs = true; |
| 101 | linkInputs = true; |
Skyler Grey | ec13fbd | 2024-08-03 08:11:04 +0000 | [diff] [blame^] | 102 | })); |
Skyler Grey | f08a619 | 2024-06-01 23:55:20 +0000 | [diff] [blame] | 103 | }; |
| 104 | } |