aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/agent.hcl1
-rw-r--r--example/example-batch.hcl46
-rw-r--r--example/example-service.hcl35
-rw-r--r--example/example.hcl24
-rw-r--r--example/example2.hcl28
5 files changed, 82 insertions, 52 deletions
diff --git a/example/agent.hcl b/example/agent.hcl
index 740c221..dc3c2f5 100644
--- a/example/agent.hcl
+++ b/example/agent.hcl
@@ -5,5 +5,6 @@ client {
plugin "nix2-driver" {
config {
+ default_nixpkgs = "github:nixos/nixpkgs/nixos-22.05"
}
}
diff --git a/example/example-batch.hcl b/example/example-batch.hcl
new file mode 100644
index 0000000..a4dc946
--- /dev/null
+++ b/example/example-batch.hcl
@@ -0,0 +1,46 @@
+job "nix2-example-batch" {
+ datacenters = ["dc1"]
+ type = "batch"
+
+ group "example" {
+ # Simple example: how to run a binary from a Nixpkgs package
+ # By default, this will use nixpkgs from github:nixos/nixpkgs/nixos-22.05
+ # as a base system, as defined in the agent config file.
+ # This could be overridden by setting nixpkgs = "another flake"
+ # inside the config {} block
+ task "nix-hello" {
+ driver = "nix2"
+
+ config {
+ packages = [
+ "hello" # equivalent to "github:nixos/nixpkgs/nixos-22.05#hello"
+ ]
+ command = "hello"
+ }
+ }
+
+ # This example show how to setup root CA certificates so that jobs
+ # can do TLS connections
+ # Here, a Nix profile is built using packages curl and cacert from nixpkgs.
+ # Because the cacert package is included, the ca-bundle.crt file is added to
+ # /etc in that profile. Then, the nix2 driver binds all files from that
+ # profile in the root directory, making ca-bundle.crt available directly under /etc.
+ # Reference: see https://gist.github.com/CMCDragonkai/1ae4f4b5edeb021ca7bb1d271caca999
+ task "nix-curl-ssl" {
+ driver = "nix2"
+
+ config {
+ packages = [
+ "curl", "cacert"
+ ]
+ command = "curl"
+ args = [
+ "https://nixos.org"
+ ]
+ }
+ env = {
+ SSL_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt"
+ }
+ }
+ }
+}
diff --git a/example/example-service.hcl b/example/example-service.hcl
new file mode 100644
index 0000000..18dde44
--- /dev/null
+++ b/example/example-service.hcl
@@ -0,0 +1,35 @@
+job "nix2-example-service" {
+ datacenters = ["dc1"]
+ type = "service"
+
+ group "example" {
+ # This task defines a server that runs a simple python file server on port 8080,
+ # which allows to explore the contents of the filesystem namespace as visible
+ # by processes that run inside the task.
+ # A bunch of utilities are included as well, so that you can exec into the container
+ # and explore what's inside by yourself.
+ task "nix-python-serve-http" {
+ driver = "nix2"
+
+ config {
+ packages = [
+ "python3",
+ "bash",
+ "coreutils",
+ "curl",
+ "nix",
+ "git",
+ "cacert",
+ "strace",
+ "gnugrep",
+ "mount",
+ ]
+ command = "python3"
+ args = [ "-m", "http.server", "8080" ]
+ }
+ env = {
+ SSL_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt"
+ }
+ }
+ }
+}
diff --git a/example/example.hcl b/example/example.hcl
deleted file mode 100644
index dee0e0e..0000000
--- a/example/example.hcl
+++ /dev/null
@@ -1,24 +0,0 @@
-job "example" {
- datacenters = ["dc1"]
- type = "batch"
-
- group "example" {
- task "test-nix-hello" {
- driver = "nix2"
-
- config {
- command = "sh"
- args = [
- "-c",
- "pwd; ls -l *; mount; hello"
- ]
- packages = [
- "github:NixOS/nixpkgs#coreutils",
- "github:NixOS/nixpkgs#bash",
- "github:NixOS/nixpkgs#hello"
- ]
- }
- user = "lx"
- }
- }
-}
diff --git a/example/example2.hcl b/example/example2.hcl
deleted file mode 100644
index 8b56f8a..0000000
--- a/example/example2.hcl
+++ /dev/null
@@ -1,28 +0,0 @@
-job "example2" {
- datacenters = ["dc1"]
- type = "service"
-
- group "example" {
- task "server" {
- driver = "nix2"
-
- config {
- packages = [
- "github:nixos/nixpkgs#python3",
- "github:nixos/nixpkgs#bash",
- "github:nixos/nixpkgs#coreutils",
- "github:nixos/nixpkgs#curl",
- "github:nixos/nixpkgs#nix",
- "github:nixos/nixpkgs#git",
- "github:nixos/nixpkgs#cacert",
- "github:nixos/nixpkgs#strace",
- "github:nixos/nixpkgs#gnugrep",
- "github:nixos/nixpkgs#mount",
- ]
- command = "python3"
- args = [ "-m", "http.server", "8080" ]
- }
- user = "lx"
- }
- }
-}