blob: 838808d69d25e127b24fbd80b5e866bbcb5acdc7 [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
61 ./modules/git.nix
62 ./modules/grafana.nix
63 ./modules/home-manager-users.nix
Skyler Grey0e05d262023-10-09 07:04:36 +000064 ./modules/keycloak.nix
Skyler Greya78aa672023-05-20 13:48:18 +020065 ./modules/kitty.nix
Skyler Grey480fd8b2023-05-24 19:11:16 +020066 ./modules/loginctl-linger.nix
Skyler Greya78aa672023-05-20 13:48:18 +020067 ./modules/matrix.nix
68 ./modules/mongodb.nix
69 ./modules/node.nix
70 ./modules/postgres.nix
Skyler Grey9fe61282023-08-20 21:52:48 +000071 ./modules/privatebin.nix
Skyler Greya78aa672023-05-20 13:48:18 +020072 ./modules/samba.nix
73 ./modules/scalpel.nix
Skyler Grey07c947a2023-06-08 14:11:23 +020074 ./modules/ssh.nix
Skyler Grey5b2c0382023-05-29 11:09:05 +020075 ./modules/static-ip.nix
Skyler Grey87a11552023-06-14 23:02:25 +020076 ./modules/syncthing.nix
Skyler Greya78aa672023-05-20 13:48:18 +020077 ./modules/tesseract.nix
Skyler Grey87a11552023-06-14 23:02:25 +020078 ./modules/vaultwarden.nix
Skyler Greya78aa672023-05-20 13:48:18 +020079 sops-nix.nixosModules.sops
Skyler Grey9fe61282023-08-20 21:52:48 +000080 "${nixpkgs-privatebin}/nixos/modules/services/web-apps/privatebin.nix"
Skyler Greya78aa672023-05-20 13:48:18 +020081 {
82 users.mutableUsers = false;
Skyler Greya78aa672023-05-20 13:48:18 +020083 }
84 ];
TheCodedProfd23784c2023-06-13 14:28:23 -040085 specialArgs = { base = null; drive_paths = import ./variables/drive_paths.nix; };
Skyler Greya78aa672023-05-20 13:48:18 +020086 };
87 in
88 base.extendModules {
Skyler Grey07584fb2023-05-01 21:37:13 +000089 modules = [
Skyler Greya78aa672023-05-20 13:48:18 +020090 scalpel.nixosModules.scalpel
Skyler Grey07584fb2023-05-01 21:37:13 +000091 ];
Skyler Greya78aa672023-05-20 13:48:18 +020092 specialArgs = { inherit base; };
Skyler Grey4f3e6062023-03-04 01:29:29 +000093 };
Skyler Grey07584fb2023-05-01 21:37:13 +000094
Skyler Greyb3516c22023-05-24 19:17:11 +020095 nixosConfigurations.clicks-without-mongodb =
96 nixosConfigurations.clicks.extendModules {
97 modules = [
98 { services.mongodb.enable = nixpkgs.lib.mkForce false; }
99 ];
100 };
101
Skyler Grey07584fb2023-05-01 21:37:13 +0000102 deploy.nodes.clicks = {
103 sudo = "doas -u";
104 profiles = {
105 system = {
106 remoteBuild = true;
107 user = "root";
108 path = deploy-rs.lib.x86_64-linux.activate.nixos
109 self.nixosConfigurations.clicks;
110 };
111 } // (
112 let
113 mkServiceConfig = service: {
114 remoteBuild = true;
115 user = service;
116
117 profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager";
118 path =
119 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
120 {
121 inherit pkgs;
122 modules = [
123 {
124 home.homeDirectory = "/services/${service}";
125 home.username = service;
126 home.stateVersion = "22.11";
127 programs.home-manager.enable = true;
128 }
129 "${./services}/${service}"
130 ];
Skyler Greyb30f5dd2023-09-01 21:02:44 +0000131 extraSpecialArgs = { inherit (inputs) nixpkgs-clicksforms; inherit system; };
Skyler Grey07584fb2023-05-01 21:37:13 +0000132 });
133 };
134 in
135 nixpkgs.lib.pipe ./services [
136 builtins.readDir
137 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
138 builtins.attrNames
139 (map (name: {
140 inherit name; value = mkServiceConfig name;
141 }))
142 builtins.listToAttrs
143 ]
Skyler Grey5b2c0382023-05-29 11:09:05 +0200144 ) // (
145 let
146 mkBlankConfig = username:
147 {
148 remoteBuild = true;
149 user = username;
150
151 profilePath = "/nix/var/nix/profiles/per-user/${username}/home-manager";
152 path =
153 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
154 {
155 inherit pkgs;
156 modules = [
157 {
158 home.username = username;
159 home.stateVersion = "22.11";
160 programs.home-manager.enable = true;
161 }
162 "${./homes}/${username}"
163 ];
164 });
165 };
166 in
167 nixpkgs.lib.pipe ./homes [
168 builtins.readDir
169 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
170 builtins.attrNames
171 (map (name: {
172 inherit name; value = mkBlankConfig name;
173 }))
174 builtins.listToAttrs
175 ]
Skyler Grey07584fb2023-05-01 21:37:13 +0000176 );
177 hostname = "clicks";
178 profilesOrder = [ "system" ];
Skyler Grey1e2187f2023-03-03 22:45:10 +0000179 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000180
Skyler Greyb30f5dd2023-09-01 21:02:44 +0000181 devShells.x86_64-linux.default = pkgs.mkShell {
182 packages = [ pkgs.deploy-rs ];
183 };
184
Skyler Grey07584fb2023-05-01 21:37:13 +0000185 formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
Skyler Grey1e2187f2023-03-03 22:45:10 +0000186 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000187}