From ee4bac9dc1afdbf3eadaf9f5ed4f33117e510bfe Mon Sep 17 00:00:00 2001 From: Calum MacRae Date: Thu, 8 Apr 2021 21:44:36 +0100 Subject: [PATCH] tooling: Provide a Nix Flake --- .github/workflows/build-and-release.yaml | 20 ++++++-- .gitignore | 1 + CHANGELOG.md | 1 + README.md | 24 +++++++++- flake.lock | 27 +++++++++++ flake.nix | 60 ++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.github/workflows/build-and-release.yaml b/.github/workflows/build-and-release.yaml index 446c632..e1800bb 100644 --- a/.github/workflows/build-and-release.yaml +++ b/.github/workflows/build-and-release.yaml @@ -17,15 +17,23 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - - name: Fetch history - run: git fetch --prune --unshallow + with: + # Flakes don't work on shallow clones + fetch-depth: 0 - name: Configure Git run: | git config user.name "$GITHUB_ACTOR" git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + - name: Install Nix + uses: cachix/install-nix-action@v12 + with: + install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20210207_fd6eaa1/install + + - name: Enable Flakes + run: echo "experimental-features = nix-command flakes" | sudo tee -a /etc/nix/nix.conf + - name: Build id: build-bin run: | @@ -39,6 +47,10 @@ jobs: run: | echo "::set-output name=version::$(./bin/spacebar --version | cut -d- -f2)" + - name: Build with Nix + run: | + nix build + - name: Get the current tag name if: ${{ startsWith(github.ref, 'refs/tags/') }} run: | @@ -48,7 +60,7 @@ jobs: if: ${{ startsWith(github.ref, 'refs/tags/') }} run: | [[ "$RELEASE_VERSION" == ${{ steps.check-bin.outputs.version }} ]] - + - name: Create Release if: ${{ startsWith(github.ref, 'refs/tags/') }} id: create-release diff --git a/.gitignore b/.gitignore index a39af62..4239aff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /bin /archive /.idea +result diff --git a/CHANGELOG.md b/CHANGELOG.md index 645b491..b0d325f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Default to "Solid" style of Font Awesome 5 Free icon font - Option to display spaces for all displays, including: optional separator, secondary & tertiary space indicator colours in relation to display - Option to specify only drawing one bar on the main display or multiple bars, one for each display (this aligns with yabai's `external_bar` option) +- Provide a [Nix Flake](https://nixos.wiki/wiki/Flakes) ## [1.2.1](https://github.com/cmacrae/spacebar/releases/tag/v1.2.1) - 2020-11-18 diff --git a/README.md b/README.md index aea8a24..fc0c974 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,27 @@ brew services start spacebar ### Nix A package is generally available to Nix users on macOS in the various channels. +A [Flake](https://nixos.wiki/wiki/Flakes) is also available in this repository and can be used like so: +```nix +{ + inputs.darwin.url = "github:lnl7/nix-darwin"; + inputs.spacebar.url = "github:cmacrae/spacebar"; + + outputs = { self, darwin, spacebar }: { + darwinConfigurations.example = darwin.lib.darwinSystem { + modules = [ + { + nixpkgs.overlays = [ + spacebar.overlay + ]; + } + ]; + }; + }; +} +``` +Or try it out with `nix run github:cmacrae/spacebar`! + spacebar can be configured and managed in a declarative manner using the `services.spacebar` module in [nix-darwin](https://github.com/LnL7/nix-darwin) ### Accessibility Permissions @@ -178,7 +199,8 @@ brew upgrade spacebar brew services start spacebar ``` -If you're using the Nix package and keeping your channels up to date, package upgrades will roll in as you command. +If you're using the Nix package form the nixpkgs collection and keeping your channels up to date, package upgrades will roll in as you command. +If you're using the Nix Flake, you can update your `input.spacebar.url` to point to the latest release tag and update your lockfile. ## Requirements and Caveats Please read the below requirements carefully. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a0155db --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1616847335, + "narHash": "sha256-AQrNtJZRl9P78u+otHNXVxcQzu84vuTJLqynupp335g=", + "owner": "cmacrae", + "repo": "nixpkgs", + "rev": "7745d5338ad3c6cef295f40a732c6a739b1fcc7b", + "type": "github" + }, + "original": { + "owner": "cmacrae", + "ref": "fix_spacebar", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ce5507d --- /dev/null +++ b/flake.nix @@ -0,0 +1,60 @@ +{ + description = "A minimal status bar for macOS"; + + # TODO: Move to official nixpkgs once PR is merged + # https://github.com/NixOS/nixpkgs/pull/117780 + inputs.nixpkgs.url = "github:cmacrae/nixpkgs/fix_spacebar"; + + outputs = { self, nixpkgs }: + let + pkgs = import nixpkgs { + config = {}; + system = "x86_64-darwin"; + }; + + buildInputs = with pkgs.darwin.apple_sdk.frameworks; [ + Carbon + Cocoa + ScriptingBridge + SkyLight + ]; + + shellInputs = buildInputs ++ [ pkgs.asciidoctor ]; + in + { + packages.x86_64-darwin.spacebar = + pkgs.stdenv.mkDerivation rec { + pname = "spacebar"; + version = "1.3.0"; + src = self; + + inherit buildInputs; + + installPhase = '' + mkdir -p $out/bin + mkdir -p $out/share/man/man1/ + cp ./bin/spacebar $out/bin/spacebar + cp ./doc/spacebar.1 $out/share/man/man1/spacebar.1 + ''; + + meta = with pkgs.lib; { + description = "A minimal status bar for macOS"; + homepage = "https://github.com/cmacrae/spacebar"; + platforms = platforms.darwin; + maintainers = [ maintainers.cmacrae ]; + license = licenses.mit; + }; + }; + + overlay = final: prev: { + spacebar = self.packages.x86_64-darwin.spacebar; + }; + + defaultPackage.x86_64-darwin = self.packages.x86_64-darwin.spacebar; + + devShell.x86_64-darwin = pkgs.stdenv.mkDerivation { + name = "spacebar"; + buildInputs = shellInputs; + }; + }; +}