blob: 3b81fe7c8ac1126df87252611a83bc61bb7a6521 [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 Grey07c947a2023-06-08 14:11:23 +020018 outputs = { self, nixpkgs, deploy-rs, home-manager, sops-nix, scalpel, ... }@inputs:
Skyler Grey07584fb2023-05-01 21:37:13 +000019 let
20 system = "x86_64-linux";
21 pkgs = import nixpkgs {
22 inherit system;
23 config.allowUnfree = true;
24 };
25 in
Skyler Greyb3516c22023-05-24 19:17:11 +020026 rec {
Skyler Grey07584fb2023-05-01 21:37:13 +000027 nixosConfigurations.clicks =
Skyler Greya78aa672023-05-20 13:48:18 +020028 let
29 base = nixpkgs.lib.nixosSystem {
30 inherit system pkgs;
31 modules = [
32 ./default/configuration.nix
33 ./default/hardware-configuration.nix
Skyler Grey703e75a2023-06-08 13:39:50 +020034 ./modules/cache.nix
Skyler Greya78aa672023-05-20 13:48:18 +020035 ./modules/caddy.nix
36 ./modules/clamav.nix
Skyler Greya78aa672023-05-20 13:48:18 +020037 ./modules/dmarc.nix
38 ./modules/dnsmasq.nix
39 ./modules/doas.nix
40 ./modules/docker.nix
41 ./modules/ecryptfs.nix
42 ./modules/fail2ban.nix
43 ./modules/fuck.nix
44 ./modules/git.nix
45 ./modules/grafana.nix
46 ./modules/home-manager-users.nix
47 ./modules/kitty.nix
Skyler Grey480fd8b2023-05-24 19:11:16 +020048 ./modules/loginctl-linger.nix
Skyler Greya78aa672023-05-20 13:48:18 +020049 ./modules/matrix.nix
50 ./modules/mongodb.nix
51 ./modules/node.nix
52 ./modules/postgres.nix
53 ./modules/samba.nix
54 ./modules/scalpel.nix
Skyler Grey07c947a2023-06-08 14:11:23 +020055 ./modules/ssh.nix
Skyler Grey5b2c0382023-05-29 11:09:05 +020056 ./modules/static-ip.nix
Skyler Greya78aa672023-05-20 13:48:18 +020057 ./modules/tesseract.nix
58 sops-nix.nixosModules.sops
59 {
60 users.mutableUsers = false;
Skyler Greya78aa672023-05-20 13:48:18 +020061 }
62 ];
TheCodedProfd23784c2023-06-13 14:28:23 -040063 specialArgs = { base = null; drive_paths = import ./variables/drive_paths.nix; };
Skyler Greya78aa672023-05-20 13:48:18 +020064 };
65 in
66 base.extendModules {
Skyler Grey07584fb2023-05-01 21:37:13 +000067 modules = [
Skyler Greya78aa672023-05-20 13:48:18 +020068 scalpel.nixosModules.scalpel
Skyler Grey07584fb2023-05-01 21:37:13 +000069 ];
Skyler Greya78aa672023-05-20 13:48:18 +020070 specialArgs = { inherit base; };
Skyler Grey4f3e6062023-03-04 01:29:29 +000071 };
Skyler Grey07584fb2023-05-01 21:37:13 +000072
Skyler Greyb3516c22023-05-24 19:17:11 +020073 nixosConfigurations.clicks-without-mongodb =
74 nixosConfigurations.clicks.extendModules {
75 modules = [
76 { services.mongodb.enable = nixpkgs.lib.mkForce false; }
77 ];
78 };
79
Skyler Grey07584fb2023-05-01 21:37:13 +000080 deploy.nodes.clicks = {
81 sudo = "doas -u";
82 profiles = {
83 system = {
84 remoteBuild = true;
85 user = "root";
86 path = deploy-rs.lib.x86_64-linux.activate.nixos
87 self.nixosConfigurations.clicks;
88 };
89 } // (
90 let
91 mkServiceConfig = service: {
92 remoteBuild = true;
93 user = service;
94
95 profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager";
96 path =
97 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
98 {
99 inherit pkgs;
100 modules = [
101 {
102 home.homeDirectory = "/services/${service}";
103 home.username = service;
104 home.stateVersion = "22.11";
105 programs.home-manager.enable = true;
106 }
107 "${./services}/${service}"
108 ];
109 });
110 };
111 in
112 nixpkgs.lib.pipe ./services [
113 builtins.readDir
114 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
115 builtins.attrNames
116 (map (name: {
117 inherit name; value = mkServiceConfig name;
118 }))
119 builtins.listToAttrs
120 ]
Skyler Grey5b2c0382023-05-29 11:09:05 +0200121 ) // (
122 let
123 mkBlankConfig = username:
124 {
125 remoteBuild = true;
126 user = username;
127
128 profilePath = "/nix/var/nix/profiles/per-user/${username}/home-manager";
129 path =
130 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
131 {
132 inherit pkgs;
133 modules = [
134 {
135 home.username = username;
136 home.stateVersion = "22.11";
137 programs.home-manager.enable = true;
138 }
139 "${./homes}/${username}"
140 ];
141 });
142 };
143 in
144 nixpkgs.lib.pipe ./homes [
145 builtins.readDir
146 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
147 builtins.attrNames
148 (map (name: {
149 inherit name; value = mkBlankConfig name;
150 }))
151 builtins.listToAttrs
152 ]
Skyler Grey07584fb2023-05-01 21:37:13 +0000153 );
154 hostname = "clicks";
155 profilesOrder = [ "system" ];
Skyler Grey1e2187f2023-03-03 22:45:10 +0000156 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000157
Skyler Grey07584fb2023-05-01 21:37:13 +0000158 formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
Skyler Grey1e2187f2023-03-03 22:45:10 +0000159 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000160}