Skip to content
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

feat: add flake #15

Merged
merged 2 commits into from
Nov 11, 2022
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
25 changes: 24 additions & 1 deletion doc/content/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<version>` and add the correct `sha256` and `vendorSha256` for the version:
```nix
{ config, pkgs, fetchFromGitHub, ... }:

let
xc = pkgs.buildGoModule rec {
pname = "xc";
version = "<version>";
subPackages = ["cmd/xc"];
src = pkgs.fetchFromGitHub {
owner = "joerdav";
repo = "xc";
rev = version;
sha256 = "";
};
vendorSha256 = "";
};
in
{
environment.systemPackages = [ xc ];
}
```
{{% /details %}}
{{% details "Scoop" %}}
Expand Down
41 changes: 41 additions & 0 deletions flake.lock

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

30 changes: 30 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 ];
};
};
}
);
}
13 changes: 13 additions & 0 deletions update-nix.sh
Original file line number Diff line number Diff line change
@@ -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 <nixpkgs> { }; callPackage ./xc.nix { }'
SRC_SHA256="$(nix-build -E 'with import <nixpkgs> { }; 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 <nixpkgs> { }; 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

14 changes: 14 additions & 0 deletions xc.nix
Original file line number Diff line number Diff line change
@@ -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=";
}
14 changes: 14 additions & 0 deletions xc.nix.tmpl
Original file line number Diff line number Diff line change
@@ -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;
}