diff --git a/README.md b/README.md index 5b12369..dc8900c 100644 --- a/README.md +++ b/README.md @@ -92,3 +92,9 @@ echo Adding git tag with version v0.0.${VERSION} git tag v0.0.${VERSION} git push origin v0.0.${VERSION} ``` + +### update-nix +Updates nix flake. +``` +sh ./update-nix.sh +``` diff --git a/doc/content/getting-started.md b/doc/content/getting-started.md index 80d65ff..0cdde67 100644 --- a/doc/content/getting-started.md +++ b/doc/content/getting-started.md @@ -28,8 +28,31 @@ TODO ``` {{% /details %}} {{% details "Nix" %}} +There is a nix flake that can be used: ```sh -TODO +nix develop github:joerdav/xc +``` +Or to create your own `xc.nix`, replace `` and add the correct `sha256` and `vendorSha256` for the version: +```nix +{ config, pkgs, fetchFromGitHub, ... }: + +let + xc = pkgs.buildGoModule rec { + pname = "xc"; + version = ""; + subPackages = ["cmd/xc"]; + src = pkgs.fetchFromGitHub { + owner = "joerdav"; + repo = "xc"; + rev = version; + sha256 = ""; + }; + vendorSha256 = ""; + }; +in +{ + environment.systemPackages = [ xc ]; +} ``` {{% /details %}} {{% details "Scoop" %}} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..cd0ce96 --- /dev/null +++ b/flake.lock @@ -0,0 +1,41 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1668086072, + "narHash": "sha256-msFoXI5ThCmhTTqgl27hpCXWhaeqxphBaleJAgD8JYM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "72d8853228c9758820c39b8659415b6d89279493", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9f49268 --- /dev/null +++ b/flake.nix @@ -0,0 +1,30 @@ +{ + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + flake-utils.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + system = system; + }; + xc = pkgs.callPackage ./xc.nix {}; + in + { + defaultPackage = xc; + packages = { + xc = xc; + }; + devShells = { + default = pkgs.mkShell { + packages = [ xc ]; + }; + xc = pkgs.mkShell { + packages = [ xc ]; + }; + }; + } + ); +} diff --git a/update-nix.sh b/update-nix.sh new file mode 100755 index 0000000..a0a774c --- /dev/null +++ b/update-nix.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +sed -e "s/__VERSION__/$(git describe --tags --abbrev=0)/g" xc.nix.tmpl > xc.nix + +# We first try to build and it fails with hash mismatch, and we use it to populate sha256. +nix-build -E 'with import { }; callPackage ./xc.nix { }' +SRC_SHA256="$(nix-build -E 'with import { }; callPackage ./xc.nix { }' 2>&1 | grep -oE 'got:\s+sha256-\S+' | cut -d "-" -f 2)" +sed -i -e "s|sha256 = lib.fakeSha256;|sha256 = \"$SRC_SHA256\";|g" xc.nix + +# We try again to build and it fails with hash mismatch, and we use it to populate vendorSha256. +VENDOR_SHA256="$(nix-build -E 'with import { }; callPackage ./xc.nix { }' 2>&1 | grep -oE 'got:\s+sha256-\S+' | cut -d "-" -f 2)" +sed -i -e "s|vendorSha256 = lib.fakeSha256;|vendorSha256 = \"$VENDOR_SHA256\";|g" xc.nix + diff --git a/xc.nix b/xc.nix new file mode 100644 index 0000000..468fad5 --- /dev/null +++ b/xc.nix @@ -0,0 +1,14 @@ +{ config, lib, pkgs, fetchFromGitHub, ... }: + +pkgs.buildGoModule rec { + pname = "xc"; + version = "v0.0.110"; + subPackages = ["cmd/xc"]; + src = pkgs.fetchFromGitHub { + owner = "joerdav"; + repo = "xc"; + rev = version; + sha256 = "Yn+9FPYPwx1BfDf45uaNZ5fLEIu6LgN6ihw4eDAT9mY="; + }; + vendorSha256 = "14dtguu787VR8/sYA+9WaS6xr/dB6ZcUjOzDEkFDpH4="; +} diff --git a/xc.nix.tmpl b/xc.nix.tmpl new file mode 100644 index 0000000..7744333 --- /dev/null +++ b/xc.nix.tmpl @@ -0,0 +1,14 @@ +{ config, lib, pkgs, fetchFromGitHub, ... }: + +pkgs.buildGoModule rec { + pname = "xc"; + version = "__VERSION__"; + subPackages = ["cmd/xc"]; + src = pkgs.fetchFromGitHub { + owner = "joerdav"; + repo = "xc"; + rev = version; + sha256 = lib.fakeSha256; + }; + vendorSha256 = lib.fakeSha256; +}