aboutsummaryrefslogtreecommitdiff
path: root/examples/system/flake.nix
blob: 68cf3cebc187ddb3f408256c870d06e7f711f9da (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
# SPDX-FileCopyrightText: 2020 Serokell <https://serokell.io/>
#
# SPDX-License-Identifier: MPL-2.0

{
  description = "Deploy a full system with hello service as a separate profile";

  outputs = { self, nixpkgs }:
    let
      setActivate = base: activate: nixpkgs.legacyPackages.x86_64-linux.symlinkJoin {
        name = ("activatable-" + base.name);
        paths = [
          base
          (nixpkgs.legacyPackages.x86_64-linux.writeTextFile {
            name = base.name + "-activate-path";
            text = ''
              #!${nixpkgs.legacyPackages.x86_64-linux.runtimeShell}
              ${activate}
            '';
            executable = true;
            destination = "/activate";
          })
        ];
      };
    in
    {
      nixosConfigurations.example-nixos-system = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [ ./configuration.nix ];
      };

      nixosConfigurations.bare = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules =
          [ ./bare.nix "${nixpkgs}/nixos/modules/virtualisation/qemu-vm.nix" ];
      };

      # This is the application we actually want to run
      defaultPackage.x86_64-linux = import ./hello.nix nixpkgs;

      deploy.nodes.example = {
        sshOpts = [ "-p" "2221" ];
        hostname = "localhost";
        fastConnection = true;
        profiles = {
          system = {
            sshUser = "admin";
            path =
              setActivate self.nixosConfigurations.example-nixos-system.config.system.build.toplevel "./bin/switch-to-configuration switch";
            user = "root";
          };
          hello = {
            sshUser = "hello";
            path = setActivate self.defaultPackage.x86_64-linux "./bin/activate";
            user = "hello";
          };
        };
      };

      checks = builtins.mapAttrs
        (_: pkgs: {
          jsonschema = pkgs.runCommandNoCC "jsonschema-deploy-system" { }
            "${pkgs.python3.pkgs.jsonschema}/bin/jsonschema -i ${
          pkgs.writeText "deploy.json" (builtins.toJSON self.deploy)
        } ${../../interface/deploy.json} && touch $out";
        })
        nixpkgs.legacyPackages;
    };
}