Show More
@@ -1,163 +1,160 b'' | |||||
1 | # Utility to generate the license information |
|
1 | # Utility to generate the license information | |
2 | # |
|
2 | # | |
3 | # Usage: |
|
3 | # Usage: | |
4 | # |
|
4 | # | |
5 | # nix-build -I ~/dev license.nix -A result |
|
5 | # nix-build -I ~/dev license.nix -A result | |
6 | # |
|
6 | # | |
7 | # Afterwards ./result will contain the license information as JSON files. |
|
7 | # Afterwards ./result will contain the license information as JSON files. | |
8 | # |
|
8 | # | |
9 | # |
|
9 | # | |
10 | # Overview |
|
10 | # Overview | |
11 | # |
|
11 | # | |
12 | # Uses two steps to get the relevant license information: |
|
12 | # Uses two steps to get the relevant license information: | |
13 | # |
|
13 | # | |
14 | # 1. Walk down the derivations based on "buildInputs" and |
|
14 | # 1. Walk down the derivations based on "buildInputs" and | |
15 | # "propagatedBuildInputs". This results in all dependencies based on the nix |
|
15 | # "propagatedBuildInputs". This results in all dependencies based on the nix | |
16 | # declartions. |
|
16 | # declartions. | |
17 | # |
|
17 | # | |
18 | # 2. Build Enterprise and query nix-store to get a list of runtime |
|
18 | # 2. Build Enterprise and query nix-store to get a list of runtime | |
19 | # dependencies. The results from step 1 are then limited to the ones which |
|
19 | # dependencies. The results from step 1 are then limited to the ones which | |
20 | # are in this list. |
|
20 | # are in this list. | |
21 | # |
|
21 | # | |
22 | # The result is then available in ./result/license.json. |
|
22 | # The result is then available in ./result/license.json. | |
23 | # |
|
23 | # | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | let |
|
26 | let | |
27 |
|
27 | |||
28 | nixpkgs = import <nixpkgs> {}; |
|
28 | nixpkgs = import <nixpkgs> {}; | |
29 |
|
29 | |||
30 | stdenv = nixpkgs.stdenv; |
|
30 | stdenv = nixpkgs.stdenv; | |
31 |
|
31 | |||
32 | # Enterprise as simple as possible, goal here is just to identify the runtime |
|
32 | # Enterprise as simple as possible, goal here is just to identify the runtime | |
33 | # dependencies. Ideally we could avoid building Enterprise at all and somehow |
|
33 | # dependencies. Ideally we could avoid building Enterprise at all and somehow | |
34 | # figure it out without calling into nix-store. |
|
34 | # figure it out without calling into nix-store. | |
35 | enterprise = import ./default.nix { |
|
35 | enterprise = import ./default.nix { | |
36 | doCheck = false; |
|
36 | doCheck = false; | |
37 | with_vcsserver = false; |
|
|||
38 | with_pyramid = false; |
|
|||
39 | cythonize = false; |
|
|||
40 | }; |
|
37 | }; | |
41 |
|
38 | |||
42 | # For a given derivation, return the list of all dependencies |
|
39 | # For a given derivation, return the list of all dependencies | |
43 | drvToDependencies = drv: nixpkgs.lib.flatten [ |
|
40 | drvToDependencies = drv: nixpkgs.lib.flatten [ | |
44 | drv.nativeBuildInputs or [] |
|
41 | drv.nativeBuildInputs or [] | |
45 | drv.propagatedNativeBuildInputs or [] |
|
42 | drv.propagatedNativeBuildInputs or [] | |
46 | ]; |
|
43 | ]; | |
47 |
|
44 | |||
48 | # Transform the given derivation into the meta information which we need in |
|
45 | # Transform the given derivation into the meta information which we need in | |
49 | # the resulting JSON files. |
|
46 | # the resulting JSON files. | |
50 | drvToMeta = drv: { |
|
47 | drvToMeta = drv: { | |
51 | name = drv.name or "UNNAMED"; |
|
48 | name = drv.name or "UNNAMED"; | |
52 | license = if drv ? meta.license then drv.meta.license else "UNKNOWN"; |
|
49 | license = if drv ? meta.license then drv.meta.license else "UNKNOWN"; | |
53 | }; |
|
50 | }; | |
54 |
|
51 | |||
55 | # Walk the tree of buildInputs and propagatedBuildInputs and return it as a |
|
52 | # Walk the tree of buildInputs and propagatedBuildInputs and return it as a | |
56 | # flat list. Duplicates are avoided. |
|
53 | # flat list. Duplicates are avoided. | |
57 | listDrvDependencies = drv: let |
|
54 | listDrvDependencies = drv: let | |
58 | addElement = element: seen: |
|
55 | addElement = element: seen: | |
59 | if (builtins.elem element seen) |
|
56 | if (builtins.elem element seen) | |
60 | then seen |
|
57 | then seen | |
61 | else let |
|
58 | else let | |
62 | newSeen = seen ++ [ element ]; |
|
59 | newSeen = seen ++ [ element ]; | |
63 | newDeps = drvToDependencies element; |
|
60 | newDeps = drvToDependencies element; | |
64 | in nixpkgs.lib.fold addElement newSeen newDeps; |
|
61 | in nixpkgs.lib.fold addElement newSeen newDeps; | |
65 | initialElements = drvToDependencies drv; |
|
62 | initialElements = drvToDependencies drv; | |
66 | in nixpkgs.lib.fold addElement [] initialElements; |
|
63 | in nixpkgs.lib.fold addElement [] initialElements; | |
67 |
|
64 | |||
68 | # Reads in a file with store paths and returns a list of derivation names. |
|
65 | # Reads in a file with store paths and returns a list of derivation names. | |
69 | # |
|
66 | # | |
70 | # Reads the file, splits the lines, then removes the prefix, so that we |
|
67 | # Reads the file, splits the lines, then removes the prefix, so that we | |
71 | # end up with a list of derivation names in the end. |
|
68 | # end up with a list of derivation names in the end. | |
72 | storePathsToDrvNames = srcPath: let |
|
69 | storePathsToDrvNames = srcPath: let | |
73 | rawStorePaths = nixpkgs.lib.removeSuffix "\n" ( |
|
70 | rawStorePaths = nixpkgs.lib.removeSuffix "\n" ( | |
74 | builtins.readFile srcPath); |
|
71 | builtins.readFile srcPath); | |
75 | storePaths = nixpkgs.lib.splitString "\n" rawStorePaths; |
|
72 | storePaths = nixpkgs.lib.splitString "\n" rawStorePaths; | |
76 | # TODO: johbo: Would be nice to use some sort of utility here to convert |
|
73 | # TODO: johbo: Would be nice to use some sort of utility here to convert | |
77 | # the path to a derivation name. |
|
74 | # the path to a derivation name. | |
78 | storePathPrefix = ( |
|
75 | storePathPrefix = ( | |
79 | builtins.stringLength "/nix/store/zwy7aavnif9ayw30rya1k6xiacafzzl6-"); |
|
76 | builtins.stringLength "/nix/store/zwy7aavnif9ayw30rya1k6xiacafzzl6-"); | |
80 | storePathToName = path: |
|
77 | storePathToName = path: | |
81 | builtins.substring storePathPrefix (builtins.stringLength path) path; |
|
78 | builtins.substring storePathPrefix (builtins.stringLength path) path; | |
82 | in (map storePathToName storePaths); |
|
79 | in (map storePathToName storePaths); | |
83 |
|
80 | |||
84 | in rec { |
|
81 | in rec { | |
85 |
|
82 | |||
86 | # Build Enterprise and call nix-store to retrieve the runtime |
|
83 | # Build Enterprise and call nix-store to retrieve the runtime | |
87 | # dependencies. The result is available in the nix store. |
|
84 | # dependencies. The result is available in the nix store. | |
88 | runtimeDependencies = stdenv.mkDerivation { |
|
85 | runtimeDependencies = stdenv.mkDerivation { | |
89 | name = "runtime-dependencies"; |
|
86 | name = "runtime-dependencies"; | |
90 | buildInputs = [ |
|
87 | buildInputs = [ | |
91 | # Needed to query the store |
|
88 | # Needed to query the store | |
92 | nixpkgs.nix |
|
89 | nixpkgs.nix | |
93 | ]; |
|
90 | ]; | |
94 | unpackPhase = '' |
|
91 | unpackPhase = '' | |
95 | echo "Nothing to unpack" |
|
92 | echo "Nothing to unpack" | |
96 | ''; |
|
93 | ''; | |
97 | buildPhase = '' |
|
94 | buildPhase = '' | |
98 | # Get a list of runtime dependencies |
|
95 | # Get a list of runtime dependencies | |
99 | nix-store -q --references ${enterprise} > nix-store-references |
|
96 | nix-store -q --references ${enterprise} > nix-store-references | |
100 | ''; |
|
97 | ''; | |
101 | installPhase = '' |
|
98 | installPhase = '' | |
102 | mkdir -p $out |
|
99 | mkdir -p $out | |
103 | cp -v nix-store-references $out/ |
|
100 | cp -v nix-store-references $out/ | |
104 | ''; |
|
101 | ''; | |
105 | }; |
|
102 | }; | |
106 |
|
103 | |||
107 | # Produce the license overview files. |
|
104 | # Produce the license overview files. | |
108 | result = let |
|
105 | result = let | |
109 |
|
106 | |||
110 | # Dependencies according to the nix-store |
|
107 | # Dependencies according to the nix-store | |
111 | runtimeDependencyNames = ( |
|
108 | runtimeDependencyNames = ( | |
112 | storePathsToDrvNames "${runtimeDependencies}/nix-store-references"); |
|
109 | storePathsToDrvNames "${runtimeDependencies}/nix-store-references"); | |
113 |
|
110 | |||
114 | # Dependencies based on buildInputs and propagatedBuildInputs |
|
111 | # Dependencies based on buildInputs and propagatedBuildInputs | |
115 | enterpriseAllDependencies = listDrvDependencies enterprise; |
|
112 | enterpriseAllDependencies = listDrvDependencies enterprise; | |
116 | enterpriseRuntimeDependencies = let |
|
113 | enterpriseRuntimeDependencies = let | |
117 | elemName = element: element.name or "UNNAMED"; |
|
114 | elemName = element: element.name or "UNNAMED"; | |
118 | isRuntime = element: builtins.elem (elemName element) runtimeDependencyNames; |
|
115 | isRuntime = element: builtins.elem (elemName element) runtimeDependencyNames; | |
119 | in builtins.filter isRuntime enterpriseAllDependencies; |
|
116 | in builtins.filter isRuntime enterpriseAllDependencies; | |
120 |
|
117 | |||
121 | # Extract relevant meta information |
|
118 | # Extract relevant meta information | |
122 | enterpriseAllLicenses = map drvToMeta enterpriseAllDependencies; |
|
119 | enterpriseAllLicenses = map drvToMeta enterpriseAllDependencies; | |
123 | enterpriseRuntimeLicenses = map drvToMeta enterpriseRuntimeDependencies; |
|
120 | enterpriseRuntimeLicenses = map drvToMeta enterpriseRuntimeDependencies; | |
124 |
|
121 | |||
125 | in stdenv.mkDerivation { |
|
122 | in stdenv.mkDerivation { | |
126 |
|
123 | |||
127 | name = "licenses"; |
|
124 | name = "licenses"; | |
128 |
|
125 | |||
129 | buildInputs = []; |
|
126 | buildInputs = []; | |
130 |
|
127 | |||
131 | unpackPhase = '' |
|
128 | unpackPhase = '' | |
132 | echo "Nothing to unpack" |
|
129 | echo "Nothing to unpack" | |
133 | ''; |
|
130 | ''; | |
134 |
|
131 | |||
135 | buildPhase = '' |
|
132 | buildPhase = '' | |
136 | mkdir build |
|
133 | mkdir build | |
137 |
|
134 | |||
138 | # Copy list of runtime dependencies for the Python processor |
|
135 | # Copy list of runtime dependencies for the Python processor | |
139 | cp "${runtimeDependencies}/nix-store-references" ./build/nix-store-references |
|
136 | cp "${runtimeDependencies}/nix-store-references" ./build/nix-store-references | |
140 |
|
137 | |||
141 | # All licenses which we found by walking buildInputs and |
|
138 | # All licenses which we found by walking buildInputs and | |
142 | # propagatedBuildInputs |
|
139 | # propagatedBuildInputs | |
143 | cat > build/all-licenses.json <<EOF |
|
140 | cat > build/all-licenses.json <<EOF | |
144 | ${builtins.toJSON enterpriseAllLicenses} |
|
141 | ${builtins.toJSON enterpriseAllLicenses} | |
145 | EOF |
|
142 | EOF | |
146 |
|
143 | |||
147 | # License information for our runtime dependencies only. Basically all |
|
144 | # License information for our runtime dependencies only. Basically all | |
148 | # licenses limited to the items which where also reported by nix-store as |
|
145 | # licenses limited to the items which where also reported by nix-store as | |
149 | # a dependency. |
|
146 | # a dependency. | |
150 | cat > build/licenses.json <<EOF |
|
147 | cat > build/licenses.json <<EOF | |
151 | ${builtins.toJSON enterpriseRuntimeLicenses} |
|
148 | ${builtins.toJSON enterpriseRuntimeLicenses} | |
152 | EOF |
|
149 | EOF | |
153 | ''; |
|
150 | ''; | |
154 |
|
151 | |||
155 | installPhase = '' |
|
152 | installPhase = '' | |
156 | mkdir -p $out |
|
153 | mkdir -p $out | |
157 |
|
154 | |||
158 | # Store it all, that helps when things go wrong |
|
155 | # Store it all, that helps when things go wrong | |
159 | cp -rv ./build/* $out |
|
156 | cp -rv ./build/* $out | |
160 | ''; |
|
157 | ''; | |
161 | }; |
|
158 | }; | |
162 |
|
159 | |||
163 | } |
|
160 | } |
General Comments 0
You need to be logged in to leave comments.
Login now