blob: d2be14dc493fe4a58b9e989f31570f7a7ab64fbe [file] [log] [blame]
Skyler Grey1e2187f2023-03-03 22:45:10 +00001{
2 description = "A flake to deploy and configure Clicks' NixOS server";
3
Skyler Grey07584fb2023-05-01 21:37:13 +00004 inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
Skyler Greya7fbaee2023-05-12 00:29:20 +00005 inputs.nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
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 Grey07584fb2023-05-01 21:37:13 +00008 inputs.home-manager.url = "github:nix-community/home-manager/release-22.11";
Skyler Greya7fbaee2023-05-12 00:29:20 +00009 inputs.sops-nix.url = "github:Mic92/sops-nix";
Skyler Grey1e2187f2023-03-03 22:45:10 +000010
Skyler Greyfed0bb12023-05-01 21:42:03 +000011 inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";
12 inputs.home-manager.inputs.utils.follows = "deploy-rs/utils";
13
Skyler Greya7fbaee2023-05-12 00:29:20 +000014 inputs.sops-nix.inputs.nixpkgs.follows = "nixpkgs";
15
16 outputs = { self, nixpkgs, deploy-rs, home-manager, sops-nix, nixpkgs-unstable, ... }@inputs:
Skyler Grey07584fb2023-05-01 21:37:13 +000017 let
18 system = "x86_64-linux";
19 pkgs = import nixpkgs {
20 inherit system;
21 config.allowUnfree = true;
22 };
Skyler Greya7fbaee2023-05-12 00:29:20 +000023 pkgs-unstable = import nixpkgs-unstable {
24 inherit system;
25 config.allowUnfree = true;
26 };
Skyler Grey07584fb2023-05-01 21:37:13 +000027 in
28 {
29 nixosConfigurations.clicks =
30 nixpkgs.lib.nixosSystem {
31 inherit system pkgs;
32 modules = [
33 ./default/configuration.nix
34 ./default/hardware-configuration.nix
35 ./modules/caddy.nix
36 ./modules/clamav.nix
37 ./modules/code-server.nix
Skyler Greya7fbaee2023-05-12 00:29:20 +000038 ./modules/dmarc.nix
Skyler Grey07584fb2023-05-01 21:37:13 +000039 ./modules/dnsmasq.nix
40 ./modules/doas.nix
41 ./modules/docker.nix
42 ./modules/ecryptfs.nix
43 ./modules/fail2ban.nix
44 ./modules/fuck.nix
45 ./modules/git.nix
Skyler Grey6f0f43d2023-05-03 15:01:05 +000046 ./modules/grafana.nix
Skyler Grey07584fb2023-05-01 21:37:13 +000047 ./modules/home-manager-users.nix
48 ./modules/kitty.nix
49 ./modules/mongodb.nix
50 ./modules/node.nix
51 ./modules/samba.nix
52 ./modules/tesseract.nix
Skyler Greya7fbaee2023-05-12 00:29:20 +000053 sops-nix.nixosModules.sops
Skyler Grey07584fb2023-05-01 21:37:13 +000054 {
55 users.mutableUsers = false;
Skyler Greya7fbaee2023-05-12 00:29:20 +000056 _module.args = { inherit pkgs-unstable; };
Skyler Grey07584fb2023-05-01 21:37:13 +000057 }
58 ];
Skyler Grey4f3e6062023-03-04 01:29:29 +000059 };
Skyler Grey07584fb2023-05-01 21:37:13 +000060
61 deploy.nodes.clicks = {
62 sudo = "doas -u";
63 profiles = {
64 system = {
65 remoteBuild = true;
66 user = "root";
67 path = deploy-rs.lib.x86_64-linux.activate.nixos
68 self.nixosConfigurations.clicks;
69 };
70 } // (
71 let
72 mkServiceConfig = service: {
73 remoteBuild = true;
74 user = service;
75
76 profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager";
77 path =
78 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
79 {
80 inherit pkgs;
81 modules = [
82 {
83 home.homeDirectory = "/services/${service}";
84 home.username = service;
85 home.stateVersion = "22.11";
86 programs.home-manager.enable = true;
87 }
88 "${./services}/${service}"
89 ];
90 });
91 };
92 in
93 nixpkgs.lib.pipe ./services [
94 builtins.readDir
95 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
96 builtins.attrNames
97 (map (name: {
98 inherit name; value = mkServiceConfig name;
99 }))
100 builtins.listToAttrs
101 ]
102 );
103 hostname = "clicks";
104 profilesOrder = [ "system" ];
Skyler Grey1e2187f2023-03-03 22:45:10 +0000105 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000106
Skyler Grey07584fb2023-05-01 21:37:13 +0000107 formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
Skyler Grey1e2187f2023-03-03 22:45:10 +0000108 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000109}