summaryrefslogtreecommitdiffstats
path: root/flake.nix
blob: faf9eadb9ef25f07a97d03fede9d3e22edcfbddb (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
{
  description = "My NixOS configurations";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/release-20.09";
  inputs.nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.home-manager = {
    url = "github:nix-community/home-manager/release-20.09";
    inputs.nixpkgs.follows = "nixpkgs";
  };
  inputs.neovim-master = {
    url = "github:neovim/neovim?dir=contrib";
    inputs.nixpkgs.follows = "nixpkgs-unstable";
  };

  outputs = inputs @ { self, nixpkgs, home-manager, ... }: {

    nixosModules = {
      default = { ... }: {
        imports = [
          home-manager.nixosModules.home-manager
          (import ./configuration.nix inputs)
        ];
      };

      test = { config, ... }: {
        imports = [ self.nixosModules.default ];

        home-manager.users.minijackson.home.stateVersion = "20.09";
        home-manager.users.root.home.stateVersion = "20.09";

        users.users.minijackson.initialHashedPassword = "";
        users.users.root.initialHashedPassword = "";

        topology.mainVpn = {
          interfaceName = "tinc.testNet";
          subnet = "fd1f:340c:c5eb:9b18::/64";
          currentNodeIP = "fd1f:340c:c5eb:9b18::1";
        };

        services.tinc.networks.testNet = { };

        # TODO: automate that? {{{
        networking.interfaces."tinc.testNet" = {
          virtual = true;
          virtualType = "tun";
          ipv6.addresses = [{
            address = config.topology.mainVpn.currentNodeIP;
            prefixLength = 64;
          }];
        };

        systemd.services."tinc.testNet" = {
          after = [ "network-addresses-tinc.testNet.service" ];
          requires = [ "network-addresses-tinc.testNet.service" ];
        };
        # }}}
      };

      usecases.common = {
        backupClient = (import ./usecases/common/backup-client.nix inputs);
        dnscrypt = (import ./usecases/common/dnscrypt.nix inputs);
        fwupd = (import ./usecases/common/fwupd.nix inputs);
      };

      usecases.desktop = {
        default = (import ./usecases/desktop/default.nix inputs);

        development = (import ./usecases/desktop/development.nix inputs);
        networkManager = (import ./usecases/desktop/networking/network-manager.nix inputs);
      };

      usecases.server = {
        default = (import ./usecases/server/default.nix inputs);

        ankisyncd = (import ./usecases/server/ankisyncd.nix inputs);
        audit = (import ./usecases/server/audit.nix inputs);
        fail2ban = (import ./usecases/server/fail2ban.nix inputs);
        gotifyServer = (import ./usecases/server/gotify-server.nix inputs);
        hydraServer = (import ./usecases/server/hydra-server.nix inputs);
        monitoringTarget = (import ./usecases/server/monitoring-target.nix inputs);
        radicale = (import ./usecases/server/radicale.nix inputs);
        smartd = (import ./usecases/server/smartd.nix inputs);
        zfs = (import ./usecases/server/zfs.nix inputs);
      };

      profiles = {
        desktop = (import ./profiles/desktop.nix inputs);
        server = (import ./profiles/server.nix inputs);
      };
    };

    nixosConfigurations = {
      testDefault = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          self.nixosModules.test
        ];
      };

      testPlainDesktop = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          self.nixosModules.test
          self.nixosModules.profiles.desktop
        ];
      };

      testDevDesktop = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          self.nixosModules.test
          self.nixosModules.profiles.desktop
          self.nixosModules.usecases.desktop.development
        ];
      };

      testServer = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          self.nixosModules.test
          self.nixosModules.profiles.server
        ];
      };
    };

    hydraJobs = let
      testing = import (nixpkgs + "/nixos/lib/testing-python.nix") { system = "x86_64-linux"; };
    in {

      tests.testDefault = testing.simpleTest {
        machine = self.nixosModules.test;
        testScript = ''
          # TODO
          machine.wait_for_unit("multi-user.target")
        '';
      };

      tests.testPlainDesktop = testing.simpleTest {
        machine = { ... }: {
          imports = [
            self.nixosModules.test
            self.nixosModules.profiles.desktop
            self.nixosModules.usecases.common.fwupd
          ];
        };
        testScript = ''
          # TODO
          machine.wait_for_unit("multi-user.target")
        '';
      };

      tests.testDevDesktop = testing.simpleTest {
        machine = { ... }: {
          imports = [
            self.nixosModules.test
            self.nixosModules.profiles.desktop
            self.nixosModules.usecases.common.fwupd
            self.nixosModules.usecases.desktop.development
          ];
        };
        testScript = ''
          # TODO
          machine.wait_for_unit("multi-user.target")
        '';
      };

      tests.testServer = testing.simpleTest {
        machine = { ... }: {
          imports = [
            self.nixosModules.test
            self.nixosModules.profiles.server
            self.nixosModules.usecases.server.ankisyncd
            self.nixosModules.usecases.server.gotifyServer
            self.nixosModules.usecases.server.hydraServer
            self.nixosModules.usecases.server.radicale
            self.nixosModules.usecases.server.zfs

            {
              # Needed for ZFS
              networking.hostId = "4e98920d";

              services.hydra = {
                hydraURL = "localhost:3000";
                notificationSender = "hydra@localhost";
                secretKeyLocation = builtins.toFile
                  "secret-key"
                  "testServer:0d5jJjOxIoe6sTr2YKWkQxsM3ZcW+9GAk52yYNVxfYBUxS2nUfzfQk5Jo0OwHnT95bTLXCVNQETGV4m6KHsVCA==";
              };
            }
          ];
        };
        testScript = ''
          # TODO
          machine.wait_for_unit("multi-user.target")
        '';
      };

    };

  };
}