Skip to content

Commit 944ff28

Browse files
authored
[nixpkgs version] devbox init should add default nixpkgs commit (#259)
## Summary This PR updates `devbox init` to insert the default nixpkgs commit. ## How was it tested? feature flag OFF: ``` devbox/testdata/nodejs/nodejs-18/fake-dir on  savil/nixpkgs-version-init [!] at ☸️ jetpack-cloud (savil-srivastava-jetpack-io) ➜ devbox init devbox/testdata/nodejs/nodejs-18/fake-dir on  savil/nixpkgs-version-init [!?] at ☸️ jetpack-cloud (savil-srivastava-jetpack-io) ➜ cat devbox.json { "packages": [], "shell": { "init_hook": null }, "nixpkgs": {} }% ``` feature flag ON ``` devbox/testdata/nodejs/nodejs-18/fake-dir on  savil/nixpkgs-version-init [!] at ☸️ jetpack-cloud (savil-srivastava-jetpack-io) ➜ DEVBOX_FEATURE_NIXPKG_VERSION=1 devbox init devbox/testdata/nodejs/nodejs-18/fake-dir on  savil/nixpkgs-version-init [!?] at ☸️ jetpack-cloud (savil-srivastava-jetpack-io) ➜ cat devbox.json { "packages": [], "shell": { "init_hook": null }, "nixpkgs": { "commit": "af9e00071d0971eb292fd5abef334e66eda3cb69" } }% ```
1 parent 57c922e commit 944ff28

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

config.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ type Config struct {
4141
} `json:"shell,omitempty"`
4242

4343
// Nixpkgs specifies the repository to pull packages from
44-
Nixpkgs struct {
45-
Commit string `json:"commit,omitempty"`
46-
} `json:"nixpkgs,omitempty"`
44+
Nixpkgs NixpkgsConfig `json:"nixpkgs,omitempty"`
45+
}
46+
47+
type NixpkgsConfig struct {
48+
Commit string `json:"commit,omitempty"`
4749
}
4850

4951
// This contains a subset of fields from plansdk.Stage

config_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,7 @@ func TestNixpkgsValidation(t *testing.T) {
396396
assert := assert.New(t)
397397

398398
err := validateNixpkg(&Config{
399-
Nixpkgs: struct {
400-
Commit string `json:"commit,omitempty"`
401-
}{
399+
Nixpkgs: NixpkgsConfig{
402400
Commit: testCase.commit,
403401
},
404402
})

devbox.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ const (
4444
// exist.
4545
func InitConfig(dir string) (created bool, err error) {
4646
cfgPath := filepath.Join(dir, configFilename)
47-
return cuecfg.InitFile(cfgPath, &Config{})
47+
48+
config := &Config{}
49+
if featureflag.Get(featureflag.NixpkgVersion).Enabled() {
50+
config.Nixpkgs = NixpkgsConfig{
51+
Commit: plansdk.DefaultNixpkgsCommit,
52+
}
53+
}
54+
return cuecfg.InitFile(cfgPath, config)
4855
}
4956

5057
// Devbox provides an isolated development environment that contains a set of

planner/plansdk/plansdk.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,19 @@ type NixpkgsInfo struct {
213213
Sha256 string
214214
}
215215

216+
// Commit hash as of 2022-08-16
217+
// `git ls-remote https://github.com/nixos/nixpkgs nixos-unstable`
218+
const DefaultNixpkgsCommit = "af9e00071d0971eb292fd5abef334e66eda3cb69"
219+
216220
func GetNixpkgsInfo(commitHash string) (*NixpkgsInfo, error) {
217221

218222
// If the featureflag is OFF, then we fallback to the hardcoded commit
219223
// and ignore any value set in the devbox.json
220224
if !featureflag.Get(featureflag.NixpkgVersion).Enabled() {
221-
// Commit hash as of 2022-08-16
222-
// `git ls-remote https://github.com/nixos/nixpkgs nixos-unstable`
223-
//
224225
// sha256 from:
225226
// nix-prefetch-url --unpack https://github.com/nixos/nixpkgs/archive/<commit-hash>.tar.gz
226227
return &NixpkgsInfo{
227-
URL: "https://github.com/nixos/nixpkgs/archive/af9e00071d0971eb292fd5abef334e66eda3cb69.tar.gz",
228+
URL: fmt.Sprintf("https://github.com/nixos/nixpkgs/archive/%s.tar.gz", DefaultNixpkgsCommit),
228229
Sha256: "1mdwy0419m5i9ss6s5frbhgzgyccbwycxm5nal40c8486bai0hwy",
229230
}, nil
230231
}

0 commit comments

Comments
 (0)