blob: ed9c9af7208b4809c159466296feefc68ddf04c3 [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{
Skyler Grey02c195e2024-06-22 01:35:26 +00007 description = "Clicks Infrastructure";
Skyler Greyf08a6192024-06-01 23:55:20 +00008
9 inputs = {
Skyler Grey67cf8aa2024-07-28 13:21:32 +000010 agenix.url = "github:ryantm/agenix";
11
12 agenix-rekey = {
13 url = "github:oddlama/agenix-rekey";
14 inputs.nixpkgs.follows = "nixpkgs";
15 };
16
Skyler Greyf08a6192024-06-01 23:55:20 +000017 deploy-rs = {
18 url = "github:serokell/deploy-rs";
19 inputs.nixpkgs.follows = "nixpkgs";
20 };
Skyler Greyd3377402024-06-06 22:01:26 +000021
Skyler Greyd7e1acd2024-06-22 14:42:11 +000022 home-manager = {
23 url = "github:nix-community/home-manager";
24 inputs.nixpkgs.follows = "nixpkgs";
25 };
26
27 flake-utils.url = "github:numtide/flake-utils";
28
29 impermanence.url = "github:nix-community/impermanence";
30
31 nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
32
Skyler Greye6a8c712024-06-22 01:41:28 +000033 snowfall-lib = {
34 url = "github:snowfallorg/lib";
35 inputs.nixpkgs.follows = "nixpkgs";
36 };
37
Skyler Greyd7e1acd2024-06-22 14:42:11 +000038 unstable.url = "github:nixos/nixpkgs/nixos-unstable";
Skyler Grey3299e4f2024-07-04 00:33:43 +000039
40 aux--docs-site = {
41 url = "git+https://git.auxolotl.org/auxolotl/docs-site";
42 inputs.nixpkgs.follows = "nixpkgs";
43 inputs.snowfall-lib.follows = "snowfall-lib";
44 inputs.wiki.follows = "aux--wiki";
45 };
46 aux--wiki = {
47 url = "git+https://git.auxolotl.org/auxolotl/wiki";
48 flake = false;
49 };
Skyler Greyf08a6192024-06-01 23:55:20 +000050 };
51
52 outputs =
53 inputs:
54 let
Skyler Greye6a8c712024-06-22 01:41:28 +000055 lib = (inputs.snowfall-lib.mkLib {
Skyler Greyf08a6192024-06-01 23:55:20 +000056 inherit inputs;
57
58 src = ./.;
59
60 snowfall = {
61 namespace = "clicks";
62 };
Skyler Greye6a8c712024-06-22 01:41:28 +000063 }).snowfall.internal.system-lib;
Skyler Grey38d4a3e2024-08-02 19:47:04 +000064
65 nixosModuleDependencies = {
66 agenix = inputs.agenix.nixosModules.default;
67 agenix-rekey = inputs.agenix-rekey.nixosModules.default;
68 impermanence = inputs.impermanence.nixosModules.impermanence;
69 };
Skyler Greyf08a6192024-06-01 23:55:20 +000070 in
71 lib.mkFlake {
Skyler Grey67cf8aa2024-07-28 13:21:32 +000072 overlays = [
73 inputs.agenix-rekey.overlays.default
74 ];
Skyler Greyf08a6192024-06-01 23:55:20 +000075
Skyler Grey82ea8052024-06-08 22:56:00 +000076 systems.modules.nixos = [
Skyler Grey4bf2de52024-07-29 17:55:05 +000077 {
78 config.clicks.defaults.enable = true;
79 # set defaults that are clicks-specific, such as our backups module
80 # being enabled...
81 }
Skyler Grey38d4a3e2024-08-02 19:47:04 +000082 ] ++ (lib.attrsets.attrValues nixosModuleDependencies);
Skyler Greyd3377402024-06-06 22:01:26 +000083
Skyler Greye6a8c712024-06-22 01:41:28 +000084 deploy = lib.clicks.deploy.mkDeploy {
Skyler Greyf08a6192024-06-01 23:55:20 +000085 inherit (inputs) self;
86 overrides = {
Skyler Grey8ef34812024-06-09 19:42:15 +000087 teal.hostname = "teal.alpha.clicks.domains";
Skyler Greyf08a6192024-06-01 23:55:20 +000088 };
89 };
90
Skyler Grey67cf8aa2024-07-28 13:21:32 +000091 agenix-rekey = inputs.agenix-rekey.configure {
92 userFlake = inputs.self // { outPath = lib.pipe "" [
93 lib.snowfall.fs.get-snowfall-file
94 (lib.strings.removeSuffix "/")
95 ]; };
96 nodes = inputs.self.nixosConfigurations;
97 };
98
Skyler Grey38d4a3e2024-08-02 19:47:04 +000099 # We need to re-export dependencies, as this is *invalid* unless
100 # environment.persistence is defined, so importing all our modules will
101 # otherwise break evaluation
102 #
103 # config = lib.mkIf false {
104 # environment.persistence = {
105 # ...
106 # };
107 # };
108 #
109 modules.nixos = lib.attrsets.mapAttrs' (name: value: {
110 name = "dependency/${name}";
111 inherit value;
112 }) nixosModuleDependencies;
113
Skyler Greye6a8c712024-06-22 01:41:28 +0000114 outputs-builder = channels: {
115 specs = let
116 nixFiles = lib.snowfall.fs.get-nix-files-recursive ./.;
117 specFiles = builtins.filter (lib.clicks.strings.endsWith ".spec.nix") nixFiles;
118 importedSpecs = lib.forEach specFiles (file: {
119 name = builtins.unsafeDiscardStringContext (builtins.baseNameOf file);
120 value = import file {
121 inherit channels lib;
122 };
123 });
124 in builtins.listToAttrs importedSpecs;
Skyler Greyf08a6192024-06-01 23:55:20 +0000125
Skyler Greye6a8c712024-06-22 01:41:28 +0000126 formatter = channels.nixpkgs.nixfmt-rfc-style;
127
128 checks = let
129 allChecks = {
130 deploy-rs = lib.deploy-rs.${channels.nixpkgs.system}.deployChecks inputs.self.deploy;
131 clicks = lib.clicks.checks channels.nixpkgs;
132 };
133
134 mergedChecks = lib.trivial.pipe allChecks [
135 (lib.attrsets.mapAttrsToList (sourceName: (lib.attrsets.mapAttrsToList (checkName: value: {
136 name = "${sourceName}:${checkName}";
137 inherit value;
138 }))))
139 lib.lists.flatten
140 builtins.listToAttrs
141 ];
142 in mergedChecks;
143 };
Skyler Greyf08a6192024-06-01 23:55:20 +0000144 };
145}