10 # Mapping from GCS component architecture names to Nix archictecture names
17 # Mapping from GCS component operating systems to Nix operating systems
25 # Convert an archicecture + OS to a Nix platform
26 toNixPlatform = arch: os:
28 arch' = arches.${arch} or (throw "unsupported architecture '${arch}'");
29 os' = oses.${os} or (throw "unsupported OS '${os}'");
33 # All architectures that are supported by GCS
34 allArches = builtins.attrNames arches;
36 # A description of all available google-cloud-sdk components.
37 # It's a JSON file with a list of components, along with some metadata
38 snapshot = builtins.fromJSON (builtins.readFile snapshotPath);
40 # Generate a snapshot file for a single component. It has the same format as
41 # `snapshot`, but only contains a single component. These files are
42 # installed with google-cloud-sdk to let it know which components are
44 snapshotFromComponent =
51 components = [ component ];
52 inherit revision schema_version version;
55 # Generate a set of components from a JSON file describing these components
56 componentsFromSnapshot =
65 builtins.listToAttrs (
69 value = componentFromSnapshot self { inherit component revision schema_version version; };
75 # Generate a single component from its snapshot, along with a set of
76 # available dependencies to choose from.
77 componentFromSnapshot =
78 # Component derivations that can be used as dependencies
80 # This component's snapshot
87 baseUrl = builtins.dirOf schema_version.url;
88 # Architectures supported by this component. Defaults to all available
90 architectures = builtins.filter
91 (arch: builtins.elem arch (builtins.attrNames arches))
92 (lib.attrByPath [ "platform" "architectures" ] allArches component);
93 # Operating systems supported by this component
94 operating_systems = builtins.filter
95 (os: builtins.elem os (builtins.attrNames oses))
96 component.platform.operating_systems;
101 version = component.version.version_string;
103 if lib.hasAttrByPath [ "data" "source" ] component
104 then "${baseUrl}/${component.data.source}"
106 sha256 = lib.attrByPath [ "data" "checksum" ] "" component;
107 dependencies = builtins.map (dep: builtins.getAttr dep components) component.dependencies;
109 if component.platform == { }
110 then lib.platforms.all
113 (arch: builtins.map (os: toNixPlatform arch os) operating_systems)
115 snapshot = snapshotFromComponent attrs;
118 # Filter out dependencies not supported by current system
119 filterForSystem = builtins.filter (drv: builtins.elem system drv.meta.platforms);
121 # Make a google-cloud-sdk component
125 # Source tarball, if any
127 # Checksum for the source tarball, if there is a source
129 # Other components this one depends on
131 # Short text describing the component
133 # Platforms supported
134 , platforms ? lib.platforms.all
135 # The snapshot corresponding to this component
137 }: stdenv.mkDerivation {
138 inherit name version snapshot;
146 phases = [ "installPhase" "fixupPhase" ];
148 mkdir -p $out/google-cloud-sdk/.install
150 # If there is a source, unpack it
151 if [ ! -z "$src" ]; then
152 tar -xf $src -C $out/google-cloud-sdk/
154 # If the source has binaries, link them to `$out/bin`
155 if [ -d "$out/google-cloud-sdk/bin" ]; then
157 find $out/google-cloud-sdk/bin/ -type f -exec ln -s {} $out/bin/ \;
161 # Write the snapshot file to the `.install` folder
162 cp $snapshotPath $out/google-cloud-sdk/.install/${name}.snapshot.json
165 dependencies = filterForSystem dependencies;
167 passAsFile = [ "snapshot" ];
169 inherit description platforms;
173 componentsFromSnapshot snapshot