Ability to use taskdir as flake; change nixpkgs syntax
This commit is contained in:
parent
8b424e1950
commit
59aba76075
5 changed files with 59 additions and 17 deletions
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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" ]
|
||||
|
|
18
example/flake.nix
Normal file
18
example/flake.nix
Normal file
|
@ -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;
|
||||
|
||||
};
|
||||
}
|
|
@ -510,8 +510,8 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
|
|||
}
|
||||
// Use that repo for all packages not specified from a flake already.
|
||||
for i := range driverConfig.Packages {
|
||||
if !strings.Contains(driverConfig.Packages[i], "#") && !strings.Contains(driverConfig.Packages[i], "/") {
|
||||
driverConfig.Packages[i] = nixpkgs + "#" + driverConfig.Packages[i]
|
||||
if strings.HasPrefix(driverConfig.Packages[i], "#") {
|
||||
driverConfig.Packages[i] = nixpkgs + driverConfig.Packages[i]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ func prepareNixPackages(taskDir string, packages []string, nixpkgs string) (hclu
|
|||
mounts := make(hclutils.MapStrStr)
|
||||
|
||||
profileLink := filepath.Join(taskDir, "current-profile")
|
||||
profile, err := nixBuildProfile(packages, profileLink)
|
||||
profile, err := nixBuildProfile(taskDir, packages, profileLink)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Build of the flakes failed: %v", err)
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func prepareNixPackages(taskDir string, packages []string, nixpkgs string) (hclu
|
|||
return mounts, nil
|
||||
}
|
||||
|
||||
func nixBuildProfile(flakes []string, link string) (string, error) {
|
||||
func nixBuildProfile(taskDir string, flakes []string, link string) (string, error) {
|
||||
cmd := exec.Command("nix", append(
|
||||
[]string{
|
||||
"--extra-experimental-features", "nix-command",
|
||||
|
@ -84,6 +84,7 @@ func nixBuildProfile(flakes []string, link string) (string, error) {
|
|||
flakes...)...)
|
||||
stderr := &bytes.Buffer{}
|
||||
cmd.Stderr = stderr
|
||||
cmd.Dir = taskDir
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return "", fmt.Errorf("%v failed: %s. Err: %v", cmd.Args, stderr.String(), err)
|
||||
|
|
Loading…
Reference in a new issue