blob: 7d0d732ef2f9c66561b76c7d5e519e378d42e12e [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
64 ./modules/kitty.nix
Skyler Grey480fd8b2023-05-24 19:11:16 +020065 ./modules/loginctl-linger.nix
Skyler Greya78aa672023-05-20 13:48:18 +020066 ./modules/matrix.nix
67 ./modules/mongodb.nix
68 ./modules/node.nix
69 ./modules/postgres.nix
Skyler Grey9fe61282023-08-20 21:52:48 +000070 ./modules/privatebin.nix
Skyler Greya78aa672023-05-20 13:48:18 +020071 ./modules/samba.nix
72 ./modules/scalpel.nix
Skyler Grey07c947a2023-06-08 14:11:23 +020073 ./modules/ssh.nix
Skyler Grey5b2c0382023-05-29 11:09:05 +020074 ./modules/static-ip.nix
Skyler Grey87a11552023-06-14 23:02:25 +020075 ./modules/syncthing.nix
Skyler Greya78aa672023-05-20 13:48:18 +020076 ./modules/tesseract.nix
Skyler Grey87a11552023-06-14 23:02:25 +020077 ./modules/vaultwarden.nix
Skyler Greya78aa672023-05-20 13:48:18 +020078 sops-nix.nixosModules.sops
Skyler Grey9fe61282023-08-20 21:52:48 +000079 "${nixpkgs-privatebin}/nixos/modules/services/web-apps/privatebin.nix"
Skyler Greya78aa672023-05-20 13:48:18 +020080 {
81 users.mutableUsers = false;
Skyler Greya78aa672023-05-20 13:48:18 +020082 }
83 ];
TheCodedProfd23784c2023-06-13 14:28:23 -040084 specialArgs = { base = null; drive_paths = import ./variables/drive_paths.nix; };
Skyler Greya78aa672023-05-20 13:48:18 +020085 };
86 in
87 base.extendModules {
Skyler Grey07584fb2023-05-01 21:37:13 +000088 modules = [
Skyler Greya78aa672023-05-20 13:48:18 +020089 scalpel.nixosModules.scalpel
Skyler Grey07584fb2023-05-01 21:37:13 +000090 ];
Skyler Greya78aa672023-05-20 13:48:18 +020091 specialArgs = { inherit base; };
Skyler Grey4f3e6062023-03-04 01:29:29 +000092 };
Skyler Grey07584fb2023-05-01 21:37:13 +000093
Skyler Greyb3516c22023-05-24 19:17:11 +020094 nixosConfigurations.clicks-without-mongodb =
95 nixosConfigurations.clicks.extendModules {
96 modules = [
97 { services.mongodb.enable = nixpkgs.lib.mkForce false; }
98 ];
99 };
100
Skyler Grey07584fb2023-05-01 21:37:13 +0000101 deploy.nodes.clicks = {
102 sudo = "doas -u";
103 profiles = {
104 system = {
105 remoteBuild = true;
106 user = "root";
107 path = deploy-rs.lib.x86_64-linux.activate.nixos
108 self.nixosConfigurations.clicks;
109 };
110 } // (
111 let
112 mkServiceConfig = service: {
113 remoteBuild = true;
114 user = service;
115
116 profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager";
117 path =
118 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
119 {
120 inherit pkgs;
121 modules = [
122 {
123 home.homeDirectory = "/services/${service}";
124 home.username = service;
125 home.stateVersion = "22.11";
126 programs.home-manager.enable = true;
127 }
128 "${./services}/${service}"
129 ];
Skyler Greyb30f5dd2023-09-01 21:02:44 +0000130 extraSpecialArgs = { inherit (inputs) nixpkgs-clicksforms; inherit system; };
Skyler Grey07584fb2023-05-01 21:37:13 +0000131 });
132 };
133 in
134 nixpkgs.lib.pipe ./services [
135 builtins.readDir
136 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
137 builtins.attrNames
138 (map (name: {
139 inherit name; value = mkServiceConfig name;
140 }))
141 builtins.listToAttrs
142 ]
Skyler Grey5b2c0382023-05-29 11:09:05 +0200143 ) // (
144 let
145 mkBlankConfig = username:
146 {
147 remoteBuild = true;
148 user = username;
149
150 profilePath = "/nix/var/nix/profiles/per-user/${username}/home-manager";
151 path =
152 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
153 {
154 inherit pkgs;
155 modules = [
156 {
157 home.username = username;
158 home.stateVersion = "22.11";
159 programs.home-manager.enable = true;
160 }
161 "${./homes}/${username}"
162 ];
163 });
164 };
165 in
166 nixpkgs.lib.pipe ./homes [
167 builtins.readDir
168 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
169 builtins.attrNames
170 (map (name: {
171 inherit name; value = mkBlankConfig name;
172 }))
173 builtins.listToAttrs
174 ]
Skyler Grey07584fb2023-05-01 21:37:13 +0000175 );
176 hostname = "clicks";
177 profilesOrder = [ "system" ];
Skyler Grey1e2187f2023-03-03 22:45:10 +0000178 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000179
Skyler Greyb30f5dd2023-09-01 21:02:44 +0000180 devShells.x86_64-linux.default = pkgs.mkShell {
181 packages = [ pkgs.deploy-rs ];
182 };
183
Skyler Grey07584fb2023-05-01 21:37:13 +0000184 formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
Skyler Grey1e2187f2023-03-03 22:45:10 +0000185 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000186}