diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.github/workflows/flakehub-tagged.yml b/.github/workflows/flakehub-tagged.yml new file mode 100644 index 0000000..7206132 --- /dev/null +++ b/.github/workflows/flakehub-tagged.yml @@ -0,0 +1,27 @@ +name: "Publish tags to FlakeHub" +on: + push: + tags: + - "v?[0-9]+.[0-9]+.[0-9]+*" + workflow_dispatch: + inputs: + tag: + description: "The existing tag to publish to FlakeHub" + type: "string" + required: true +jobs: + flakehub-publish: + runs-on: "ubuntu-latest" + permissions: + id-token: "write" + contents: "read" + steps: + - uses: "actions/checkout@v3" + with: + ref: "${{ (inputs.tag != null) && format('refs/tags/{0}', inputs.tag) || '' }}" + - uses: "DeterminateSystems/nix-installer-action@main" + - uses: "DeterminateSystems/flakehub-push@main" + with: + visibility: "public" + name: "blue-build/cli" + tag: "${{ inputs.tag }}" diff --git a/.gitignore b/.gitignore index f47bb99..f73b671 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /target .sccache/ .vscode/ +result* +.direnv/ cosign.key diff --git a/README.md b/README.md index 5d62bc8..a2ab87d 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,49 @@ This will install the binary on your system in `/usr/local/bin`. This is only a podman run --rm ghcr.io/blue-build/cli:latest-installer | bash ``` +### Nix Flake + +You can install this CLI through the Nix flake on [Flakehub](https://flakehub.com/) + +#### Non-nixos + +You can install BlueBuild to your global package environment on non-nixos systems by running + +```shell +# you can replace "*" with a specific tag +nix profile install https://flakehub.com/f/bluebuild/cli/*.tar.gz#bluebuild +``` + +#### NixOS + +If you are using a dedicated flake to manage your dependencies, you can add BlueBuild as a flake input throught the [fh](https://github.com/DeterminateSystems/fh) cli (that can be installed through nixpkgs) and add `bluebuild` to it. +```nix +{pkgs,inputs,...}: { + ... + environment.SystemPackages = [ + inputs.bluebuild.packages.${pkgs.system}.bluebuild # change bluebuild with the fh added input name + ]; + ... +} +``` + +If you are not using a dedicated nix flake, you can add the BlueBuild flake as a variable inside your `/etc/nixos/*.nix` configuration, though this requires you to run `nixos-rebuild` with the `--impure` variable, it is not advisable to do so. + +```nix +{pkgs,...}: +let + bluebuild = builtins.fetchTarball "https://flakehub.com/f/bluebuild/cli/*.tar.gz"; +in { + ... + environment.SystemPackages = [ + bluebuild.packages.${pkgs.system}.bluebuild + ]; + ... +} +``` + +You can also use `nix develop .#` in this repos directory to run a nix shell with development dependencies and some helful utilities for building BlueBuild! + ### Github Install Script ```bash diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..080bd20 --- /dev/null +++ b/flake.lock @@ -0,0 +1,95 @@ +{ + "nodes": { + "flake-schemas": { + "locked": { + "lastModified": 1697467827, + "narHash": "sha256-j8SR19V1SRysyJwpOBF4TLuAvAjF5t+gMiboN4gYQDU=", + "rev": "764932025c817d4e500a8d2a4d8c565563923d29", + "revCount": 29, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.2/018b3da8-4cc3-7fbb-8ff7-1588413c53e2/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A.tar.gz" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1708984720, + "narHash": "sha256-gJctErLbXx4QZBBbGp78PxtOOzsDaQ+yw1ylNQBuSUY=", + "rev": "13aff9b34cc32e59d35c62ac9356e4a41198a538", + "revCount": 588909, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.588909%2Brev-13aff9b34cc32e59d35c62ac9356e4a41198a538/018dec1e-579e-771e-9f64-eb8879874075/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz" + } + }, + "root": { + "inputs": { + "flake-schemas": "flake-schemas", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709086241, + "narHash": "sha256-3QHK5zu/5XOa+ghBeKzvt+/BLdEPjw/xDNLcpDfbkmg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "5d56056fb905ff550ee61b6ebb6674d494f57a9e", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f137118 --- /dev/null +++ b/flake.nix @@ -0,0 +1,77 @@ +{ + + description = "BlueBuild's command line program that builds Containerfiles and custom images"; + + + inputs = { + flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*.tar.gz"; + + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz"; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + + outputs = { self, flake-schemas, nixpkgs, rust-overlay }: + let + overlays = [ + rust-overlay.overlays.default + (final: prev: { + rustToolchain = (final.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override { extensions = [ "rust-src"]; }; + }) + ]; + + supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; + forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f rec { + pkgs = import nixpkgs { inherit overlays system; }; + lib = pkgs.lib; + }); + in { + schemas = flake-schemas.schemas; + + packages = forEachSupportedSystem ({ pkgs, lib }: rec { + default = bluebuild; + bluebuild = pkgs.rustPlatform.buildRustPackage { + pname = "bluebuild"; + version = "v0.8.1"; + + src = pkgs.lib.cleanSource ./.; + cargoLock.lockFile = ./Cargo.lock; + + meta = { + description = "BlueBuild's command line program that builds Containerfiles and custom images"; + homepage = "https://github.com/blue-build/cli"; + license = lib.licenses.apsl20; + }; + }; + }); + + devShells = forEachSupportedSystem ({ pkgs, ... }: { + default = pkgs.mkShell { + + packages = with pkgs; [ + rustToolchain + cargo-bloat + cargo-edit + cargo-outdated + cargo-watch + rust-analyzer + cargo + rustc + bacon + earthly + yq + jq + nixpkgs-fmt + ]; + + env = { + RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library"; + }; + }; + }); + }; +}