Skip to content

Commit dd07aa8

Browse files
authored
[allow unfree] add --impure and env-var to nix profile commands (#753)
## Summary Adding these back. They enable adding unfree packages and do not affect shell perf. ``` ❯ time devbox run -- echo "hi" Warning: local and global devbox.json have different nixpkgs commits. Will use the local version. This may lead to version mismatch and nix store bloat. Ensuring packages are installed. hi devbox run -- echo "hi" 0.41s user 0.16s system 67% cpu 0.847 total ``` context: #749 (comment) ## How was it tested? these now work ``` > devbox add slack > devbox add vscode ``` ~I will add a testscript unit test in a follow up PR~ Added testscript unit test
1 parent 6eb0abe commit dd07aa8

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

examples/testdata/unfree-packages/devbox.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

internal/nix/profile.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"bytes"
66
"fmt"
77
"io"
8+
"os"
89
"os/exec"
910
"strconv"
1011
"strings"
@@ -32,11 +33,6 @@ func ProfileListItems(writer io.Writer, profileDir string) ([]*NixProfileListIte
3233
// that we need to parse.
3334
cmd.Stderr = writer
3435

35-
//out, err := cmd.Output()
36-
//if err != nil {
37-
// return nil, errors.WithStack(err)
38-
//}
39-
4036
// The `out` output is of the form:
4137
// <index> <UnlockedReference> <LockedReference> <NixStorePath>
4238
//
@@ -230,8 +226,10 @@ func profileInstall(args *ProfileInstallArgs) error {
230226
cmd := exec.Command(
231227
"nix", "profile", "install",
232228
"--profile", args.ProfilePath,
229+
"--impure", // for NIXPKGS_ALLOW_UNFREE
233230
FlakeNixpkgs(args.NixpkgsCommit)+"#"+args.Package,
234231
)
232+
cmd.Env = AllowUnfreeEnv()
235233
cmd.Args = append(cmd.Args, ExperimentalFlags()...)
236234
if args.Priority != "" {
237235
cmd.Args = append(cmd.Args, "--priority", args.Priority)
@@ -300,8 +298,10 @@ func ProfileRemove(profilePath, nixpkgsCommit, pkg string) error {
300298
}
301299
cmd := exec.Command("nix", "profile", "remove",
302300
"--profile", profilePath,
301+
"--impure", // for NIXPKGS_ALLOW_UNFREE
303302
info.attributeKey,
304303
)
304+
cmd.Env = AllowUnfreeEnv()
305305
cmd.Args = append(cmd.Args, ExperimentalFlags()...)
306306
out, err := cmd.CombinedOutput()
307307
if bytes.Contains(out, []byte("does not match any packages")) {
@@ -310,3 +310,7 @@ func ProfileRemove(profilePath, nixpkgsCommit, pkg string) error {
310310

311311
return errors.Wrap(err, string(out))
312312
}
313+
314+
func AllowUnfreeEnv() []string {
315+
return append(os.Environ(), "NIXPKGS_ALLOW_UNFREE=1")
316+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test ensures that we can add and remove "unfree" nix packages
2+
3+
exec devbox init
4+
5+
# we could test with slack and/or vscode. Using slack since it is lighter.
6+
exec devbox add slack
7+
stderr 'Installing package: slack.'
8+
stderr 'is now installed.'
9+
10+
exec devbox rm slack
11+
stderr 'is now removed.'

0 commit comments

Comments
 (0)