blob: 2dafc74162da5eb4eefc59921ac3cbb691d28b4b [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
Skyler Grey480fd8b2023-05-24 19:11:16 +020054 ./modules/loginctl-linger.nix
Skyler Greya78aa672023-05-20 13:48:18 +020055 ./modules/matrix.nix
56 ./modules/mongodb.nix
57 ./modules/node.nix
58 ./modules/postgres.nix
59 ./modules/samba.nix
60 ./modules/scalpel.nix
61 ./modules/tesseract.nix
62 sops-nix.nixosModules.sops
63 {
64 users.mutableUsers = false;
65 _module.args = { inherit pkgs-unstable; };
66 }
67 ];
68 specialArgs = { base = null; };
69 };
70 in
71 base.extendModules {
Skyler Grey07584fb2023-05-01 21:37:13 +000072 modules = [
Skyler Greya78aa672023-05-20 13:48:18 +020073 scalpel.nixosModules.scalpel
Skyler Grey07584fb2023-05-01 21:37:13 +000074 ];
Skyler Greya78aa672023-05-20 13:48:18 +020075 specialArgs = { inherit base; };
Skyler Grey4f3e6062023-03-04 01:29:29 +000076 };
Skyler Grey07584fb2023-05-01 21:37:13 +000077
78 deploy.nodes.clicks = {
79 sudo = "doas -u";
80 profiles = {
81 system = {
82 remoteBuild = true;
83 user = "root";
84 path = deploy-rs.lib.x86_64-linux.activate.nixos
85 self.nixosConfigurations.clicks;
86 };
87 } // (
88 let
89 mkServiceConfig = service: {
90 remoteBuild = true;
91 user = service;
92
93 profilePath = "/nix/var/nix/profiles/per-user/${service}/home-manager";
94 path =
95 deploy-rs.lib.x86_64-linux.activate.home-manager (home-manager.lib.homeManagerConfiguration
96 {
97 inherit pkgs;
98 modules = [
99 {
100 home.homeDirectory = "/services/${service}";
101 home.username = service;
102 home.stateVersion = "22.11";
103 programs.home-manager.enable = true;
104 }
105 "${./services}/${service}"
106 ];
107 });
108 };
109 in
110 nixpkgs.lib.pipe ./services [
111 builtins.readDir
112 (nixpkgs.lib.filterAttrs (_name: value: value == "directory"))
113 builtins.attrNames
114 (map (name: {
115 inherit name; value = mkServiceConfig name;
116 }))
117 builtins.listToAttrs
118 ]
119 );
120 hostname = "clicks";
121 profilesOrder = [ "system" ];
Skyler Grey1e2187f2023-03-03 22:45:10 +0000122 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000123
Skyler Grey07584fb2023-05-01 21:37:13 +0000124 formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
Skyler Grey1e2187f2023-03-03 22:45:10 +0000125 };
Skyler Grey1e2187f2023-03-03 22:45:10 +0000126}