Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #19 from kachick/nix-flake-run
Browse files Browse the repository at this point in the history
Make it useable in `nix run`
  • Loading branch information
kachick committed Jul 24, 2023
2 parents cf48bdb + 0a77ec9 commit 1d1f989
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 16 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ jobs:
- run: nix develop --command echo 'This step should be done before any other "nix develop" steps because of measuring Nix build time'
- run: nix develop --command task versions
- run: nix develop --command task
- run: nix run . -- --version
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,14 @@
},
"[go]": {
"editor.defaultFormatter": "golang.go"
},
"nix.enableLanguageServer": true,
"nix.serverPath": "nil",
"nix.serverSettings": {
"nil": {
"formatting": {
"command": ["nixpkgs-fmt"]
}
}
}
}
12 changes: 2 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ task: [lint] go vet
PASS
ok nix-headbump 0.313s

> find dist
dist
dist/metadata.json
dist/config.yaml
dist/nix-headbump_linux_amd64_v1
dist/nix-headbump_linux_amd64_v1/nix-headbump
dist/artifacts.json

> ./dist/nix-headbump_linux_amd64_v1/nix-headbump --version
nix-headbump 0.1.1-next (906924b) # 2023-06-19T09:33:14Z
> ./dist/nix-headbump --version
nix-headbump dev (rev) # unknown
```
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ When I want to bump it, I always visit the nixpkgs repository and copy and paste

## Installation

`go install` is also okay, or use [prebuilt binaries](https://github.com/kachick/nix-headbump/releases)
[Prebuilt binaries](https://github.com/kachick/nix-headbump/releases)

```console
> curl -L https://github.com/kachick/nix-headbump/releases/latest/download/nix-headbump_Linux_x86_64.tar.gz | tar xvz -C ./ nix-headbump
> ./nix-headbump --version
nix-headbump 0.2.0 (70f68fa) # 2023-06-22T09:58:05Z
```

In [Nix](https://nixos.org/), you can skip installation steps

```console
> nix run github:kachick/nix-headbump -- --version
nix-headbump dev (rev) # unknown
> nix run github:kachick/nix-headbump/v0.2.3 -- detect --current
(Will work with specific versions since v0.2.3)
```

## Usage

Providing two subcommands. I'm using `detect` in CI and `bump` in local.
Expand Down
5 changes: 4 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ tasks:
install:
cmds:
- go install -ldflags "-X main.commit=$(git rev-parse HEAD) -X main.date=$(date --iso-8601)"
build:preview:
cmds:
- goreleaser build --snapshot --single-target --clean --output dist/nix-headbump
build:
cmds:
- goreleaser build --snapshot --single-target --clean
- go build -o ./dist/nix-headbump ./cmd/nix-headbump
test:
cmds:
- go test
Expand Down
11 changes: 9 additions & 2 deletions cmd/nix-headbump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import (
)

var (
// Used in goreleaser
version = "dev"
commit = "none"
date = "unknown"

revision = "rev"
)

func main() {
Expand Down Expand Up @@ -40,10 +43,14 @@ $ nix-headbump -version`
bumpCmd.Usage()
}

if len(commit) >= 7 {
revision = commit[:7]
}
version := fmt.Sprintf("%s\n", "nix-headbump"+" "+version+" "+"("+revision+") # "+date)

flag.Parse()
if *versionFlag {
revision := commit[:7]
fmt.Printf("%s\n", "nix-headbump"+" "+version+" "+"("+revision+") # "+date)
fmt.Println(version)
return
}

Expand Down
32 changes: 30 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
rec {
devShells.default = with pkgs;
mkShell {
buildInputs = [
Expand All @@ -24,5 +24,33 @@
go-tools
];
};
});

packages.nix-headbump = pkgs.stdenv.mkDerivation
{
name = "nix-headbump";
src = self;
buildInputs = with pkgs; [
go_1_20
go-task
];
buildPhase = ''
# https://github.com/NixOS/nix/issues/670#issuecomment-1211700127
export HOME=$(pwd)
task build
'';
installPhase = ''
mkdir -p $out/bin
install -t $out/bin dist/nix-headbump
'';
};

packages.default = packages.nix-headbump;

# `nix run`
apps.default = {
type = "app";
program = "${packages.nix-headbump}/bin/nix-headbump";
};
}
);
}

0 comments on commit 1d1f989

Please sign in to comment.