Skip to content

Commit b553141

Browse files
feat: nix flake for export CLI tool
feat: nix flake for export CLI tool
2 parents d65bae3 + 8d6ddfc commit b553141

5 files changed

Lines changed: 200 additions & 0 deletions

File tree

.github/workflows/flake-check.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
on:
2+
pull_request:
3+
4+
jobs:
5+
flake-check:
6+
permissions:
7+
contents: read
8+
name: Check nix flakes
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
12+
- name: Check Nix flake inputs
13+
uses: DeterminateSystems/flake-checker-action@main
14+
with:
15+
check-outdated: false
16+
- uses: cachix/install-nix-action@4e002c8ec80594ecd40e759629461e26c8abed15 # version v31.9.0
17+
- name: Check flake
18+
run: |
19+
nix flake check
20+
21+
vendor-hash-check:
22+
permissions:
23+
contents: read
24+
name: Comparing vendor hash values
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
28+
- name: Check Nix flake inputs
29+
uses: DeterminateSystems/flake-checker-action@main
30+
with:
31+
check-outdated: false
32+
- uses: cachix/install-nix-action@4e002c8ec80594ecd40e759629461e26c8abed15 # version v31.9.0
33+
- name: Get vendor directory
34+
run: |
35+
nix develop . -c go mod vendor
36+
- id: calculated-hash
37+
name: Calculate vendor hash
38+
run: |
39+
hash=$(nix hash path vendor)
40+
echo "Calculated vendor hash: $hash"
41+
echo "HASH=$hash" >> "$GITHUB_OUTPUT"
42+
- id: current-hash
43+
name: Get the current vendor hash
44+
run: |
45+
hash=$(nix eval --file ./config.nix --raw --argstr lib '' 'exporter-cli.vendorHash' --raw)
46+
echo "Configured vendor hash: $hash"
47+
echo "HASH=$hash" >> "$GITHUB_OUTPUT"
48+
- name: Comparing hashes
49+
if: ${{ steps.calculated-hash.outputs.HASH != steps.current-hash.outputs.HASH }}
50+
run: |
51+
echo "::error file=config.nix,line=6,title=Invalid vendorHash::Update the vendor hash. Suggested value: ${{steps.calculated-hash.outputs.HASH}}"
52+
exit 1

cmd/exporter/docs/USERGUIDE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ The `xpcf` tool observes *Cloud Foundry* resources and exports them as managed C
77

88
# TODO Installation
99

10+
## Nix users
11+
12+
Nix users can easily execute the `xpcf` tool using the following command:
13+
14+
```bash
15+
nix run github:SAP/crossplane-provider-cloudfoundry/<version>#xpcf -- <flags>
16+
```
17+
18+
To get the *help* for version v0.3.4, execute
19+
20+
```bash
21+
nix run github:SAP/crossplane-provider-cloudfoundry/v0.3.4#xpcf -- --help
22+
```
1023

1124
# Quick Start
1225

config.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ lib }:
2+
{
3+
exporter-cli = {
4+
name = "xpcf";
5+
version = "0.0.1-alpha1";
6+
vendorHash = "sha256-HiWXSvLwRzt1/wMl2LQfwrBPoRpsl5E3TsN/1N0PGWs=";
7+
meta = {
8+
description = "xpcf is a CLI tool for exporting existing resources as Crossplane managed resources";
9+
homepage = "https://github.com/SAP/crossplane-provider-cloudfoundry";
10+
license = lib.licenses.asl20;
11+
};
12+
src = with lib; fileset.toSource {
13+
root = ./.;
14+
fileset = fileset.unions [
15+
(fileset.fromSource (sources.sourceFilesBySuffices ./. [".go"]))
16+
./go.mod
17+
./go.sum
18+
./flake.nix
19+
./flake.lock
20+
./config.nix
21+
];
22+
};
23+
};
24+
}

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
description = "Description for the project";
3+
4+
inputs = {
5+
flake-parts.url = "github:hercules-ci/flake-parts";
6+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
7+
};
8+
9+
outputs = inputs@{ flake-parts, ... }:
10+
flake-parts.lib.mkFlake { inherit inputs; } {
11+
imports = [
12+
];
13+
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
14+
perSystem = { config, self', inputs', pkgs, lib, system, ... }:
15+
let
16+
config = import ./config.nix { inherit lib; };
17+
in
18+
{
19+
packages = rec {
20+
exporter = pkgs.buildGoModule {
21+
inherit (config.exporter-cli) version;
22+
pname = config.exporter-cli.name;
23+
ldflags = ["-X main.ShortName=${config.exporter-cli.name}"];
24+
src = config.exporter-cli.src;
25+
subPackages = ["cmd/exporter"];
26+
vendorHash = config.exporter-cli.vendorHash;
27+
meta = config.exporter-cli.meta;
28+
};
29+
"${config.exporter-cli.name}" = pkgs.runCommand "${config.exporter-cli.name}" {} ''
30+
mkdir -p $out/bin
31+
cp ${exporter}/bin/exporter $out/bin/${config.exporter-cli.name}
32+
'';
33+
};
34+
devShells.default = pkgs.mkShell {
35+
packages = with pkgs; [go];
36+
};
37+
apps.exporter = {
38+
meta = config.exporter-cli.meta;
39+
type = "app";
40+
program = "${self'.packages.${config.exporter-cli.name}}/bin/${config.exporter-cli.name}";
41+
};
42+
checks = {
43+
exporter = pkgs.runCommand "exporter-help" {} ''
44+
${self'.packages.${config.exporter-cli.name}}/bin/${config.exporter-cli.name} --help > $out
45+
'';
46+
};
47+
};
48+
flake = {};
49+
};
50+
}

0 commit comments

Comments
 (0)