blob: c897bc8f431d8f1a2f564065a270d274bc5b79d3 [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 Greya78aa672023-05-20 13:48:18 +020010 inputs.scalpel.url = "github:polygon/scalpel";
Skyler Grey1e2187f2023-03-03 22:45:10 +000011
Skyler Greyfed0bb12023-05-01 21:42:03 +000012 inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";
13 inputs.home-manager.inputs.utils.follows = "deploy-rs/utils";
14
Skyler Greya7fbaee2023-05-12 00:29:20 +000015 inputs.sops-nix.inputs.nixpkgs.follows = "nixpkgs";
16
Skyler Greya78aa672023-05-20 13:48:18 +020017 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 Grey07584fb2023-05-01 21:37:13 +000021 let
22 system = "x86_64-linux";
23 pkgs = import nixpkgs {
24 inherit system;
25 config.allowUnfree = true;
26 };
Skyler Greya7fbaee2023-05-12 00:29:20 +000027 pkgs-unstable = import nixpkgs-unstable {
28 inherit system;
29 config.allowUnfree = true;
30 };
Skyler Grey07584fb2023-05-01 21:37:13 +000031 in
32 {
33 nixosConfigurations.clicks =
Skyler Greya78aa672023-05-20 13:48:18 +020034 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
54 ./modules/matrix.nix
55 ./modules/mongodb.nix
56 ./modules/node.nix
57 ./modules/postgres.nix
58 ./modules/samba.nix
59 ./modules/scalpel.nix
60 ./modules/tesseract.nix
61 sops-nix.nixosModules.sops
62 {
63 users.mutableUsers = false;
64 _module.args = { inherit pkgs-unstable; };
65 }
66 ];
67 specialArgs = { base = null; };
68 };
69 in
70 base.extendModules {
Skyler Grey07584fb2023-05-01 21:37:13 +000071 modules = [
Skyler Greya78aa672023-05-20 13:48:18 +020072 scalpel.nixosModules.scalpel
Skyler Grey07584fb2023-05-01 21:37:13 +000073 ];
Skyler Greya78aa672023-05-20 13:48:18 +020074 specialArgs = { inherit base; };
Skyler Grey4f3e6062023-03-04 01:29:29 +000075 };
Skyler Grey07584fb2023-05-01 21:37:13 +000076
77 deploy.nodes.clicks = {
78 sudo = "doas -u";
79 profiles = {
80 system = {
81 remoteBuild = true;
82 user = "root";
83 path = deploy-rs.lib.x86_64-linux.activate.nixos
84 self.nixosConfigurations.clicks;
85 };
86 } // (
87 let
88 mkServiceConfig = service: {
89 remoteBuild = true;
90 user = service;
91
92 profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager";
93 path =
94 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
95 {
96 inherit pkgs;
97 modules = [
98 {
99 home.homeDirectory = "/services/${service}";
100 home.username = service;
101 home.stateVersion = "22.11";
102 programs.home-manager.enable = true;
103 }
104 "${./services}/${service}"
105 ];
106 });
107 };
108 in
109 nixpkgs.lib.pipe ./services [
110 builtins.readDir
111 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
112 builtins.attrNames
113 (map (name: {
114 inherit name; value = mkServiceConfig name;
115 }))
116 builtins.listToAttrs
117 ]
118 );
119 hostname = "clicks";
120 profilesOrder = [ "system" ];
Skyler Grey1e2187f2023-03-03 22:45:10 +0000121 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000122
Skyler Grey07584fb2023-05-01 21:37:13 +0000123 formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
Skyler Grey1e2187f2023-03-03 22:45:10 +0000124 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000125}