-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2a793f9
Showing
29 changed files
with
2,195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: automation | ||
|
||
on: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
automation: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Nix | ||
uses: cachix/install-nix-action@v24 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-unstable | ||
- run: | | ||
nix run .#update-versions > versions.json | ||
nix run .#update-templates | ||
nix run .#test | ||
nix run .#readme > README.md | ||
- uses: test-room-7/[email protected] | ||
with: | ||
file-path: | | ||
versions.json | ||
templates/** | ||
README.md | ||
commit-msg: Automatic update | ||
github-token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: pr | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
automation: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Nix | ||
uses: cachix/install-nix-action@v24 | ||
with: | ||
nix_path: nixpkgs=channel:nixos-unstable | ||
- run: | | ||
nix run .#update-templates | ||
nix run .#test | ||
nix run .#readme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This file is for zig-specific build artifacts. | ||
# If you have OS-specific or editor-specific files to ignore, | ||
# such as *.swp or .DS_Store, put those in your global | ||
# ~/.gitignore and put this in your ~/.gitconfig: | ||
# | ||
# [core] | ||
# excludesfile = ~/.gitignore | ||
# | ||
# Cheers! | ||
# -andrewrk | ||
|
||
zig-cache/ | ||
zig-out/ | ||
/release/ | ||
/debug/ | ||
/build/ | ||
/build-*/ | ||
/docgen_tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (Expat) | ||
|
||
Copyright (c) 2024 Vetoniemi Jari Juhani | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
# zig2nix flake | ||
|
||
Flake for packaging, building and running Zig projects. | ||
|
||
https://ziglang.org/ | ||
|
||
--- | ||
|
||
[](https://opensource.org/licenses/MIT) | ||
|
||
* Zig master: `0.12.0-dev.2139+e025ad7b4 @ 2024-01-10` | ||
* Zig default: `0.11.0 @ 2023-08-04` | ||
|
||
## Zig project template | ||
|
||
```bash | ||
nix flake init -t github:Cloudef/zig2nix | ||
nix run . | ||
# for more options check the flake.nix file | ||
``` | ||
|
||
### With master version of Zig | ||
|
||
```bash | ||
nix flake init -t github:Cloudef/zig2nix#master | ||
nix run . | ||
# for more options check the flake.nix file | ||
``` | ||
|
||
## Running zig compiler directly | ||
|
||
```bash | ||
nix run github:Cloudef/zig2nix -- version | ||
``` | ||
|
||
## Shell for building and running a Zig project | ||
|
||
```bash | ||
nix develop github:Cloudef/zig2nix | ||
``` | ||
|
||
## Crude documentation | ||
|
||
Below is auto-generated dump of important outputs in this flake. | ||
|
||
```nix | ||
#! Structures. | ||
#: Helper function for building and running Zig projects. | ||
zig-env = { | ||
# Overrideable nixpkgs. | ||
pkgs ? _pkgs, | ||
# Zig version to use. Normally there is no need to change this. | ||
zig ? zigv.default, | ||
# Additional runtime deps to inject into the helpers. | ||
customRuntimeDeps ? [], | ||
# Additional runtime libs to inject to the helpers. | ||
# Gets included in LD_LIBRARY_PATH and DYLD_LIBRARY_PATH. | ||
customRuntimeLibs ? [], | ||
# Custom prelude in the flake app helper. | ||
customAppHook ? "", | ||
# Custom prelude in the flake shell helper. | ||
customDevShellHook ? "", | ||
# Enable Wayland support. | ||
enableWayland ? false, | ||
# Enable X11 support. | ||
enableX11 ? false, | ||
}: {}; | ||
#! --- Outputs of zig-env {} function. | ||
#! access: (zig-env {}).thing | ||
#! Inherit given pkgs and zig version | ||
inherit pkgs zig; | ||
#: Flake app helper (Without zig-env and root dir restriction). | ||
app-bare-no-root = deps: script: { | ||
type = "app"; | ||
program = toString (pkgs.writeShellApplication { | ||
name = "app"; | ||
runtimeInputs = [] ++ deps; | ||
text = '' | ||
# shellcheck disable=SC2059 | ||
error() { printf -- "error: $1" "''${@:1}" 1>&2; exit 1; } | ||
${script} | ||
''; | ||
}; | ||
#! Flake app helper (Without zig-env). | ||
app-bare = deps: script: app-bare-no-root deps | ||
#! Flake app helper (without root dir restriction). | ||
app-no-root = deps: script: app-bare-no-root (deps ++ _deps) | ||
#! Flake app helper. | ||
app = deps: script: app-bare (deps ++ _deps) | ||
#: Creates dev shell. | ||
shell = pkgs.mkShell { | ||
buildInputs = _deps; | ||
shellHook = _extraShell; | ||
}; | ||
#! Packages zig project. | ||
#! NOTE: If your project has build.zig.zon you must first generate build.zig.zon.nix using zon2nix. | ||
#! It is recommended to commit the build.zig.zon.nix to your repo. | ||
#! <https://github.com/NixOS/nixpkgs/blob/master/doc/hooks/zig.section.md> | ||
package = attrs: let | ||
#! --- Architecture dependent flake outputs. | ||
#! access: `zig2nix.outputs.thing.${system}` | ||
#! Helper function for building and running Zig projects. | ||
inherit zig-env; | ||
#! Versioned Zig packages. | ||
packages.zig = zigv; | ||
#! zon2json: Converts zon files to json | ||
packages.zon2json = zon2json; | ||
#! zon2nix: Converts build.zig.zon files to nix | ||
packages.zon2nix = zon2nix; | ||
#! Default zig package. | ||
#! Latest released zig. | ||
packages.default = zigv.default; | ||
#! Run zon2json | ||
apps.zon2json = app-no-root [zon2json] ''zon2json "$@"''; | ||
#! Run zon2nix | ||
apps.zon2nix = app-no-root [zon2nix] ''zon2nix "$@"''; | ||
#! Run a version of a Zig compiler inside a `zig-env`. | ||
#! nix run#zig."zig-version" | ||
#! example: nix run#zig.master | ||
apps.zig = mapAttrs (k: v: (zig-env {zig = v;}).app-no-root [] ''zig "$@"'') zigv; | ||
#! Run a version of a Zig compiler inside a `zig-env` (With Wayland support). | ||
#! nix run#zig-wayland."zig-version" | ||
#! example: nix run#zig-wayland.master | ||
apps.zig-wayland = mapAttrs (k: v: (zig-env {zig = v; enableWayland = true;}).app-no-root [] ''zig "$@"'') zigv; | ||
#! Run a version of a Zig compiler inside a `zig-env` (With X11 support). | ||
#! nix run#zig-x11."zig-version" | ||
#! example: nix run#zig-x11.master | ||
apps.zig-x11 = mapAttrs (k: v: (zig-env {zig = v; enableX11 = true;}).app-no-root [] ''zig "$@"'') zigv; | ||
#! Run a latest released version of a Zig compiler inside a `zig-env`. | ||
#! nix run | ||
apps.default = apps.zig.default; | ||
#! Develop shell for building and running Zig projects. | ||
#! nix develop#zig."zig-version" | ||
#! example: nix develop#zig.master | ||
devShells.zig = mapAttrs (k: v: (zig-env {zig = v;}).shell) zigv; | ||
#! Develop shell for building and running Zig projects. (With Wayland support) | ||
#! nix develop#zig-wayland."zig-version" | ||
#! example: nix develop#zig-wayland.master | ||
devShells.zig-wayland = mapAttrs (k: v: (zig-env {zig = v; enableWayland = true;}).shell) zigv; | ||
#! Develop shell for building and running Zig projects. (With X11 support) | ||
#! nix develop#zig-x11."zig-version" | ||
#! example: nix develop#zig-x11.master | ||
devShells.zig-x11 = mapAttrs (k: v: (zig-env {zig = v; enableX11 = true;}).shell) zigv; | ||
#! Develop shell for building and running Zig projects. | ||
#! Uses latest released version of Zig. | ||
#! nix develop | ||
devShells.default = devShells.zig.default; | ||
#! Develop shell for building and running Zig projects (with Wayland support). | ||
#! Uses latest released version of Zig. | ||
#! nix develop | ||
devShells.wayland = devShells.zig-wayland.default; | ||
#! Develop shell for building and running Zig projects (with X11 support). | ||
#! Uses latest released version of Zig. | ||
#! nix develop | ||
devShells.x11 = devShells.zig-x11.default; | ||
#! --- Generic flake outputs. | ||
#! access: `zig2nix.outputs.thing` | ||
#: Overlay for overriding Zig with specific version. | ||
overlays.zig = mapAttrs (k: v: (final: prev: { | ||
zig = v; | ||
zon2json = outputs.packages.zon2json; | ||
zon2nix = outputs.packages.zon2nix; | ||
}; | ||
#: mitchellh/zig-overlay compatible overlay. | ||
overlays.zig-overlay = final: prev: { | ||
zigpkgs = outputs.packages.${prev.system}.zig; | ||
}; | ||
#! Default overlay | ||
overlays.default = overlays.zig.default; | ||
#: Default project template | ||
#: nix flake init -t templates | ||
templates.default = rec { | ||
path = ./templates/default; | ||
description = "Default Zig project template"; | ||
welcomeText = '' | ||
# ${description} | ||
- Zig: https://ziglang.org/ | ||
## Build & Run | ||
--- | ||
nix run . | ||
--- | ||
See flake.nix for more options. | ||
''; | ||
}; | ||
#: Master project template | ||
#: nix flake init -t templates | ||
templates.master = rec { | ||
path = ./templates/master; | ||
description = "Master Zig project template"; | ||
welcomeText = '' | ||
# ${description} | ||
- Zig: https://ziglang.org/ | ||
## Build & Run | ||
--- | ||
nix run . | ||
--- | ||
See flake.nix for more options. | ||
''; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/#!/ { | ||
gsub(/^[ \t]+/, "", $0) | ||
print($0); | ||
P = 1; | ||
next; | ||
} | ||
|
||
P == 1 { | ||
gsub(/^[ \t]+/, "", $0) | ||
print($0); | ||
if (length($0) > 0) { | ||
print(""); | ||
} | ||
P = 0; | ||
} | ||
|
||
/#:/ { | ||
PP = 1; | ||
} | ||
|
||
PP == 1 && /^[ \t]*}.*[:;]/ { | ||
gsub(/^[ \t]+/, "", $0); | ||
if (substr($0, 0, 2) == "}:") { | ||
print("}: {};\n"); | ||
} else { | ||
print("};\n"); | ||
} | ||
PP = 0 | ||
INDENT -= (INDENT > 0); | ||
} | ||
|
||
PP == 1 { | ||
gsub(/^[ \t]+/, "", $0); | ||
if (INDENT) { | ||
print(" ", $0); | ||
} else { | ||
print($0); | ||
} | ||
} | ||
|
||
PP == 1 && /{/ { INDENT += 1; } | ||
INDENT > 0 && /}/ { INDENT -= 1; } |
Oops, something went wrong.