Monorepo for Tangled
tangled.org
1package nixery
2
3import (
4 "fmt"
5 "strings"
6)
7
8func nixConfStep() Step {
9 setupCmd := `mkdir -p /etc/nix
10echo 'extra-experimental-features = nix-command flakes' >> /etc/nix/nix.conf
11echo 'build-users-group = ' >> /etc/nix/nix.conf
12echo 'sandbox = false' >> /etc/nix/nix.conf
13printf '#!/bin/sh\nrm -rf /homeless-shelter\n' > /etc/nix/post-build-hook.sh
14chmod +x /etc/nix/post-build-hook.sh
15echo 'post-build-hook = /etc/nix/post-build-hook.sh' >> /etc/nix/nix.conf`
16 return Step{
17 command: setupCmd,
18 name: "Configure Nix",
19 }
20}
21
22// dependencyStep processes dependencies defined in the workflow.
23// For dependencies using a custom registry (i.e. not nixpkgs), it collects
24// all packages and adds a single 'nix profile add' step to the
25// beginning of the workflow's step list.
26func dependencyStep(deps map[string][]string) *Step {
27 var customPackages []string
28
29 for registry, packages := range deps {
30 if registry == "nixpkgs" {
31 continue
32 }
33
34 if len(packages) == 0 {
35 customPackages = append(customPackages, registry)
36 }
37 // collect packages from custom registries
38 for _, pkg := range packages {
39 customPackages = append(customPackages, fmt.Sprintf("'%s#%s'", registry, pkg))
40 }
41 }
42
43 if len(customPackages) > 0 {
44 installCmd := "nix --extra-experimental-features nix-command --extra-experimental-features flakes profile add"
45 cmd := fmt.Sprintf("%s %s", installCmd, strings.Join(customPackages, " "))
46 installStep := Step{
47 command: cmd,
48 name: "Install custom dependencies",
49 environment: map[string]string{
50 "NIX_NO_COLOR": "1",
51 "NIX_SHOW_DOWNLOAD_PROGRESS": "0",
52 },
53 }
54 return &installStep
55 }
56 return nil
57}