blob: 3022dc29255bd43f46b67219a532ec949dde9eec [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
Skyler Grey09c5cda2023-10-09 07:10:10 +000069 ./modules/nextcloud.nix
Skyler Greya78aa672023-05-20 13:48:18 +020070 ./modules/node.nix
71 ./modules/postgres.nix
Skyler Grey9fe61282023-08-20 21:52:48 +000072 ./modules/privatebin.nix
Skyler Greya78aa672023-05-20 13:48:18 +020073 ./modules/samba.nix
74 ./modules/scalpel.nix
Skyler Grey07c947a2023-06-08 14:11:23 +020075 ./modules/ssh.nix
Skyler Grey5b2c0382023-05-29 11:09:05 +020076 ./modules/static-ip.nix
Skyler Grey87a11552023-06-14 23:02:25 +020077 ./modules/syncthing.nix
Skyler Greya78aa672023-05-20 13:48:18 +020078 ./modules/tesseract.nix
Skyler Grey87a11552023-06-14 23:02:25 +020079 ./modules/vaultwarden.nix
Skyler Greya78aa672023-05-20 13:48:18 +020080 sops-nix.nixosModules.sops
Skyler Grey9fe61282023-08-20 21:52:48 +000081 "${nixpkgs-privatebin}/nixos/modules/services/web-apps/privatebin.nix"
Skyler Greya78aa672023-05-20 13:48:18 +020082 {
83 users.mutableUsers = false;
Skyler Greya78aa672023-05-20 13:48:18 +020084 }
85 ];
TheCodedProfd23784c2023-06-13 14:28:23 -040086 specialArgs = { base = null; drive_paths = import ./variables/drive_paths.nix; };
Skyler Greya78aa672023-05-20 13:48:18 +020087 };
88 in
89 base.extendModules {
Skyler Grey07584fb2023-05-01 21:37:13 +000090 modules = [
Skyler Greya78aa672023-05-20 13:48:18 +020091 scalpel.nixosModules.scalpel
Skyler Grey07584fb2023-05-01 21:37:13 +000092 ];
Skyler Greya78aa672023-05-20 13:48:18 +020093 specialArgs = { inherit base; };
Skyler Grey4f3e6062023-03-04 01:29:29 +000094 };
Skyler Grey07584fb2023-05-01 21:37:13 +000095
Skyler Greyb3516c22023-05-24 19:17:11 +020096 nixosConfigurations.clicks-without-mongodb =
97 nixosConfigurations.clicks.extendModules {
98 modules = [
99 { services.mongodb.enable = nixpkgs.lib.mkForce false; }
100 ];
101 };
102
Skyler Grey07584fb2023-05-01 21:37:13 +0000103 deploy.nodes.clicks = {
104 sudo = "doas -u";
105 profiles = {
106 system = {
107 remoteBuild = true;
108 user = "root";
109 path = deploy-rs.lib.x86_64-linux.activate.nixos
110 self.nixosConfigurations.clicks;
111 };
112 } // (
113 let
114 mkServiceConfig = service: {
115 remoteBuild = true;
116 user = service;
117
118 profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager";
119 path =
120 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
121 {
122 inherit pkgs;
123 modules = [
124 {
125 home.homeDirectory = "/services/${service}";
126 home.username = service;
127 home.stateVersion = "22.11";
128 programs.home-manager.enable = true;
129 }
130 "${./services}/${service}"
131 ];
Skyler Greyb30f5dd2023-09-01 21:02:44 +0000132 extraSpecialArgs = { inherit (inputs) nixpkgs-clicksforms; inherit system; };
Skyler Grey07584fb2023-05-01 21:37:13 +0000133 });
134 };
135 in
136 nixpkgs.lib.pipe ./services [
137 builtins.readDir
138 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
139 builtins.attrNames
140 (map (name: {
141 inherit name; value = mkServiceConfig name;
142 }))
143 builtins.listToAttrs
144 ]
Skyler Grey5b2c0382023-05-29 11:09:05 +0200145 ) // (
146 let
147 mkBlankConfig = username:
148 {
149 remoteBuild = true;
150 user = username;
151
152 profilePath = "/nix/var/nix/profiles/per-user/${username}/home-manager";
153 path =
154 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
155 {
156 inherit pkgs;
157 modules = [
158 {
159 home.username = username;
160 home.stateVersion = "22.11";
161 programs.home-manager.enable = true;
162 }
163 "${./homes}/${username}"
164 ];
165 });
166 };
167 in
168 nixpkgs.lib.pipe ./homes [
169 builtins.readDir
170 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
171 builtins.attrNames
172 (map (name: {
173 inherit name; value = mkBlankConfig name;
174 }))
175 builtins.listToAttrs
176 ]
Skyler Grey07584fb2023-05-01 21:37:13 +0000177 );
178 hostname = "clicks";
179 profilesOrder = [ "system" ];
Skyler Grey1e2187f2023-03-03 22:45:10 +0000180 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000181
Skyler Greyb30f5dd2023-09-01 21:02:44 +0000182 devShells.x86_64-linux.default = pkgs.mkShell {
183 packages = [ pkgs.deploy-rs ];
184 };
185
Skyler Grey07584fb2023-05-01 21:37:13 +0000186 formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
Skyler Grey1e2187f2023-03-03 22:45:10 +0000187 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000188}