Skip to content

Commit 200c6cf

Browse files
authored
[flakes] enable unfree packages (#670)
## Summary To enable unfree packages with flakes, we need to do both of: 1. set `NIXPKGS_ALLOW_UNFREE=1` 2. use `--impure` flag There is also an option to do: ``` nixpkgs { config { allowUnfree = true; } } ``` However, I have not done this because: 1. we'd still need `--impure` for `nix profile install` that doesn't use `flake.nix`. 2. I couldn't actually figure out how to set `config.allowUnfree` in our flake.nix since we are using the num-tides flakes-utils to enable the flake to work for all `system` values. ## How was it tested? in `examples/testdata/unfree-packages`, I can now do: ``` DEVBOX_FEATURE_FLAKES=1 DEVBOX_FEATURE_UNIFIED_ENV=1 DEVBOX_DEBUG=1 devbox shell ``` I was a little concerned that `--impure` would introduce a lot of other environment variables into the shell, but I think it is safe for the following reasons. 1. I tested with a specific env-var: ``` > export SAVIL=impure-test > env | grep SAVIL SAVIL=impure-test > DEVBOX_FEATURE_FLAKES=1 DEVBOX_FEATURE_UNIFIED_ENV=1 DEVBOX_DEBUG=1 devbox shell (devbox) > env | grep SAVIL ``` So, the `SAVIL` env-var was not included in the devbox shell. 2. I compared all the env-vars by doing `env > env_with_{property}.txt` for this branch and the `main` branch. From visual inspection, the order of env-vars was different but the number of lines were same. So, I sorted them alphabetically and then compared them: ``` ❯ cat env_with_main.txt | sort > env_with_main_sorted.txt (devbox) ❯ cat env_with_impure.txt | sort > env_with_impure_sorted.txt (devbox) ❯ diff env_with_main_sorted.txt env_with_impure_sorted.txt 77c77 < STARSHIP_SESSION_KEY=7757126821727611 --- > STARSHIP_SESSION_KEY=3237459778369717 92c92 < ZDOTDIR=/var/folders/zv/r3sx92_94gq86_rq3yn1ky2h0000gn/T/devbox3757196048 --- > ZDOTDIR=/var/folders/zv/r3sx92_94gq86_rq3yn1ky2h0000gn/T/devbox1045668199 ``` The differences here are session-specific, and I don't see a lot of other env-vars being introduced due to `--impure`.
1 parent 18f413c commit 200c6cf

File tree

7 files changed

+11
-10
lines changed

7 files changed

+11
-10
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"packages": [
3-
"go"
3+
"go_1_18"
44
],
55
"shell": {
66
"init_hook": null
77
},
88
"nixpkgs": {
9-
"commit": "af9e00071d0971eb292fd5abef334e66eda3cb69"
9+
"commit": "9e0eed654c705c7cafe192a8eba1610217f70544"
1010
}
11-
}
11+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"dev_packages": [
3-
"go"
3+
"go_1_18"
44
]
5-
}
5+
}

examples/testdata/unfree-packages/devbox.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"packages": [
3+
"slack",
34
"vscode"
45
],
56
"shell": {
@@ -9,6 +10,6 @@
910
}
1011
},
1112
"nixpkgs": {
12-
"commit": "52e3e80afff4b16ccb7c52e9f0f5220552f03d04"
13+
"commit": "9e0eed654c705c7cafe192a8eba1610217f70544"
1314
}
1415
}

internal/impl/devbox.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,6 @@ func (d *Devbox) computeNixEnv(setFullPath bool) (map[string]string, error) {
802802

803803
// These variables are only needed for shell, but we include them here in the computed env
804804
// for both shell and run in order to be as identical as possible.
805-
env["NIX_PKGS_ALLOW_UNFREE"] = "1" // Only for shell because we don't expect nix calls within run
806805
env["__ETC_PROFILE_NIX_SOURCED"] = "1" // Prevent user init file from loading nix profiles
807806
env["DEVBOX_SHELL_ENABLED"] = "1" // Used to determine whether we're inside a shell (e.g. to prevent shell inception)
808807

internal/impl/packages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (d *Devbox) addPackagesToProfile(mode installMode) error {
8787
"nix", "profile", "install",
8888
"--profile", profileDir,
8989
"--extra-experimental-features", "nix-command flakes",
90+
"--impure", // Needed to allow flags from environment to be used.
9091
nix.FlakeNixpkgs(d.cfg.Nixpkgs.Commit)+"#"+pkg,
9192
)
9293
cmd.Stdout = &nixPackageInstallWriter{d.writer}

internal/nix/nix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ func PrintDevEnv(nixShellFilePath, nixFlakesFilePath string) (*varsAndFuncs, err
154154
"--extra-experimental-features", "nix-command",
155155
"--extra-experimental-features", "ca-derivations",
156156
"--option", "experimental-features", "nix-command flakes",
157+
"--impure",
157158
"--json")
158159
debug.Log("Running print-dev-env cmd: %s\n", cmd)
160+
cmd.Env = DefaultEnv()
159161
out, err := cmd.Output()
160162
if err != nil {
161163
return nil, errors.WithStack(err)

testscripts/run/env.test.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ exec devbox run echo '$USER'
1414
stdout 'test-user'
1515

1616
# Fixed/hard-coded vars are set
17-
exec devbox run echo '$NIX_PKGS_ALLOW_UNFREE'
18-
stdout '1'
1917
exec devbox run echo '$__ETC_PROFILE_NIX_SOURCED'
2018
stdout '1'
2119

@@ -60,4 +58,4 @@ stdout 'devbox-json-override'
6058
"CONFIG_VAR3": "${PWD}",
6159
"NGINX_CONFDIR": "devbox-json-override"
6260
}
63-
}
61+
}

0 commit comments

Comments
 (0)