Skip to content
Open
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
44 changes: 44 additions & 0 deletions .github/workflows/flake-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: nix flake check

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types: [opened, reopened, synchronize]
repository_dispatch:
types: [create-pull-request]

jobs:
flake-check:
runs-on: "ubuntu-latest"
steps:
- name: "Checking out repository..."
uses: actions/checkout@v4

- name: "Installing and configuring the nix package manager..."
uses: DeterminateSystems/nix-installer-action@main
with:
extra-conf: |
accept-flake-config = true

- name: "Setting up packages..."
run: |
nix profile install nixpkgs#nix-fast-build # parallel nix builder

- name: "Running `nix flake check`..."
run: nix-fast-build --skip-cached --no-nom
# NOTE: You can also limit the build only to the currentSystem
# run: nix-fast-build --skip-cached --no-nom --flake ".#checks.$(nix eval --raw --impure --expr builtins.currentSystem)"

- name: "Running `nix build ...`..."
run: nix-fast-build --skip-cached --no-nom --flake ".#packages"
# run: nix-fast-build --skip-cached --no-nom --flake ".#packages.$(nix eval --raw --impure --expr builtins.currentSystem)"

- name: "Running `nix develop...`..."
run: nix-fast-build --skip-cached --no-nom --flake ".#devShells"
# run: nix-fast-build --skip-cached --no-nom --flake ".#devShells.$(nix eval --raw --impure --expr builtins.currentSystem)"

- name: "Checking flake inputs for stale & insecure nixpkgs versions..."
uses: DeterminateSystems/flake-checker-action@main
29 changes: 29 additions & 0 deletions .github/workflows/update-flake-lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: update-flake-lock
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 0" # runs weekly on Sunday at 00:00

jobs:
update-flake-lock:
runs-on: ubuntu-latest
steps:
- name: "Checking out repository..."
uses: actions/checkout@v4

- name: "Installing and configuring the nix package manager..."
uses: DeterminateSystems/nix-installer-action@main
with:
extra-conf: |
accept-flake-config = true

- name: "Updating flake.lock..."
uses: DeterminateSystems/update-flake-lock@main
with:
pr-title: "Automated action - Update flake.lock"
pr-labels: |
dependencies
automated

# NOTE You can use a PAT to identify as a user, for CI purposes
# token: ${{ secrets.GH_TOKEN_FOR_UPDATES }}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@ You can view the [.env-sample](./.env-sample) as an example completed template.
- Messages are sourced from [praises.json](./cmd/bot/praises.json) and
[conspiracies.json](./cmd/bot/conspiracies.json). If your timings for message are too short for the duration the bot
runs, the messages will repeat.

### If using nix

*and if you are NOT using direnv*
At the project root directory, run:
`nix develop` and you'll have a development shell with the `go.mod` specified version of Golang (1.23.4 as of writing)
And if you're a chad, using direnv, you'll automatically load the environment when you `cd` into the project.

The flake also comes with **pre commit hooks** that will be run automatically when running `nix flake check`, it can also be extended to run arbitrary tests.
170 changes: 170 additions & 0 deletions flake.lock

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

71 changes: 71 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
devshell.url = "github:numtide/devshell";
git-hooks.url = "github:cachix/git-hooks.nix";
};

outputs = inputs:
inputs.flake-parts.lib.mkFlake {inherit inputs;} {
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];

imports = [
inputs.devshell.flakeModule
inputs.git-hooks.flakeModule
];

perSystem = {pkgs, ...}: {
pre-commit.settings.hooks = {
alejandra.enable = true;
deadnix.enable = true;
gofmt.enable = true;
};

devshells.default = let
version = "1.23.4";
go = pkgs.go.overrideAttrs {
name = "go-${version}";
inherit version;
src = pkgs.fetchFromGitHub {
owner = "golang";
repo = "go";
rev = "refs/tags/go${version}";
hash = "sha256-rRlln7DluZ0CCmjoHWrXwHxrIIHzd7X6AnEIbSu8Kio=";
};
};
in {
packages = with pkgs; [
deadnix
alejandra
go
];
env = [
{
name = "NIX_CONFIG";
value = "experimental-features = nix-command flakes";
}
];
commands = [
{
name = "fmt";
help = "format nix code (using alejandra)";
command = "nix fmt";
category = "nix";
}
{
name = "lint";
help = "lint go code";
command = "gofmt";
category = "golang";
}
];
};
};
};
}