Skip to content

Commit d523080

Browse files
committed
[nix] Add detsys installer
1 parent ac07204 commit d523080

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package featureflag
2+
3+
var UseDetSysInstaller = cicdOnly("DETSYS_INSTALLER")

internal/boxcli/featureflag/feature.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ func enable(name string) *feature {
4343
return features[name]
4444
}
4545

46+
func cicdOnly(name string) *feature {
47+
if os.Getenv("CI") != "" || os.Getenv("CIRCLECI") != "" || os.Getenv("GITHUB_ACTIONS") != "" {
48+
enable(name)
49+
}
50+
return disable(name)
51+
}
52+
4653
var logMap = map[string]bool{}
4754

4855
func (f *feature) Enabled() bool {

internal/boxcli/setup.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ func setupCmd() *cobra.Command {
2929
},
3030
}
3131

32-
installNixCommand.Flags().Bool(nixDaemonFlag, false, "Install Nix in multi-user mode.")
32+
installNixCommand.Flags().Bool(
33+
nixDaemonFlag,
34+
false,
35+
"Install Nix in multi-user mode. This flag is not supported if you are using DetSys installer",
36+
)
3337
setupCommand.AddCommand(installNixCommand)
3438
return setupCommand
3539
}
3640

3741
func runInstallNixCmd(cmd *cobra.Command) error {
3842
if nix.BinaryInstalled() {
43+
// TODO: If existing installation is not detsys, but new installation is detsys can we detect
44+
// that and replace it?
3945
ux.Finfof(
4046
cmd.ErrOrStderr(),
4147
"Nix is already installed. If this is incorrect "+

internal/nix/install.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/mattn/go-isatty"
1717
"github.com/pkg/errors"
1818

19+
"go.jetpack.io/devbox/internal/boxcli/featureflag"
1920
"go.jetpack.io/devbox/internal/boxcli/usererr"
2021
"go.jetpack.io/devbox/internal/build"
2122
"go.jetpack.io/devbox/internal/cmdutil"
@@ -39,11 +40,20 @@ func Install(writer io.Writer, daemon *bool) error {
3940
defer r.Close()
4041

4142
installScript := "curl -L https://releases.nixos.org/nix/nix-2.18.1/install | sh -s"
42-
if daemon != nil {
43-
if *daemon {
44-
installScript += " -- --daemon"
45-
} else {
46-
installScript += " -- --no-daemon"
43+
if featureflag.UseDetSysInstaller.Enabled() {
44+
// Should we pin version? Or just trust detsys
45+
installScript = "curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install"
46+
if isLinuxWithoutSystemd() {
47+
installScript += " linux --init none"
48+
}
49+
installScript += " --no-confirm"
50+
} else {
51+
if daemon != nil {
52+
if *daemon {
53+
installScript += " -- --daemon"
54+
} else {
55+
installScript += " -- --no-daemon"
56+
}
4757
}
4858
}
4959

@@ -169,3 +179,14 @@ func EnsureNixInstalled(writer io.Writer, withDaemonFunc func() *bool) (err erro
169179
fmt.Fprintln(writer, "Nix installed successfully. Devbox is ready to use!")
170180
return nil
171181
}
182+
183+
func isLinuxWithoutSystemd() bool {
184+
if build.OS() != build.OSLinux {
185+
return false
186+
}
187+
// My best interpretation of https://github.com/DeterminateSystems/nix-installer/blob/66ad2759a3ecb6da345373e3c413c25303305e25/src/action/common/configure_init_service.rs#L108-L118
188+
if _, err := os.Stat("/run/systemd/system"); errors.Is(err, os.ErrNotExist) {
189+
return true
190+
}
191+
return !cmdutil.Exists("systemctl")
192+
}

0 commit comments

Comments
 (0)