blob: 8c3be8b23208db2d7b86492892cca09d6f46eb8d [file] [log] [blame]
Skyler Grey1e2187f2023-03-03 22:45:10 +00001{
2 description = "A flake to deploy and configure Clicks' NixOS server";
3
Skyler Grey07c947a2023-06-08 14:11:23 +02004 inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
Skyler Greyb30f5dd2023-09-01 21:02:44 +00005 inputs.nixpkgs-clicksforms.url = "github:nixos/nixpkgs/nixos-22.05";
Skyler Grey061574c2023-05-01 21:39:24 +00006 inputs.flake-utils.url = "github:numtide/flake-utils";
Skyler Grey1e2187f2023-03-03 22:45:10 +00007 inputs.deploy-rs.url = "github:serokell/deploy-rs";
Skyler Grey07c947a2023-06-08 14:11:23 +02008 inputs.home-manager.url = "github:nix-community/home-manager/release-23.05";
Skyler Greya7fbaee2023-05-12 00:29:20 +00009 inputs.sops-nix.url = "github:Mic92/sops-nix";
Skyler Greya78aa672023-05-20 13:48:18 +020010 inputs.scalpel.url = "github:polygon/scalpel";
Skyler Grey1e2187f2023-03-03 22:45:10 +000011
Skyler Greyfed0bb12023-05-01 21:42:03 +000012 inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";
Skyler Greyfed0bb12023-05-01 21:42:03 +000013
Skyler Greya7fbaee2023-05-12 00:29:20 +000014 inputs.sops-nix.inputs.nixpkgs.follows = "nixpkgs";
15
Skyler Greya78aa672023-05-20 13:48:18 +020016 inputs.scalpel.inputs.nixpkgs.follows = "nixpkgs";
17 inputs.scalpel.inputs.sops-nix.follows = "sops-nix";
18
Skyler Grey9fe61282023-08-20 21:52:48 +000019 inputs.nixpkgs-privatebin.url = "github:e1mo/nixpkgs/privatebin";
20
21 outputs =
22 { self
23 , nixpkgs
24 , deploy-rs
25 , home-manager
26 , sops-nix
27 , scalpel
28 , nixpkgs-privatebin
29 , ...
30 }@inputs:
Skyler Grey07584fb2023-05-01 21:37:13 +000031 let
32 system = "x86_64-linux";
33 pkgs = import nixpkgs {
34 inherit system;
35 config.allowUnfree = true;
Skyler Grey9fe61282023-08-20 21:52:48 +000036 overlays = [
37 (final: prev: { inherit (nixpkgs-privatebin.legacyPackages.${system}) privatebin pbcli; })
38 ];
Skyler Grey07584fb2023-05-01 21:37:13 +000039 };
40 in
Skyler Greyb3516c22023-05-24 19:17:11 +020041 rec {
Skyler Grey07584fb2023-05-01 21:37:13 +000042 nixosConfigurations.clicks =
Skyler Greya78aa672023-05-20 13:48:18 +020043 let
44 base = nixpkgs.lib.nixosSystem {
45 inherit system pkgs;
46 modules = [
47 ./default/configuration.nix
48 ./default/hardware-configuration.nix
Skyler Grey703e75a2023-06-08 13:39:50 +020049 ./modules/cache.nix
Skyler Greya78aa672023-05-20 13:48:18 +020050 ./modules/caddy.nix
51 ./modules/clamav.nix
Skyler Grey5e2bc9e2023-08-24 21:58:52 +000052 ./modules/cloudflare-ddns.nix
Skyler Greya78aa672023-05-20 13:48:18 +020053 ./modules/dmarc.nix
54 ./modules/dnsmasq.nix
55 ./modules/doas.nix
56 ./modules/docker.nix
Skyler Grey87a11552023-06-14 23:02:25 +020057 ./modules/drivePaths.nix
Skyler Greya78aa672023-05-20 13:48:18 +020058 ./modules/ecryptfs.nix
59 ./modules/fail2ban.nix
60 ./modules/fuck.nix
Skyler Grey08758a62023-10-09 07:35:09 +000061 ./modules/gerrit.nix
Skyler Greya78aa672023-05-20 13:48:18 +020062 ./modules/git.nix
63 ./modules/grafana.nix
64 ./modules/home-manager-users.nix
Skyler Grey0e05d262023-10-09 07:04:36 +000065 ./modules/keycloak.nix
Skyler Greya78aa672023-05-20 13:48:18 +020066 ./modules/kitty.nix
Skyler Grey480fd8b2023-05-24 19:11:16 +020067 ./modules/loginctl-linger.nix
Skyler Greya78aa672023-05-20 13:48:18 +020068 ./modules/matrix.nix
69 ./modules/mongodb.nix
Skyler Grey09c5cda2023-10-09 07:10:10 +000070 ./modules/nextcloud.nix
Skyler Greya78aa672023-05-20 13:48:18 +020071 ./modules/node.nix
72 ./modules/postgres.nix
Skyler Grey9fe61282023-08-20 21:52:48 +000073 ./modules/privatebin.nix
Skyler Greya78aa672023-05-20 13:48:18 +020074 ./modules/samba.nix
75 ./modules/scalpel.nix
Skyler Grey07c947a2023-06-08 14:11:23 +020076 ./modules/ssh.nix
Skyler Grey5b2c0382023-05-29 11:09:05 +020077 ./modules/static-ip.nix
Skyler Grey87a11552023-06-14 23:02:25 +020078 ./modules/syncthing.nix
Skyler Greya78aa672023-05-20 13:48:18 +020079 ./modules/tesseract.nix
Skyler Grey87a11552023-06-14 23:02:25 +020080 ./modules/vaultwarden.nix
Skyler Greya78aa672023-05-20 13:48:18 +020081 sops-nix.nixosModules.sops
Skyler Grey9fe61282023-08-20 21:52:48 +000082 "${nixpkgs-privatebin}/nixos/modules/services/web-apps/privatebin.nix"
Skyler Greya78aa672023-05-20 13:48:18 +020083 {
84 users.mutableUsers = false;
Skyler Greya78aa672023-05-20 13:48:18 +020085 }
86 ];
Skyler Grey08758a62023-10-09 07:35:09 +000087 specialArgs = { base = null; drive_paths = import ./variables/drive_paths.nix; inherit system; };
Skyler Greya78aa672023-05-20 13:48:18 +020088 };
89 in
90 base.extendModules {
Skyler Grey07584fb2023-05-01 21:37:13 +000091 modules = [
Skyler Greya78aa672023-05-20 13:48:18 +020092 scalpel.nixosModules.scalpel
Skyler Grey07584fb2023-05-01 21:37:13 +000093 ];
Skyler Greya78aa672023-05-20 13:48:18 +020094 specialArgs = { inherit base; };
Skyler Grey4f3e6062023-03-04 01:29:29 +000095 };
Skyler Grey07584fb2023-05-01 21:37:13 +000096
Skyler Greyb3516c22023-05-24 19:17:11 +020097 nixosConfigurations.clicks-without-mongodb =
98 nixosConfigurations.clicks.extendModules {
99 modules = [
100 { services.mongodb.enable = nixpkgs.lib.mkForce false; }
101 ];
102 };
103
Skyler Grey07584fb2023-05-01 21:37:13 +0000104 deploy.nodes.clicks = {
105 sudo = "doas -u";
106 profiles = {
107 system = {
108 remoteBuild = true;
109 user = "root";
110 path = deploy-rs.lib.x86_64-linux.activate.nixos
111 self.nixosConfigurations.clicks;
112 };
113 } // (
114 let
115 mkServiceConfig = service: {
116 remoteBuild = true;
117 user = service;
118
119 profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager";
120 path =
121 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
122 {
123 inherit pkgs;
124 modules = [
125 {
126 home.homeDirectory = "/services/${service}";
127 home.username = service;
128 home.stateVersion = "22.11";
129 programs.home-manager.enable = true;
130 }
131 "${./services}/${service}"
132 ];
Skyler Greyb30f5dd2023-09-01 21:02:44 +0000133 extraSpecialArgs = { inherit (inputs) nixpkgs-clicksforms; inherit system; };
Skyler Grey07584fb2023-05-01 21:37:13 +0000134 });
135 };
136 in
137 nixpkgs.lib.pipe ./services [
138 builtins.readDir
139 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
140 builtins.attrNames
141 (map (name: {
142 inherit name; value = mkServiceConfig name;
143 }))
144 builtins.listToAttrs
145 ]
Skyler Grey5b2c0382023-05-29 11:09:05 +0200146 ) // (
147 let
148 mkBlankConfig = username:
149 {
150 remoteBuild = true;
151 user = username;
152
153 profilePath = "/nix/var/nix/profiles/per-user/${username}/home-manager";
154 path =
155 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
156 {
157 inherit pkgs;
158 modules = [
159 {
160 home.username = username;
161 home.stateVersion = "22.11";
162 programs.home-manager.enable = true;
163 }
164 "${./homes}/${username}"
165 ];
166 });
167 };
168 in
169 nixpkgs.lib.pipe ./homes [
170 builtins.readDir
171 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
172 builtins.attrNames
173 (map (name: {
174 inherit name; value = mkBlankConfig name;
175 }))
176 builtins.listToAttrs
177 ]
Skyler Grey07584fb2023-05-01 21:37:13 +0000178 );
179 hostname = "clicks";
180 profilesOrder = [ "system" ];
Skyler Grey1e2187f2023-03-03 22:45:10 +0000181 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000182
Skyler Greyb30f5dd2023-09-01 21:02:44 +0000183 devShells.x86_64-linux.default = pkgs.mkShell {
184 packages = [ pkgs.deploy-rs ];
185 };
186
Skyler Grey07584fb2023-05-01 21:37:13 +0000187 formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
Skyler Grey1e2187f2023-03-03 22:45:10 +0000188 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000189}