-
Notifications
You must be signed in to change notification settings - Fork 1
add nix flake to project #69
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f1cc2bf
add nix flake
15e10f9
add nix-build ci job to verify build and update the vendorHash in fla…
e9a2e21
update description in flake.nix
58e99db
do not update the vendorHash automatically
320b0e2
use tagged version of nix-installer-action & magic-nix-cache-action
3cb1f47
corrrect magic-nix-cache-action gh action tag
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| { | ||
| description = "infrahub-backup - Backup/restore and task management tools for Infrahub"; | ||
|
|
||
| inputs = { | ||
| nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | ||
| flake-utils.url = "github:numtide/flake-utils"; | ||
| }; | ||
|
|
||
| outputs = { self, nixpkgs, flake-utils }: | ||
| flake-utils.lib.eachDefaultSystem (system: | ||
| let | ||
| pkgs = nixpkgs.legacyPackages.${system}; | ||
|
|
||
| version = | ||
| if self ? shortRev then self.shortRev | ||
| else if self ? dirtyShortRev then self.dirtyShortRev | ||
| else "dev"; | ||
|
|
||
| # Shared build configuration for both binaries. | ||
| # The neo4j watchdog must be pre-built because both packages | ||
| # import src/internal/app which has //go:embed directives | ||
| # referencing the watchdog binaries. | ||
| commonAttrs = { | ||
| inherit version; | ||
| src = ./.; | ||
|
|
||
| vendorHash = "sha256-Vo/PzB5MVPhrVyZPyF1WUHJn1Kn/J6cjSlnDKzp+sTQ="; | ||
|
|
||
| # Don't run preBuild (watchdog compilation) in the go-modules | ||
| # derivation — it only needs to fetch/vendor dependencies. | ||
| overrideModAttrs = finalAttrs: prevAttrs: { | ||
| preBuild = ""; | ||
| }; | ||
|
|
||
| env.CGO_ENABLED = 0; | ||
|
|
||
| ldflags = [ | ||
| "-s" "-w" | ||
| "-X main.version=${version}" | ||
| ]; | ||
|
|
||
| preBuild = '' | ||
| # Build embedded neo4j watchdog binaries required by //go:embed | ||
| GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" \ | ||
| -o src/internal/app/embedded/neo4jwatchdog/neo4j_watchdog_linux_arm64 \ | ||
| ./tools/neo4jwatchdog | ||
| GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" \ | ||
| -o src/internal/app/embedded/neo4jwatchdog/neo4j_watchdog_linux_amd64 \ | ||
| ./tools/neo4jwatchdog | ||
| ''; | ||
|
|
||
| meta = with pkgs.lib; { | ||
| homepage = "https://github.com/opsmill/infrahub-backup"; | ||
| license = licenses.asl20; | ||
| maintainers = [ ]; | ||
| }; | ||
| }; | ||
| in | ||
| { | ||
| packages = { | ||
| infrahub-backup = pkgs.buildGoModule (commonAttrs // { | ||
| pname = "infrahub-backup"; | ||
| subPackages = [ "src/cmd/infrahub-backup" ]; | ||
| meta = commonAttrs.meta // { | ||
| description = "Backup and restore tool for Infrahub instances"; | ||
| mainProgram = "infrahub-backup"; | ||
| }; | ||
| }); | ||
|
|
||
| infrahub-taskmanager = pkgs.buildGoModule (commonAttrs // { | ||
| pname = "infrahub-taskmanager"; | ||
| subPackages = [ "src/cmd/infrahub-taskmanager" ]; | ||
| meta = commonAttrs.meta // { | ||
| description = "Task manager maintenance tool for Infrahub instances"; | ||
| mainProgram = "infrahub-taskmanager"; | ||
| }; | ||
| }); | ||
|
|
||
| default = pkgs.symlinkJoin { | ||
| name = "infrahub-ops-cli-${version}"; | ||
| paths = [ | ||
| self.packages.${system}.infrahub-backup | ||
| self.packages.${system}.infrahub-taskmanager | ||
| ]; | ||
| }; | ||
| }; | ||
|
|
||
| devShells.default = pkgs.mkShell { | ||
| buildInputs = with pkgs; [ | ||
| go | ||
| golangci-lint | ||
| gopls | ||
| ]; | ||
| }; | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| FLAKE_FILE="$(git rev-parse --show-toplevel)/flake.nix" | ||
| FAKE_HASH="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" | ||
|
|
||
| if [[ ! -f "$FLAKE_FILE" ]]; then | ||
| echo "error: flake.nix not found" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Extract current hash | ||
| current_hash=$(grep -oP 'vendorHash = "\K[^"]+' "$FLAKE_FILE") | ||
| echo "Current vendorHash: $current_hash" | ||
|
|
||
| # Temporarily set a fake hash | ||
| sed -i "s|vendorHash = \"${current_hash}\"|vendorHash = \"${FAKE_HASH}\"|" "$FLAKE_FILE" | ||
|
|
||
| # Build and capture the correct hash from the error output | ||
| # Use --no-link to avoid creating a result symlink inside the repo | ||
| echo "Computing correct vendorHash..." | ||
| correct_hash="" | ||
| if build_output=$(nix build --no-link 2>&1); then | ||
| echo "nix build succeeded — restoring original hash" | ||
| sed -i "s|vendorHash = \"${FAKE_HASH}\"|vendorHash = \"${current_hash}\"|" "$FLAKE_FILE" | ||
| exit 0 | ||
| else | ||
| correct_hash=$(echo "$build_output" | grep -oP 'got:\s+\K\S+' | head -1) | ||
| fi | ||
|
|
||
| if [[ -z "$correct_hash" ]]; then | ||
| echo "error: could not extract hash from nix build output" >&2 | ||
| echo "$build_output" >&2 | ||
| # Restore original hash | ||
| sed -i "s|vendorHash = \"${FAKE_HASH}\"|vendorHash = \"${current_hash}\"|" "$FLAKE_FILE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Update flake.nix with the correct hash | ||
| sed -i "s|vendorHash = \"${FAKE_HASH}\"|vendorHash = \"${correct_hash}\"|" "$FLAKE_FILE" | ||
|
|
||
| if [[ "$current_hash" == "$correct_hash" ]]; then | ||
| echo "vendorHash is already up to date: $correct_hash" | ||
| else | ||
| echo "Updated vendorHash: $current_hash -> $correct_hash" | ||
| fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.