Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 1 | { |
| 2 | description = "A flake to deploy and configure Clicks' NixOS server"; |
| 3 | |
Skyler Grey | 07c947a | 2023-06-08 14:11:23 +0200 | [diff] [blame] | 4 | inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; |
Skyler Grey | b30f5dd | 2023-09-01 21:02:44 +0000 | [diff] [blame] | 5 | inputs.nixpkgs-clicksforms.url = "github:nixos/nixpkgs/nixos-22.05"; |
Skyler Grey | 061574c | 2023-05-01 21:39:24 +0000 | [diff] [blame] | 6 | inputs.flake-utils.url = "github:numtide/flake-utils"; |
Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 7 | inputs.deploy-rs.url = "github:serokell/deploy-rs"; |
Skyler Grey | 07c947a | 2023-06-08 14:11:23 +0200 | [diff] [blame] | 8 | inputs.home-manager.url = "github:nix-community/home-manager/release-23.05"; |
Skyler Grey | a7fbaee | 2023-05-12 00:29:20 +0000 | [diff] [blame] | 9 | inputs.sops-nix.url = "github:Mic92/sops-nix"; |
Skyler Grey | a78aa67 | 2023-05-20 13:48:18 +0200 | [diff] [blame] | 10 | inputs.scalpel.url = "github:polygon/scalpel"; |
Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 11 | |
Skyler Grey | fed0bb1 | 2023-05-01 21:42:03 +0000 | [diff] [blame] | 12 | inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs"; |
Skyler Grey | fed0bb1 | 2023-05-01 21:42:03 +0000 | [diff] [blame] | 13 | |
Skyler Grey | a7fbaee | 2023-05-12 00:29:20 +0000 | [diff] [blame] | 14 | inputs.sops-nix.inputs.nixpkgs.follows = "nixpkgs"; |
| 15 | |
Skyler Grey | a78aa67 | 2023-05-20 13:48:18 +0200 | [diff] [blame] | 16 | inputs.scalpel.inputs.nixpkgs.follows = "nixpkgs"; |
| 17 | inputs.scalpel.inputs.sops-nix.follows = "sops-nix"; |
| 18 | |
Skyler Grey | 9fe6128 | 2023-08-20 21:52:48 +0000 | [diff] [blame] | 19 | inputs.nixpkgs-privatebin.url = "github:e1mo/nixpkgs/privatebin"; |
| 20 | |
Skyler Grey | 2ca6ccd | 2023-10-14 22:56:43 +0000 | [diff] [blame] | 21 | inputs.helpers.url = "git+https://git.clicks.codes/Clicks/NixHelpers"; |
| 22 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 23 | outputs = { self, nixpkgs, deploy-rs, home-manager, sops-nix, scalpel |
| 24 | , nixpkgs-privatebin, helpers, ... }@inputs: |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 25 | let |
| 26 | system = "x86_64-linux"; |
| 27 | pkgs = import nixpkgs { |
| 28 | inherit system; |
| 29 | config.allowUnfree = true; |
Skyler Grey | 9fe6128 | 2023-08-20 21:52:48 +0000 | [diff] [blame] | 30 | overlays = [ |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 31 | (final: prev: { |
| 32 | inherit (nixpkgs-privatebin.legacyPackages.${system}) |
| 33 | privatebin pbcli; |
| 34 | }) |
Skyler Grey | 9fe6128 | 2023-08-20 21:52:48 +0000 | [diff] [blame] | 35 | ]; |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 36 | }; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 37 | in rec { |
| 38 | nixosConfigurations.clicks = let |
| 39 | base = nixpkgs.lib.nixosSystem { |
| 40 | inherit system pkgs; |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 41 | modules = [ |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 42 | ./default/configuration.nix |
| 43 | ./default/hardware-configuration.nix |
| 44 | ./modules/cache.nix |
| 45 | ./modules/clamav.nix |
| 46 | ./modules/cloudflare-ddns.nix |
| 47 | ./modules/dmarc.nix |
| 48 | ./modules/dnsmasq.nix |
| 49 | ./modules/doas.nix |
| 50 | ./modules/docker.nix |
| 51 | ./modules/drivePaths.nix |
| 52 | ./modules/ecryptfs.nix |
| 53 | ./modules/fail2ban.nix |
| 54 | ./modules/gerrit.nix |
| 55 | ./modules/git.nix |
| 56 | ./modules/grafana.nix |
| 57 | ./modules/home-manager-users.nix |
| 58 | ./modules/keycloak.nix |
| 59 | ./modules/kitty.nix |
| 60 | ./modules/loginctl-linger.nix |
| 61 | ./modules/matrix.nix |
| 62 | ./modules/mongodb.nix |
| 63 | ./modules/networking.nix |
| 64 | ./modules/nextcloud.nix |
| 65 | ./modules/nginx-routes.nix |
| 66 | ./modules/nginx.nix |
| 67 | ./modules/node.nix |
| 68 | ./modules/postgres.nix |
| 69 | ./modules/privatebin.nix |
| 70 | ./modules/samba.nix |
| 71 | ./modules/scalpel.nix |
| 72 | ./modules/ssh.nix |
| 73 | ./modules/static-ip.nix |
| 74 | ./modules/syncthing.nix |
| 75 | ./modules/tesseract.nix |
| 76 | ./modules/vaultwarden.nix |
| 77 | sops-nix.nixosModules.sops |
| 78 | "${nixpkgs-privatebin}/nixos/modules/services/web-apps/privatebin.nix" |
| 79 | { users.mutableUsers = false; } |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 80 | ]; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 81 | specialArgs = { |
| 82 | base = null; |
| 83 | drive_paths = import ./variables/drive_paths.nix; |
| 84 | inherit system; |
| 85 | helpers = helpers.helpers { inherit pkgs; }; |
| 86 | }; |
Skyler Grey | 4f3e606 | 2023-03-04 01:29:29 +0000 | [diff] [blame] | 87 | }; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 88 | in base.extendModules { |
| 89 | modules = [ scalpel.nixosModules.scalpel ]; |
| 90 | specialArgs = { inherit base; }; |
| 91 | }; |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 92 | |
Skyler Grey | b3516c2 | 2023-05-24 19:17:11 +0200 | [diff] [blame] | 93 | nixosConfigurations.clicks-without-mongodb = |
| 94 | nixosConfigurations.clicks.extendModules { |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 95 | modules = [{ services.mongodb.enable = nixpkgs.lib.mkForce false; }]; |
Skyler Grey | b3516c2 | 2023-05-24 19:17:11 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 98 | deploy.nodes.clicks = { |
| 99 | sudo = "doas -u"; |
| 100 | profiles = { |
| 101 | system = { |
| 102 | remoteBuild = true; |
| 103 | user = "root"; |
| 104 | path = deploy-rs.lib.x86_64-linux.activate.nixos |
Skyler Grey | bcb46d3 | 2023-11-10 20:48:38 +0000 | [diff] [blame^] | 105 | self.nixosConfigurations.clicks-without-mongodb; |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 106 | }; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 107 | } // (let |
| 108 | mkServiceConfig = service: { |
| 109 | remoteBuild = true; |
| 110 | user = service; |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 111 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 112 | profilePath = |
| 113 | "/nix/var/nix/profiles/per-user/${service}/home-manager"; |
| 114 | path = deploy-rs.lib.x86_64-linux.activate.home-manager |
| 115 | (home-manager.lib.homeManagerConfiguration { |
| 116 | inherit pkgs; |
| 117 | modules = [ |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 118 | { |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 119 | home.homeDirectory = "/services/${service}"; |
| 120 | home.username = service; |
| 121 | home.stateVersion = "22.11"; |
| 122 | programs.home-manager.enable = true; |
| 123 | } |
| 124 | "${./services}/${service}" |
| 125 | ]; |
| 126 | extraSpecialArgs = { |
| 127 | inherit (inputs) nixpkgs-clicksforms; |
| 128 | inherit system; |
| 129 | }; |
| 130 | }); |
| 131 | }; |
| 132 | in nixpkgs.lib.pipe ./services [ |
| 133 | builtins.readDir |
| 134 | (nixpkgs.lib.filterAttrs (_name: value: value == "directory")) |
| 135 | builtins.attrNames |
| 136 | (map (name: { |
| 137 | inherit name; |
| 138 | value = mkServiceConfig name; |
| 139 | })) |
| 140 | builtins.listToAttrs |
| 141 | ]) // (let |
| 142 | mkBlankConfig = username: { |
| 143 | remoteBuild = true; |
| 144 | user = username; |
Skyler Grey | 5b2c038 | 2023-05-29 11:09:05 +0200 | [diff] [blame] | 145 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 146 | profilePath = |
| 147 | "/nix/var/nix/profiles/per-user/${username}/home-manager"; |
| 148 | path = deploy-rs.lib.x86_64-linux.activate.home-manager |
| 149 | (home-manager.lib.homeManagerConfiguration { |
| 150 | inherit pkgs; |
| 151 | modules = [ |
| 152 | { |
| 153 | home.username = username; |
| 154 | home.stateVersion = "22.11"; |
| 155 | programs.home-manager.enable = true; |
| 156 | } |
| 157 | "${./homes}/${username}" |
| 158 | ]; |
| 159 | }); |
| 160 | }; |
| 161 | in nixpkgs.lib.pipe ./homes [ |
| 162 | builtins.readDir |
| 163 | (nixpkgs.lib.filterAttrs (_name: value: value == "directory")) |
| 164 | builtins.attrNames |
| 165 | (map (name: { |
| 166 | inherit name; |
| 167 | value = mkBlankConfig name; |
| 168 | })) |
| 169 | builtins.listToAttrs |
| 170 | ]); |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 171 | hostname = "clicks"; |
| 172 | profilesOrder = [ "system" ]; |
Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 173 | }; |
Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 174 | |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame] | 175 | devShells.x86_64-linux.default = |
| 176 | pkgs.mkShell { packages = [ pkgs.deploy-rs ]; }; |
Skyler Grey | b30f5dd | 2023-09-01 21:02:44 +0000 | [diff] [blame] | 177 | |
Skyler Grey | 2ca6ccd | 2023-10-14 22:56:43 +0000 | [diff] [blame] | 178 | formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt; |
Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 179 | }; |
Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 180 | } |