From b8cb2d34cabfa43bfe18df94a82fbbbf978bef6a Mon Sep 17 00:00:00 2001
From: Ben Gamari <ben@smart-cactus.org>
Date: Wed, 2 Nov 2022 17:07:32 -0400
Subject: [PATCH] nixos: Flakify

---
 flake.nix                | 64 ++++++++++++++++++++++++++++++++++++++++
 nixos/freebsd-runner.nix |  2 ++
 2 files changed, 66 insertions(+)
 create mode 100644 flake.nix

diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..e0c7e3a
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,64 @@
+# Usage:
+#
+# {
+#   inputs.ghc-gitlab-runner.url = "git+https://gitlab.haskell.org/ghc/ci-config";
+#   outputs = inputs: {
+#     nixosConfigurations.machine = nixpkgs.lib.nixosSystem {
+#       modules = [
+#         inputs.ghc-gitlab-runner.nixosModules.ghc-runner-common
+#         inputs.ghc-gitlab-runner.nixosModules.ghc-runner
+#         inputs.ghc-gitlab-runner.nixosModules.ghc-runner-freebsd
+#       ];
+#       {
+#         ghc-gitlab-runner.token = "REGISTRATION TOKEN";
+#         ghc-gitlab-runner.name = "NAME";
+#       }
+#     };
+#   };
+# }
+
+{
+  outputs = { self }: {
+    nixosModules.ghc-runner-common = { lib, ... }: {
+      config.virtualisation.docker = {
+        enable = true;
+        autoPrune = {
+          enable = true;
+          flags = [ "--force" "--all" "--volumes" ];
+          dates = "daily";
+        };
+      };
+
+      options.ghc-gitlab-runner.name = lib.mkOption {
+        type = lib.types.str;
+        description = "GitLab runner name";
+      };
+      options.ghc-gitlab-runner.token = lib.mkOption {
+        type = lib.types.str;
+        description = "GitLab registration token";
+      };
+    };
+
+    nixosModules.ghc-runner = {config, ...}: {
+      imports = [
+        (import ./nixos/ci-worker.nix {
+          name = config.ghc-gitlab-runner.name;
+          cores = 16;
+          token = config.ghc-gitlab-runner.token;
+          lintToken = config.ghc-gitlab-runner.token;
+        })
+      ];
+    };
+
+    nixosModules.ghc-runner-freebsd = {config, ...}: {
+      imports = [
+        (import ./nixos/freebsd-runner.nix {
+          runnerName = config.ghc-gitlab-runner.name;
+          token = config.ghc-gitlab-runner.token;
+          cores = 4;
+        })
+      ];
+    };
+  };
+}
+
diff --git a/nixos/freebsd-runner.nix b/nixos/freebsd-runner.nix
index 2a09e5c..f8de84a 100644
--- a/nixos/freebsd-runner.nix
+++ b/nixos/freebsd-runner.nix
@@ -72,6 +72,8 @@ in
     User = "gitlab-runner";
     Group = "gitlab-runner";
   };
+
+  virtualisation.libvirtd.enable = true;
   
   users.groups.gitlab-runner = { };
   users.users.gitlab-runner = {
-- 
GitLab