ci.nix 4.42 KB
Newer Older
Valentin Reis's avatar
Valentin Reis committed
1
{
Valentin Reis's avatar
Valentin Reis committed
2
  pkgs ? import ../pin.nix {jsonpath=../nixpkgs-18.03.json;}
Valentin Reis's avatar
Valentin Reis committed
3 4 5 6
}:
let
  keys = [ (pkgs.lib.readFile keys/id_rsa_vrg.pub) ];
  argopkgs = import ../pkgs {};
Valentin Reis's avatar
Valentin Reis committed
7
  hydraSrc = builtins.fetchTarball https://github.com/nixos/hydra/archive/master.tar.gz;
Valentin Reis's avatar
Valentin Reis committed
8
  argomodules = import ../modules/module-list.nix;
Valentin Reis's avatar
Valentin Reis committed
9 10 11 12 13 14
in
  {
    network.description = "argo-ci";
    network.enableRollback = false;

    main =
Valentin Reis's avatar
Valentin Reis committed
15
    { config, ... }:
Valentin Reis's avatar
Valentin Reis committed
16
    {
Valentin Reis's avatar
Valentin Reis committed
17
      require=argomodules;
18 19 20
      environment.argo.known-hosts.enable=true;
      environment.argo.provider-tacc.enable=true;
      environment.argo.root-access.enable=true;
Valentin Reis's avatar
Valentin Reis committed
21

22
      imports = [ "${hydraSrc}/hydra-module.nix" ];
Valentin Reis's avatar
Valentin Reis committed
23 24
      networking = {
        firewall = {
25
          allowedTCPPorts=[ config.services.hydra.port ];
Valentin Reis's avatar
Valentin Reis committed
26 27 28 29 30 31
        };
      };

      deployment.targetEnv = "none";
      deployment.targetHost = "129.114.111.116";

Valentin Reis's avatar
Valentin Reis committed
32 33 34 35 36 37 38 39 40 41 42 43
      i18n.defaultLocale = "en_US.UTF-8";
      services.ntp.enable = false;
      services.openssh.allowSFTP = false;

      assertions = pkgs.lib.singleton {
        assertion = pkgs.system == "x86_64-linux";
        message = "unsupported system ${pkgs.system}";
      };

      environment.etc = pkgs.lib.singleton {
        target = "nix/id_buildfarm";
        source = keys/id_buildfarm;
Valentin Reis's avatar
Valentin Reis committed
44 45 46
        uid = config.users.users.hydra-queue-runner.uid;
        gid = config.users.groups.hydra.gid;
        mode = "0600";
Valentin Reis's avatar
Valentin Reis committed
47 48 49 50 51 52 53
      };

      nix = {
        useChroot = true;
        nrBuildUsers = 30;
        distributedBuilds = true;
        buildMachines = [
Valentin Reis's avatar
Valentin Reis committed
54 55 56 57 58 59 60 61
          { hostName = "129.114.111.114";
            maxJobs = 10;
            speedFactor = 1;
            sshKey = "/etc/nix/id_buildfarm";
            sshUser = "root";
            systems = ["builtin" "x86_64-linux" "i686-linux"];
            supportedFeatures = [ "nixos-test" "benchmark" ];
          }
Valentin Reis's avatar
Valentin Reis committed
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
        ];
        extraOptions = "auto-optimise-store = true";
      };

      services.hydra = {
        enable = true;
        hydraURL = "http://129.114.111.116";
        notificationSender = "hydra@example.org";
        port = 8080;
        extraConfig = "binary_cache_secret_key_file = /etc/nix/hydra.example.org-1/secret";
        buildMachinesFiles = [ "/etc/nix/machines" ];
      };

      services.postgresql = {
        package = pkgs.postgresql94;
        dataDir = "/var/db/postgresql-${config.services.postgresql.package.psqlSchema}";
      };

      systemd.services.hydra-manual-setup = {
        description = "Create Admin User for Hydra";
        serviceConfig.Type = "oneshot";
        serviceConfig.RemainAfterExit = true;
        wantedBy = [ "multi-user.target" ];
        requires = [ "hydra-init.service" ];
        after = [ "hydra-init.service" ];
        environment = config.systemd.services.hydra-init.environment;
        script = ''
          if [ ! -e ~hydra/.setup-is-complete ]; then
            # create admin user
            /run/current-system/sw/bin/hydra-create-user alice --full-name 'Alice Q. User' --email-address 'alice@example.org' --password foobar --role admin
            # create signing keys
            /run/current-system/sw/bin/install -d -m 551 /etc/nix/hydra.example.org-1
            /run/current-system/sw/bin/nix-store --generate-binary-cache-key hydra.example.org-1 /etc/nix/hydra.example.org-1/secret /etc/nix/hydra.example.org-1/public
            /run/current-system/sw/bin/chown -R hydra:hydra /etc/nix/hydra.example.org-1
            /run/current-system/sw/bin/chmod 440 /etc/nix/hydra.example.org-1/secret
            /run/current-system/sw/bin/chmod 444 /etc/nix/hydra.example.org-1/public
            # done
            touch ~hydra/.setup-is-complete
          fi
        '';
      };
Valentin Reis's avatar
Valentin Reis committed
103
     };
Valentin Reis's avatar
Valentin Reis committed
104 105

    slave1 =
Valentin Reis's avatar
Valentin Reis committed
106
    { ... }:
Valentin Reis's avatar
Valentin Reis committed
107 108 109 110
    {
      deployment.targetEnv = "none";
      deployment.targetHost = "129.114.111.114";

111 112 113 114
      require=argomodules;
      environment.argo.known-hosts.enable=true;
      environment.argo.provider-tacc.enable=true;
      environment.argo.root-access.enable=true;
Valentin Reis's avatar
Valentin Reis committed
115 116 117 118 119 120 121 122 123 124 125 126 127

      i18n.defaultLocale = "en_US.UTF-8";
      nix.useChroot = true;
      nix.nrBuildUsers = 30;
      services.ntp.enable = false;
      services.openssh.allowSFTP = false;

      nix.gc = {
        automatic = true;
        dates = "05:15";
        options = ''--max-freed "$((32 * 1024**3 - 1024 * $(df -P -k /nix/store | tail -n 1 | ${pkgs.gawk}/bin/awk '{ print $4 }')))"'';
      };

128
      services.openssh.enable = true;
Valentin Reis's avatar
Valentin Reis committed
129
      users.extraUsers.root.openssh.authorizedKeys.keys = [ (pkgs.lib.readFile ./keys/id_buildfarm.pub)];
Valentin Reis's avatar
Valentin Reis committed
130
     };
Valentin Reis's avatar
Valentin Reis committed
131
   }