blob: caa057175c89df45d557a4a154566aa5792b3ee8 [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 Greya78aa672023-05-20 13:48:18 +020051 ./modules/dmarc.nix
52 ./modules/dnsmasq.nix
53 ./modules/doas.nix
54 ./modules/docker.nix
Skyler Grey87a11552023-06-14 23:02:25 +020055 ./modules/drivePaths.nix
Skyler Greya78aa672023-05-20 13:48:18 +020056 ./modules/ecryptfs.nix
57 ./modules/fail2ban.nix
58 ./modules/fuck.nix
59 ./modules/git.nix
60 ./modules/grafana.nix
61 ./modules/home-manager-users.nix
62 ./modules/kitty.nix
Skyler Grey480fd8b2023-05-24 19:11:16 +020063 ./modules/loginctl-linger.nix
Skyler Greya78aa672023-05-20 13:48:18 +020064 ./modules/matrix.nix
65 ./modules/mongodb.nix
66 ./modules/node.nix
67 ./modules/postgres.nix
Skyler Grey9fe61282023-08-20 21:52:48 +000068 ./modules/privatebin.nix
Skyler Greya78aa672023-05-20 13:48:18 +020069 ./modules/samba.nix
70 ./modules/scalpel.nix
Skyler Grey07c947a2023-06-08 14:11:23 +020071 ./modules/ssh.nix
Skyler Grey5b2c0382023-05-29 11:09:05 +020072 ./modules/static-ip.nix
Skyler Grey87a11552023-06-14 23:02:25 +020073 ./modules/syncthing.nix
Skyler Greya78aa672023-05-20 13:48:18 +020074 ./modules/tesseract.nix
Skyler Grey87a11552023-06-14 23:02:25 +020075 ./modules/vaultwarden.nix
Skyler Greya78aa672023-05-20 13:48:18 +020076 sops-nix.nixosModules.sops
Skyler Grey9fe61282023-08-20 21:52:48 +000077 "${nixpkgs-privatebin}/nixos/modules/services/web-apps/privatebin.nix"
Skyler Greya78aa672023-05-20 13:48:18 +020078 {
79 users.mutableUsers = false;
Skyler Greya78aa672023-05-20 13:48:18 +020080 }
81 ];
TheCodedProfd23784c2023-06-13 14:28:23 -040082 specialArgs = { base = null; drive_paths = import ./variables/drive_paths.nix; };
Skyler Greya78aa672023-05-20 13:48:18 +020083 };
84 in
85 base.extendModules {
Skyler Grey07584fb2023-05-01 21:37:13 +000086 modules = [
Skyler Greya78aa672023-05-20 13:48:18 +020087 scalpel.nixosModules.scalpel
Skyler Grey07584fb2023-05-01 21:37:13 +000088 ];
Skyler Greya78aa672023-05-20 13:48:18 +020089 specialArgs = { inherit base; };
Skyler Grey4f3e6062023-03-04 01:29:29 +000090 };
Skyler Grey07584fb2023-05-01 21:37:13 +000091
Skyler Greyb3516c22023-05-24 19:17:11 +020092 nixosConfigurations.clicks-without-mongodb =
93 nixosConfigurations.clicks.extendModules {
94 modules = [
95 { services.mongodb.enable = nixpkgs.lib.mkForce false; }
96 ];
97 };
98
Skyler Grey07584fb2023-05-01 21:37:13 +000099 deploy.nodes.clicks = {
100 sudo = "doas -u";
101 profiles = {
102 system = {
103 remoteBuild = true;
104 user = "root";
105 path = deploy-rs.lib.x86_64-linux.activate.nixos
106 self.nixosConfigurations.clicks;
107 };
108 } // (
109 let
110 mkServiceConfig = service: {
111 remoteBuild = true;
112 user = service;
113
114 profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager";
115 path =
116 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
117 {
118 inherit pkgs;
119 modules = [
120 {
121 home.homeDirectory = "/services/${service}";
122 home.username = service;
123 home.stateVersion = "22.11";
124 programs.home-manager.enable = true;
125 }
126 "${./services}/${service}"
127 ];
128 });
129 };
130 in
131 nixpkgs.lib.pipe ./services [
132 builtins.readDir
133 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
134 builtins.attrNames
135 (map (name: {
136 inherit name; value = mkServiceConfig name;
137 }))
138 builtins.listToAttrs
139 ]
Skyler Grey5b2c0382023-05-29 11:09:05 +0200140 ) // (
141 let
142 mkBlankConfig = username:
143 {
144 remoteBuild = true;
145 user = username;
146
147 profilePath = "/nix/var/nix/profiles/per-user/${username}/home-manager";
148 path =
149 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
150 {
151 inherit pkgs;
152 modules = [
153 {
154 home.username = username;
155 home.stateVersion = "22.11";
156 programs.home-manager.enable = true;
157 }
158 "${./homes}/${username}"
159 ];
160 });
161 };
162 in
163 nixpkgs.lib.pipe ./homes [
164 builtins.readDir
165 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
166 builtins.attrNames
167 (map (name: {
168 inherit name; value = mkBlankConfig name;
169 }))
170 builtins.listToAttrs
171 ]
Skyler Grey07584fb2023-05-01 21:37:13 +0000172 );
173 hostname = "clicks";
174 profilesOrder = [ "system" ];
Skyler Grey1e2187f2023-03-03 22:45:10 +0000175 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000176
Skyler Grey07584fb2023-05-01 21:37:13 +0000177 formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
Skyler Grey1e2187f2023-03-03 22:45:10 +0000178 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000179}