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 | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 4 | inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11"; |
Skyler Grey | a7fbaee | 2023-05-12 00:29:20 +0000 | [diff] [blame] | 5 | inputs.nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; |
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 | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 8 | inputs.home-manager.url = "github:nix-community/home-manager/release-22.11"; |
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"; |
| 13 | inputs.home-manager.inputs.utils.follows = "deploy-rs/utils"; |
| 14 | |
Skyler Grey | a7fbaee | 2023-05-12 00:29:20 +0000 | [diff] [blame] | 15 | inputs.sops-nix.inputs.nixpkgs.follows = "nixpkgs"; |
| 16 | |
Skyler Grey | a78aa67 | 2023-05-20 13:48:18 +0200 | [diff] [blame] | 17 | inputs.scalpel.inputs.nixpkgs.follows = "nixpkgs"; |
| 18 | inputs.scalpel.inputs.sops-nix.follows = "sops-nix"; |
| 19 | |
| 20 | outputs = { self, nixpkgs, deploy-rs, home-manager, sops-nix, scalpel, nixpkgs-unstable, ... }@inputs: |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 21 | let |
| 22 | system = "x86_64-linux"; |
| 23 | pkgs = import nixpkgs { |
| 24 | inherit system; |
| 25 | config.allowUnfree = true; |
| 26 | }; |
Skyler Grey | a7fbaee | 2023-05-12 00:29:20 +0000 | [diff] [blame] | 27 | pkgs-unstable = import nixpkgs-unstable { |
| 28 | inherit system; |
| 29 | config.allowUnfree = true; |
| 30 | }; |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 31 | in |
Skyler Grey | b3516c2 | 2023-05-24 19:17:11 +0200 | [diff] [blame] | 32 | rec { |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 33 | nixosConfigurations.clicks = |
Skyler Grey | a78aa67 | 2023-05-20 13:48:18 +0200 | [diff] [blame] | 34 | let |
| 35 | base = nixpkgs.lib.nixosSystem { |
| 36 | inherit system pkgs; |
| 37 | modules = [ |
| 38 | ./default/configuration.nix |
| 39 | ./default/hardware-configuration.nix |
| 40 | ./modules/caddy.nix |
| 41 | ./modules/clamav.nix |
| 42 | ./modules/code-server.nix |
| 43 | ./modules/dmarc.nix |
| 44 | ./modules/dnsmasq.nix |
| 45 | ./modules/doas.nix |
| 46 | ./modules/docker.nix |
| 47 | ./modules/ecryptfs.nix |
| 48 | ./modules/fail2ban.nix |
| 49 | ./modules/fuck.nix |
| 50 | ./modules/git.nix |
| 51 | ./modules/grafana.nix |
| 52 | ./modules/home-manager-users.nix |
| 53 | ./modules/kitty.nix |
Skyler Grey | 480fd8b | 2023-05-24 19:11:16 +0200 | [diff] [blame] | 54 | ./modules/loginctl-linger.nix |
Skyler Grey | a78aa67 | 2023-05-20 13:48:18 +0200 | [diff] [blame] | 55 | ./modules/matrix.nix |
| 56 | ./modules/mongodb.nix |
| 57 | ./modules/node.nix |
| 58 | ./modules/postgres.nix |
| 59 | ./modules/samba.nix |
| 60 | ./modules/scalpel.nix |
Skyler Grey | 5b2c038 | 2023-05-29 11:09:05 +0200 | [diff] [blame^] | 61 | ./modules/static-ip.nix |
Skyler Grey | a78aa67 | 2023-05-20 13:48:18 +0200 | [diff] [blame] | 62 | ./modules/tesseract.nix |
| 63 | sops-nix.nixosModules.sops |
| 64 | { |
| 65 | users.mutableUsers = false; |
| 66 | _module.args = { inherit pkgs-unstable; }; |
| 67 | } |
| 68 | ]; |
| 69 | specialArgs = { base = null; }; |
| 70 | }; |
| 71 | in |
| 72 | base.extendModules { |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 73 | modules = [ |
Skyler Grey | a78aa67 | 2023-05-20 13:48:18 +0200 | [diff] [blame] | 74 | scalpel.nixosModules.scalpel |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 75 | ]; |
Skyler Grey | a78aa67 | 2023-05-20 13:48:18 +0200 | [diff] [blame] | 76 | specialArgs = { inherit base; }; |
Skyler Grey | 4f3e606 | 2023-03-04 01:29:29 +0000 | [diff] [blame] | 77 | }; |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 78 | |
Skyler Grey | b3516c2 | 2023-05-24 19:17:11 +0200 | [diff] [blame] | 79 | nixosConfigurations.clicks-without-mongodb = |
| 80 | nixosConfigurations.clicks.extendModules { |
| 81 | modules = [ |
| 82 | { services.mongodb.enable = nixpkgs.lib.mkForce false; } |
| 83 | ]; |
| 84 | }; |
| 85 | |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 86 | deploy.nodes.clicks = { |
| 87 | sudo = "doas -u"; |
| 88 | profiles = { |
| 89 | system = { |
| 90 | remoteBuild = true; |
| 91 | user = "root"; |
| 92 | path = deploy-rs.lib.x86_64-linux.activate.nixos |
| 93 | self.nixosConfigurations.clicks; |
| 94 | }; |
| 95 | } // ( |
| 96 | let |
| 97 | mkServiceConfig = service: { |
| 98 | remoteBuild = true; |
| 99 | user = service; |
| 100 | |
| 101 | profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager"; |
| 102 | path = |
| 103 | deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration |
| 104 | { |
| 105 | inherit pkgs; |
| 106 | modules = [ |
| 107 | { |
| 108 | home.homeDirectory = "/services/${service}"; |
| 109 | home.username = service; |
| 110 | home.stateVersion = "22.11"; |
| 111 | programs.home-manager.enable = true; |
| 112 | } |
| 113 | "${./services}/${service}" |
| 114 | ]; |
| 115 | }); |
| 116 | }; |
| 117 | in |
| 118 | nixpkgs.lib.pipe ./services [ |
| 119 | builtins.readDir |
| 120 | (nixpkgs.lib.filterAttrs (_name: value: value == "directory")) |
| 121 | builtins.attrNames |
| 122 | (map (name: { |
| 123 | inherit name; value = mkServiceConfig name; |
| 124 | })) |
| 125 | builtins.listToAttrs |
| 126 | ] |
Skyler Grey | 5b2c038 | 2023-05-29 11:09:05 +0200 | [diff] [blame^] | 127 | ) // ( |
| 128 | let |
| 129 | mkBlankConfig = username: |
| 130 | { |
| 131 | remoteBuild = true; |
| 132 | user = username; |
| 133 | |
| 134 | profilePath = "/nix/var/nix/profiles/per-user/${username}/home-manager"; |
| 135 | path = |
| 136 | deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration |
| 137 | { |
| 138 | inherit pkgs; |
| 139 | modules = [ |
| 140 | { |
| 141 | home.username = username; |
| 142 | home.stateVersion = "22.11"; |
| 143 | programs.home-manager.enable = true; |
| 144 | } |
| 145 | "${./homes}/${username}" |
| 146 | ]; |
| 147 | }); |
| 148 | }; |
| 149 | in |
| 150 | nixpkgs.lib.pipe ./homes [ |
| 151 | builtins.readDir |
| 152 | (nixpkgs.lib.filterAttrs (_name: value: value == "directory")) |
| 153 | builtins.attrNames |
| 154 | (map (name: { |
| 155 | inherit name; value = mkBlankConfig name; |
| 156 | })) |
| 157 | builtins.listToAttrs |
| 158 | ] |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 159 | ); |
| 160 | hostname = "clicks"; |
| 161 | profilesOrder = [ "system" ]; |
Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 162 | }; |
Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 163 | |
Skyler Grey | 07584fb | 2023-05-01 21:37:13 +0000 | [diff] [blame] | 164 | formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt; |
Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 165 | }; |
Skyler Grey | 1e2187f | 2023-03-03 22:45:10 +0000 | [diff] [blame] | 166 | } |