-
Notifications
You must be signed in to change notification settings - Fork 356
Expand file tree
/
Copy patheval.go
More file actions
68 lines (61 loc) · 1.81 KB
/
Copy patheval.go
File metadata and controls
68 lines (61 loc) · 1.81 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
package nix
import (
"context"
"encoding/json"
"os"
"strconv"
)
func EvalPackageName(path string) (string, error) {
cmd := Command("eval", "--raw", path+".name")
out, err := cmd.Output(context.TODO())
if err != nil {
return "", err
}
return string(out), nil
}
// PackageIsInsecure is a fun little nix eval that maybe works.
func PackageIsInsecure(path string) bool {
cmd := Command("eval", path+".meta.insecure")
out, err := cmd.Output(context.TODO())
if err != nil {
// We can't know for sure, but probably not.
return false
}
var insecure bool
if err := json.Unmarshal(out, &insecure); err != nil {
// We can't know for sure, but probably not.
return false
}
return insecure
}
func PackageKnownVulnerabilities(path string) []string {
cmd := Command("eval", path+".meta.knownVulnerabilities")
out, err := cmd.Output(context.TODO())
if err != nil {
// We can't know for sure, but probably not.
return nil
}
var vulnerabilities []string
if err := json.Unmarshal(out, &vulnerabilities); err != nil {
// We can't know for sure, but probably not.
return nil
}
return vulnerabilities
}
// Eval is raw nix eval. Needs to be parsed. Useful for stuff like
// nix eval --raw nixpkgs/9ef09e06806e79e32e30d17aee6879d69c011037#fuse3
// to determine if a package if a package can be installed in system.
func Eval(path string) ([]byte, error) {
cmd := Command("eval", "--raw", path)
return cmd.CombinedOutput(context.TODO())
}
func IsInsecureAllowed() bool {
allowed, _ := strconv.ParseBool(os.Getenv("NIXPKGS_ALLOW_INSECURE"))
return allowed
}
// IsUnfreeAllowed reports whether the user has opted into unfree packages by
// setting the NIXPKGS_ALLOW_UNFREE environment variable to a truthy value.
func IsUnfreeAllowed() bool {
allowed, _ := strconv.ParseBool(os.Getenv("NIXPKGS_ALLOW_UNFREE"))
return allowed
}