From 59aba7607507193587be7c24229dc71066e3ae87 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 29 Nov 2022 16:19:19 +0100 Subject: Ability to use taskdir as flake; change nixpkgs syntax --- example/example-batch.hcl | 27 +++++++++++++++++++++++++-- example/example-service.hcl | 22 +++++++++++----------- example/flake.nix | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 example/flake.nix (limited to 'example') diff --git a/example/example-batch.hcl b/example/example-batch.hcl index a4dc946..15635f9 100644 --- a/example/example-batch.hcl +++ b/example/example-batch.hcl @@ -12,8 +12,11 @@ job "nix2-example-batch" { driver = "nix2" config { + # Packages contains a list of Nix flakes to include in the environement. + # Entries that start with # will be relative to nixpkgs. + # Otherwise, they are flake names that are passed directly to Nix build packages = [ - "hello" # equivalent to "github:nixos/nixpkgs/nixos-22.05#hello" + "#hello" # equivalent to "github:nixos/nixpkgs/nixos-22.05#hello" ] command = "hello" } @@ -31,7 +34,7 @@ job "nix2-example-batch" { config { packages = [ - "curl", "cacert" + "#curl", "#cacert" ] command = "curl" args = [ @@ -42,5 +45,25 @@ job "nix2-example-batch" { SSL_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt" } } + + # This example show how to use a flake defined from a file + task "nix-hello-flake" { + driver = "nix2" + + config { + # Packages contains a list of Nix flakes to include in the environement. + # Entries that start with # will be relative to nixpkgs. + # Otherwise, they are flake names that are passed directly to Nix build + packages = [ + ".#hello" + ] + command = "hello" + } + + template { + data = file("flake.nix") + destination = "flake.nix" + } + } } } diff --git a/example/example-service.hcl b/example/example-service.hcl index 03ba0d3..2f65435 100644 --- a/example/example-service.hcl +++ b/example/example-service.hcl @@ -13,17 +13,17 @@ job "nix2-example-service" { config { packages = [ - "python3", - "bash", - "coreutils", - "curl", - "nix", - "git", - "cacert", - "strace", - "gnugrep", - "findutils", - "mount", + "#python3", + "#bash", + "#coreutils", + "#curl", + "#nix", + "#git", + "#cacert", + "#strace", + "#gnugrep", + "#findutils", + "#mount", ] command = "python3" args = [ "-m", "http.server", "8080" ] diff --git a/example/flake.nix b/example/flake.nix new file mode 100644 index 0000000..3e48ddb --- /dev/null +++ b/example/flake.nix @@ -0,0 +1,18 @@ +{ + description = "A very basic flake"; + + outputs = { self, nixpkgs }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + hello = pkgs.writeScriptBin "hello" '' + #!${pkgs.bash}/bin/bash + echo "Hello from bash script!" + ''; + in { + + packages.x86_64-linux.hello = hello; + + packages.x86_64-linux.default = self.packages.x86_64-linux.hello; + + }; +} -- cgit v1.2.3