summary refs log tree commit diff stats
path: root/flake.nix
blob: ed8ccc47a59cba4322583ff4f8c76b5b1b5dc8e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:NixOS/nixos-hardware";
    nix-index-database.url = "github:Mic92/nix-index-database";
    nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
    darwin.url = "github:lnl7/nix-darwin/master";
    darwin.inputs.nixpkgs.follows = "nixpkgs";
    home-manager.url = "github:nix-community/home-manager";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    emacs-overlay.url = "github:nix-community/emacs-overlay";
    emacs-overlay.inputs.nixpkgs.follows = "nixpkgs";
    secrets = {
      flake = false;
    };
    utils.url = "github:numtide/flake-utils";
    agenix.url = "github:ryantm/agenix";
    agenix.inputs.nixpkgs.follows = "nixpkgs";
    deploy-rs.url = "github:serokell/deploy-rs";
  };

  outputs =
    inputs@
    { self
    , utils
    , nixpkgs
    , nixos-hardware
    , home-manager
    , darwin
    , nix-index-database
    , secrets
    , emacs-overlay
    , agenix
    , deploy-rs
    , ...
    }:
    let
      mkHomeConfiguration = { modules, system }: home-manager.lib.homeManagerConfiguration {
        pkgs = import nixpkgs {
          inherit system;
          overlays = [
            self.overlays.default
          ];
        };

        inherit modules;
        extraSpecialArgs = {
          inherit inputs system;
        };
      };
    in
    {
      overlays.default = import ./overlays/htmlformat;

      nixosConfigurations.prefect = nixpkgs.lib.nixosSystem {
        system = utils.lib.system.x86_64-linux;
        specialArgs = { inherit inputs; };
        modules = [
          ./system/prefect.nix
        ] ++ (with nixos-hardware.nixosModules; [
          common-cpu-amd
          common-cpu-amd-pstate
          common-pc-ssd
          common-pc
          common-gpu-nvidia-nonprime
        ]);
      };
      nixosConfigurations.nanopi = nixpkgs.lib.nixosSystem {
        system = utils.lib.system.aarch64-linux;
        specialArgs = { inherit inputs; };
        modules = [
          agenix.nixosModules.default
          ./system/nanopi.nix
        ];
      };
      nixosConfigurations.linde = nixpkgs.lib.nixosSystem {
        system = utils.lib.system.aarch64-linux;
        specialArgs = { inherit inputs; };
        modules = [
          agenix.nixosModules.default
          ./system/linde.nix
        ];
      };
      darwinConfigurations.mba = darwin.lib.darwinSystem {
        system = utils.lib.system.aarch64-darwin;
        specialArgs = { inherit inputs; };
        modules = [ ./system/mba.nix ];
      };
      homeConfigurations."alan@mba" = mkHomeConfiguration {
        system = utils.lib.system.aarch64-darwin;
        modules = [
          ./user/mba.nix
          nix-index-database.hmModules.nix-index
          (secrets + "/default.nix")
          (secrets + "/ssh.nix")
          ({ nixpkgs.overlays = [ emacs-overlay.overlay ]; })
        ];
      };
      homeConfigurations."alan@prefect" = mkHomeConfiguration {
        system = utils.lib.system.x86_64-linux;
        modules = [
          ./user/prefect.nix
          nix-index-database.hmModules.nix-index
          (secrets + "/default.nix")
          (secrets + "/ssh.nix")
          ({ nixpkgs.overlays = [ emacs-overlay.overlay ]; })
        ];
      };
      homeConfigurations."alan@nanopi" = mkHomeConfiguration {
        system = utils.lib.system.aarch64-linux;
        modules = [
          ./user/nanopi.nix
          nix-index-database.hmModules.nix-index
          (secrets + "/default.nix")
        ];
      };
      homeConfigurations."alan@linde" = mkHomeConfiguration {
        system = utils.lib.system.aarch64-linux;
        modules = [
          ./user/server.nix
          nix-index-database.hmModules.nix-index
          (secrets + "/default.nix")
        ];
      };

      checks = builtins.mapAttrs
        (system: deployLib:
          deployLib.deployChecks self.deploy)
        deploy-rs.lib;

      deploy = {
        remoteBuild = true;
        nodes.linde = {
          remoteBuild = true;
          hostname = "linde";
          profiles.system = {
            user = "root";
            interactiveSudo = true;
            path = deploy-rs.lib.${utils.lib.system.aarch64-linux}.activate.nixos
              self.nixosConfigurations.linde;
          };
          profiles.alan = {
            user = "alan";
            path = deploy-rs.lib.${utils.lib.system.aarch64-linux}.activate.home-manager
              self.homeConfigurations."alan@linde";
          };
        };
        nodes.nanopi = {
          hostname = "nanopi";
          profiles.system = {
            user = "root";
            interactiveSudo = true;
            path = deploy-rs.lib.${utils.lib.system.aarch64-linux}.activate.nixos
              self.nixosConfigurations.nanopi;
          };
          profiles.alan = {
            user = "alan";
            path = deploy-rs.lib.${utils.lib.system.aarch64-linux}.activate.home-manager
              self.homeConfigurations."alan@nanopi";
          };
        };
      };
    } // utils.lib.eachDefaultSystem (system:
    let
      pkgs = import nixpkgs { inherit system; };
    in
    {
      devShells = {
        default = pkgs.mkShell {
          packages = [
            deploy-rs.packages.${system}.default
            agenix.packages.${system}.default
          ];
        };
      };
    });
}