Skip to content

Add flake; #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
export GOPATH=$PWD
export PATH=$GOPATH/bin:$PATH
strict_env

if has nix
then
use flake
fi
61 changes: 61 additions & 0 deletions .github/workflows/nix_adapt_hashes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Adapt Nix hashes
on:
workflow_dispatch: {} # 🚧 To-do: Remove this debug code.
pull_request:
branches:
- main
paths:
- ".github/workflows/nix_adapt_hashes.yaml"
- "go.mod"
- "go.sum"
push:
branches:
- main
paths:
- ".github/workflows/nix_adapt_hashes.yaml"
- "go.mod"
- "go.sum"

concurrency:
group: "${{ github.workflow }}/${{ github.ref }}"
cancel-in-progress: true

jobs:
check-tidy-go-mod:
name: Adapt the hashes in Nix-package-definitions.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# With push token that can trigger new PR jobs.
token: ${{ secrets.APP_AUTOSCALER_CI_TOKEN }}

- name: Install Nix
uses: cachix/install-nix-action@v26
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Install nix-update
run: nix profile install 'nixpkgs/nixos-unstable#nix-update'

- name: Run nix-update
shell: bash
run: |
#! /usr/bin/env bash
set -eu -o pipefail

nix-update 'app-autoscaler-cli-plugin' --flake

declare -i -r num_changed_files="$(git status --porcelain | wc --lines)"
if ((num_changed_files > 0))
then
echo 'Changes to some files were necessary!'
declare -r tidy_message='🤖🦾🛠️ Update Nix-package-hashes'
git add .
git commit --message="${tidy_message}"
git push
else
echo 'No hash-changes necessary!'
fi
echo '🏁'
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/out/
/pkg/
/bin/
# Editor-configurations
.idea

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would at least keep the .idea folder to ignore stuff from IntelliJ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isn't that an ideal use-case for a global ignore-pattern? See last item in the description of the official documentation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt most of the people has confgured that, I would really keep it : D

build

# ❄ Nix build-results
/result
/result-*

2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ This project is licensed to you under the Apache License, Version 2.0 (the "Lice
You may not use this project except in compliance with the License.

This project may include a number of subcomponents with separate copyright notices
and license terms. Your use of these subcomponents is subject to the terms and
and license terms. Your use of these subcomponents is subject to the terms and
conditions of the subcomponent's license, as noted in the LICENSE file.
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
description = ''
Flake for the cf-cli-plugin for app-autoscaler

For more on app-autoscaler, see: <https://github.com/cloudfoundry/app-autoscaler-release>
'';

inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-23.11;
};

outputs = { self, nixpkgs, flake-utils }:
let
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];

# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in flake-utils.lib.eachSystem supportedSystems (system: {
packages = {
app-autoscaler-cli-plugin = nixpkgsFor.${system}.buildGoModule rec {
pname = "app-autoscaler-cli-plugin";
version =
let
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
in "${builtins.substring 0 8 lastModifiedDate}-dev";
Comment on lines +25 to +28

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we get a new version if anything except the flake.nix / flake.lock changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. No, we don't: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake#flake-reference-attributes

What could be better? 🤔

  • Use current time: That's not reproducable. Identical code produced by identical builders will have two different versions.
  • Just use "dev"? That will work!
  • Stay as we are? At least compared to the option above, we will get a change in the version when the dependencies change (due to implication on vendorHash).

Copy link

@geigerj0 geigerj0 Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like none of the options are ideal as long as we don't have automation which takes care of the versioning.

Just use "dev"? That will work!

I vote for 👆

  • most simple solution
  • everbody can get the version information just by looking at the flake.nix file
  • not much going on in this repo anyhow so consuming always the latest dev-version is not hurting

src = ./.;

# 🔨🚧 To-do: Create automation to get that updated if necessary per pull-request.
# As long as this automation does not exist, it needs to be updated manually.
vendorHash = "sha256-NzEStcOv8ZQsHOA8abLABKy+ZE3/SiYbRD/ZVxo0CEk=";

doCheck = false;

meta = {
description = ''
App-AutoScaler plug-in provides the command line interface to manage
[App AutoScaler](<https://github.com/cloudfoundry/app-autoscaler-release>)
policies, retrieve metrics and scaling event history.
'';
homepage = "https://github.com/cloudfoundry/app-autoscaler-cli-plugin";
license = [nixpkgs.lib.licenses.apsl20];
};
};
};

devShells =
let
nixpkgs = nixpkgsFor.${system};
in {
default = nixpkgs.mkShell {
buildInputs = with nixpkgs; [
delve
go
gopls
];
};
};
});
}
6 changes: 3 additions & 3 deletions scripts/build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#! /usr/bin/env bash

set -e

ROOT_DIR=$(cd $(dirname $(dirname $0)) && pwd)
ROOT_DIR="$(cd $(dirname $(dirname $0)) && pwd)"

go build -o $ROOT_DIR/out/ascli cli
go build -o "${ROOT_DIR}/out/ascli/cli"