-
Notifications
You must be signed in to change notification settings - Fork 356
Expand file tree
/
Copy pathnix_test.go
More file actions
116 lines (96 loc) · 3.74 KB
/
Copy pathnix_test.go
File metadata and controls
116 lines (96 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package nix
import (
"testing"
)
func TestIsUnfreeAllowed(t *testing.T) {
cases := map[string]bool{
"": false,
"0": false,
"false": false,
"1": true,
"true": true,
}
for value, want := range cases {
t.Run(value, func(t *testing.T) {
t.Setenv("NIXPKGS_ALLOW_UNFREE", value)
if got := IsUnfreeAllowed(); got != want {
t.Errorf("IsUnfreeAllowed() with NIXPKGS_ALLOW_UNFREE=%q = %v, want %v", value, got, want)
}
})
}
}
// TestUsePrintDevEnvImpure verifies the fix for
// https://github.com/jetify-com/devbox/issues/2196: print-dev-env must run
// with --impure whenever the user opts into unfree or insecure packages so
// those environment variables are honored.
func TestUsePrintDevEnvImpure(t *testing.T) {
cases := []struct {
name string
unfree string
insec string
want bool
}{
{name: "neither set", want: false},
{name: "unfree disabled", unfree: "0", want: false},
{name: "unfree allowed", unfree: "1", want: true},
{name: "insecure allowed", insec: "true", want: true},
{name: "both allowed", unfree: "1", insec: "1", want: true},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("NIXPKGS_ALLOW_UNFREE", tt.unfree)
t.Setenv("NIXPKGS_ALLOW_INSECURE", tt.insec)
if got := usePrintDevEnvImpure(); got != tt.want {
t.Errorf("usePrintDevEnvImpure() = %v, want %v", got, tt.want)
}
})
}
}
func TestParseInsecurePackagesFromExitError(t *testing.T) {
errorText := `
at /nix/store/xwl0am98klc8mz074jdyvpnyc6vwzlla-source/lib/customisation.nix:267:17:
266| in commonAttrs // {
267| drvPath = assert condition; drv.drvPath;
| ^
268| outPath = assert condition; drv.outPath;
… while evaluating the attribute 'handled'
at /nix/store/xwl0am98klc8mz074jdyvpnyc6vwzlla-source/pkgs/stdenv/generic/check-meta.nix:490:7:
489| # or, alternatively, just output a warning message.
490| handled =
| ^
491| (
(stack trace truncated; use '--show-trace' to show the full trace)
error: Package ‘python-2.7.18.7’ in /nix/store/xwl0am98klc8mz074jdyvpnyc6vwzlla-source/pkgs/development/interpreters/python/cpython/2.7/default.nix:335 is marked as insecure, refusing to evaluate.
Known issues:
- Python 2.7 has reached its end of life after 2020-01-01. See https://www.python.org/doc/sunset-python-2/.
You can install it anyway by allowing this package, using the
following methods:
a) To temporarily allow all insecure packages, you can use an environment
variable for a single invocation of the nix tools:
$ export NIXPKGS_ALLOW_INSECURE=1
Note: When using nix shell, nix build, nix develop, etc with a flake,
then pass --impure in order to allow use of environment variables.
b) for nixos-rebuild you can add ‘python-2.7.18.7’ to
nixpkgs.config.permittedInsecurePackages in the configuration.nix,
like so:
{
nixpkgs.config.permittedInsecurePackages = [
"python-2.7.18.7"
];
}
c) For nix-env, nix-build, nix-shell or any other Nix command you can add
‘python-2.7.18.7’ to permittedInsecurePackages in
~/.config/nixpkgs/config.nix, like so:
{
permittedInsecurePackages = [
"python-2.7.18.7"
];
`
packages := parseInsecurePackagesFromExitError(errorText)
if len(packages) != 1 {
t.Errorf("Expected 1 package, got %d", len(packages))
}
if packages[0] != "python-2.7.18.7" {
t.Errorf("Expected package 'python-2.7.18.7', got %s", packages[0])
}
}