blob: e6b6c6fe3f93c7dfa8ba256ef202a00a49f11382 [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 Grey061574c2023-05-01 21:39:24 +00005 inputs.flake-utils.url = "github:numtide/flake-utils";
Skyler Grey1e2187f2023-03-03 22:45:10 +00006 inputs.deploy-rs.url = "github:serokell/deploy-rs";
Skyler Grey07c947a2023-06-08 14:11:23 +02007 inputs.home-manager.url = "github:nix-community/home-manager/release-23.05";
Skyler Greya7fbaee2023-05-12 00:29:20 +00008 inputs.sops-nix.url = "github:Mic92/sops-nix";
Skyler Greya78aa672023-05-20 13:48:18 +02009 inputs.scalpel.url = "github:polygon/scalpel";
Skyler Grey1e2187f2023-03-03 22:45:10 +000010
Skyler Greyfed0bb12023-05-01 21:42:03 +000011 inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";
Skyler Greyfed0bb12023-05-01 21:42:03 +000012
Skyler Greya7fbaee2023-05-12 00:29:20 +000013 inputs.sops-nix.inputs.nixpkgs.follows = "nixpkgs";
14
Skyler Greya78aa672023-05-20 13:48:18 +020015 inputs.scalpel.inputs.nixpkgs.follows = "nixpkgs";
16 inputs.scalpel.inputs.sops-nix.follows = "sops-nix";
17
Skyler Grey9fe61282023-08-20 21:52:48 +000018 inputs.nixpkgs-privatebin.url = "github:e1mo/nixpkgs/privatebin";
19
20 outputs =
21 { self
22 , nixpkgs
23 , deploy-rs
24 , home-manager
25 , sops-nix
26 , scalpel
27 , nixpkgs-privatebin
28 , ...
29 }@inputs:
Skyler Grey07584fb2023-05-01 21:37:13 +000030 let
31 system = "x86_64-linux";
32 pkgs = import nixpkgs {
33 inherit system;
34 config.allowUnfree = true;
Skyler Grey9fe61282023-08-20 21:52:48 +000035 overlays = [
36 (final: prev: { inherit (nixpkgs-privatebin.legacyPackages.${system}) privatebin pbcli; })
37 ];
Skyler Grey07584fb2023-05-01 21:37:13 +000038 };
39 in
Skyler Greyb3516c22023-05-24 19:17:11 +020040 rec {
Skyler Grey07584fb2023-05-01 21:37:13 +000041 nixosConfigurations.clicks =
Skyler Greya78aa672023-05-20 13:48:18 +020042 let
43 base = nixpkgs.lib.nixosSystem {
44 inherit system pkgs;
45 modules = [
46 ./default/configuration.nix
47 ./default/hardware-configuration.nix
Skyler Grey703e75a2023-06-08 13:39:50 +020048 ./modules/cache.nix
Skyler Greya78aa672023-05-20 13:48:18 +020049 ./modules/caddy.nix
50 ./modules/clamav.nix
Skyler Grey5e2bc9e2023-08-24 21:58:52 +000051 ./modules/cloudflare-ddns.nix
Skyler Greya78aa672023-05-20 13:48:18 +020052 ./modules/dmarc.nix
53 ./modules/dnsmasq.nix
54 ./modules/doas.nix
55 ./modules/docker.nix
Skyler Grey87a11552023-06-14 23:02:25 +020056 ./modules/drivePaths.nix
Skyler Greya78aa672023-05-20 13:48:18 +020057 ./modules/ecryptfs.nix
58 ./modules/fail2ban.nix
59 ./modules/fuck.nix
60 ./modules/git.nix
61 ./modules/grafana.nix
62 ./modules/home-manager-users.nix
63 ./modules/kitty.nix
Skyler Grey480fd8b2023-05-24 19:11:16 +020064 ./modules/loginctl-linger.nix
Skyler Greya78aa672023-05-20 13:48:18 +020065 ./modules/matrix.nix
66 ./modules/mongodb.nix
67 ./modules/node.nix
68 ./modules/postgres.nix
Skyler Grey9fe61282023-08-20 21:52:48 +000069 ./modules/privatebin.nix
Skyler Greya78aa672023-05-20 13:48:18 +020070 ./modules/samba.nix
71 ./modules/scalpel.nix
Skyler Grey07c947a2023-06-08 14:11:23 +020072 ./modules/ssh.nix
Skyler Grey5b2c0382023-05-29 11:09:05 +020073 ./modules/static-ip.nix
Skyler Grey87a11552023-06-14 23:02:25 +020074 ./modules/syncthing.nix
Skyler Greya78aa672023-05-20 13:48:18 +020075 ./modules/tesseract.nix
Skyler Grey87a11552023-06-14 23:02:25 +020076 ./modules/vaultwarden.nix
Skyler Greya78aa672023-05-20 13:48:18 +020077 sops-nix.nixosModules.sops
Skyler Grey9fe61282023-08-20 21:52:48 +000078 "${nixpkgs-privatebin}/nixos/modules/services/web-apps/privatebin.nix"
Skyler Greya78aa672023-05-20 13:48:18 +020079 {
80 users.mutableUsers = false;
Skyler Greya78aa672023-05-20 13:48:18 +020081 }
82 ];
TheCodedProfd23784c2023-06-13 14:28:23 -040083 specialArgs = { base = null; drive_paths = import ./variables/drive_paths.nix; };
Skyler Greya78aa672023-05-20 13:48:18 +020084 };
85 in
86 base.extendModules {
Skyler Grey07584fb2023-05-01 21:37:13 +000087 modules = [
Skyler Greya78aa672023-05-20 13:48:18 +020088 scalpel.nixosModules.scalpel
Skyler Grey07584fb2023-05-01 21:37:13 +000089 ];
Skyler Greya78aa672023-05-20 13:48:18 +020090 specialArgs = { inherit base; };
Skyler Grey4f3e6062023-03-04 01:29:29 +000091 };
Skyler Grey07584fb2023-05-01 21:37:13 +000092
Skyler Greyb3516c22023-05-24 19:17:11 +020093 nixosConfigurations.clicks-without-mongodb =
94 nixosConfigurations.clicks.extendModules {
95 modules = [
96 { services.mongodb.enable = nixpkgs.lib.mkForce false; }
97 ];
98 };
99
Skyler Grey07584fb2023-05-01 21:37:13 +0000100 deploy.nodes.clicks = {
101 sudo = "doas -u";
102 profiles = {
103 system = {
104 remoteBuild = true;
105 user = "root";
106 path = deploy-rs.lib.x86_64-linux.activate.nixos
107 self.nixosConfigurations.clicks;
108 };
109 } // (
110 let
111 mkServiceConfig = service: {
112 remoteBuild = true;
113 user = service;
114
115 profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager";
116 path =
117 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
118 {
119 inherit pkgs;
120 modules = [
121 {
122 home.homeDirectory = "/services/${service}";
123 home.username = service;
124 home.stateVersion = "22.11";
125 programs.home-manager.enable = true;
126 }
127 "${./services}/${service}"
128 ];
129 });
130 };
131 in
132 nixpkgs.lib.pipe ./services [
133 builtins.readDir
134 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
135 builtins.attrNames
136 (map (name: {
137 inherit name; value = mkServiceConfig name;
138 }))
139 builtins.listToAttrs
140 ]
Skyler Grey5b2c0382023-05-29 11:09:05 +0200141 ) // (
142 let
143 mkBlankConfig = username:
144 {
145 remoteBuild = true;
146 user = username;
147
148 profilePath = "/nix/var/nix/profiles/per-user/${username}/home-manager";
149 path =
150 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
151 {
152 inherit pkgs;
153 modules = [
154 {
155 home.username = username;
156 home.stateVersion = "22.11";
157 programs.home-manager.enable = true;
158 }
159 "${./homes}/${username}"
160 ];
161 });
162 };
163 in
164 nixpkgs.lib.pipe ./homes [
165 builtins.readDir
166 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
167 builtins.attrNames
168 (map (name: {
169 inherit name; value = mkBlankConfig name;
170 }))
171 builtins.listToAttrs
172 ]
Skyler Grey07584fb2023-05-01 21:37:13 +0000173 );
174 hostname = "clicks";
175 profilesOrder = [ "system" ];
Skyler Grey1e2187f2023-03-03 22:45:10 +0000176 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000177
Skyler Grey07584fb2023-05-01 21:37:13 +0000178 formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
Skyler Grey1e2187f2023-03-03 22:45:10 +0000179 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000180}