Skip to content

Commit

Permalink
chore(nix): build and develop with nix (#172)
Browse files Browse the repository at this point in the history
* chore(nix): build and develop with nix

* docs: adds nix flake instructions
  • Loading branch information
cristianoliveira authored Jul 9, 2024
1 parent ba001bc commit b2b9e6b
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 15 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/on-push-nixbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: nix build

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

env:
CARGO_TERM_COLOR: always

jobs:
e2e-with-nix:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- run: nix flake check
- run: nix build .#nightly --verbose
31 changes: 28 additions & 3 deletions .watch.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@

## Funzzy events file
# more details see: https://github.com/cristianoliveira/funzzy
#
# list here all the events and the commands that it should execute

- name: run my unit tests @quick
run: 'make test'
- name: build @quick
run: 'make build'
run_on_init: true
change: '**/*.go'

- name: run lint @quick
run: 'make lint'
run_on_init: true
change: '**/*.go'

- name: build nix
run:
- nix flake check
- nix build .#nightly --verbose
run_on_init: true
change:
- '**/*.go'
- '**/*.nix'

- name: run my unit tests @quick
run: 'make test'
change: '**/*.go'

- name: run tests with tag test-only @quick
Expand All @@ -19,3 +33,14 @@
- name: run integration tests
run: 'make integration'
change: 'tests/*'

- name: after all stage file
run:
- git add {{relative_filepath}}
- git add -p # start a quick review and stage the rest
change:
- 'README.md'
- 'Makefile'
- '**/*.nix'
- '**/*.go'
- 'tests/*'
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ setup-golant:

deps:
@go list -f '{{join .Imports "\n"}}{{"\n"}}{{join .TestImports "\n"}}' ./... | sort | uniq | grep -v ergo | go get

nixbuild:
@nix build .#nightly
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ I use Unix-based systems on a daily basis, so I am not able to test each build a
### Nix

```bash
nix profile install 'github:cristianoliveira/nixpkgs#funzzy'
nix profile install 'github:cristianoliveira/ergo#nightly'
// or
nix profile install 'github:cristianoliveira/nixpkgs#ergoProxy'
```

### Go
Expand Down
60 changes: 60 additions & 0 deletions flake.lock

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

36 changes: 36 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
description = "New flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, utils }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
# Inject the namespace copkgs into the package set
overlays = [
(_: prev: {
copkgs = {
ergoProxy = pkgs.callPackage ./nix/package.nix { inherit pkgs; };
nightly = pkgs.callPackage ./nix/package-nightly.nix {
inherit pkgs;
};
};
}
)
];
};
in {
devShells.default = import ./nix/dev-env.nix {
inherit pkgs;
};

packages = {
default = pkgs.copkgs.ergoProxy;
ergoProxy = pkgs.copkgs.ergoProxy;
nightly = pkgs.copkgs.nightly;
};
});
}
11 changes: 11 additions & 0 deletions nix/dev-env.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
# buildInputs is for dependencies you'd need "at run time",
# were you to to use nix-build not nix-shell and build whatever you were working on
buildInputs = [
pkgs.go
pkgs.copkgs.ergoProxy
];

shell = pkgs.zsh;
}
29 changes: 29 additions & 0 deletions nix/package-nightly.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ pkgs, ... }:
let
_version = "v0.4.1-nighlty";
in
pkgs.buildGoModule {
# name of our derivation
name = "ergo-proxy";
version = "${_version}";
doCheck = true;

# sources that will be used for our derivation.
src = ../.;

modSha256 = "sha256-yXWM59zoZkQPpOouJoUd5KWfpdCBw47wknb+hYy6rh0=";

vendorHash = "sha256-yXWM59zoZkQPpOouJoUd5KWfpdCBw47wknb+hYy6rh0=";

ldflags = [
"-s" "-w"
"-X main.VERSION=${_version}"
];

meta = with pkgs.lib; {
description = "Ergo: The reverse proxy agent for local domain management";
homepage = "https://github.com/cristianoliveira/ergo";
license = licenses.mit;
maintainers = with maintainers; [ cristianoliveira ];
};
}
33 changes: 33 additions & 0 deletions nix/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{ pkgs, ... }:
let
_version = "v0.4.1";
in
pkgs.buildGoModule {
# name of our derivation
name = "ergo-proxy";
version = "${_version}";

# sources that will be used for our derivation.
src = pkgs.fetchFromGitHub {
owner = "cristianoliveira";
repo = "ergo";
rev = _version;
sha256 = "sha256-C3lJWuRyGuvo33kvj3ktWKYuUZ2yJ8pDBNX7YZn6wNM=";
};

modSha256 = "0fagi529m1gf5jrqdlg9vxxq4yz9k9q8h92ch0gahp43kxfbgr4q";

vendorHash = "sha256-yXWM59zoZkQPpOouJoUd5KWfpdCBw47wknb+hYy6rh0=";

ldflags = [
"-s" "-w"
"-X main.VERSION=${_version}"
];

meta = with pkgs.lib; {
description = "Ergo: The reverse proxy agent for local domain management";
homepage = "https://github.com/cristianoliveira/ergo";
license = licenses.mit;
maintainers = with maintainers; [ cristianoliveira ];
};
}
11 changes: 0 additions & 11 deletions shell.nix

This file was deleted.

0 comments on commit b2b9e6b

Please sign in to comment.