diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5aae912 --- /dev/null +++ b/flake.lock @@ -0,0 +1,95 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1754498491, + "narHash": "sha256-erbiH2agUTD0Z30xcVSFcDHzkRvkRXOQ3lb887bcVrs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c2ae88e026f9525daf89587f3cbee584b92b6134", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1754531935, + "narHash": "sha256-Y9qoYxg7waoMhiRhEmG+mDs6Jx2yk5eB7MlGDPMNs8E=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "41752cc1a38a8c993cf4e92ab8df640803554c7a", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "zig2nix": "zig2nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "zig2nix": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1754532129, + "narHash": "sha256-nScPs0Hzm71rXe6H6jVy9Gp+t7MEOQcm3gjAj/L0Qvg=", + "owner": "Cloudef", + "repo": "zig2nix", + "rev": "f656a4a84e2182fb0c99132b214d136ebc087388", + "type": "github" + }, + "original": { + "owner": "Cloudef", + "repo": "zig2nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..bf21e38 --- /dev/null +++ b/flake.nix @@ -0,0 +1,84 @@ +{ + description = "Zig project flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + zig2nix.url = "github:Cloudef/zig2nix"; + }; + + outputs = { + nixpkgs, + zig2nix, + ... + }: let + flake-utils = zig2nix.inputs.flake-utils; + in (flake-utils.lib.eachDefaultSystem (system: let + # Zig flake helper + # Check the flake.nix in zig2nix project for more options: + # + env = zig2nix.outputs.zig-env.${system} {zig = zig2nix.outputs.packages.${system}.zig-master;}; + pkgs = nixpkgs.legacyPackages.${system}; + in + with builtins; + with env.pkgs.lib; rec { + # Produces clean binaries meant to be ship'd outside of nix + # nix build .#foreign + packages.foreign = env.package { + src = cleanSource ./.; + + # Packages required for compiling + nativeBuildInputs = with pkgs; [dart-sass]; + + # Packages required for linking + buildInputs = with env.pkgs; []; + + # Smaller binaries and avoids shipping glibc. + zigPreferMusl = true; + }; + + # nix build . + packages.default = packages.foreign.override (attrs: { + # Prefer nix friendly settings. + zigPreferMusl = false; + + # Executables required for runtime + # These packages will be added to the PATH + zigWrapperBins = with env.pkgs; []; + + # Libraries required for runtime + # These packages will be added to the LD_LIBRARY_PATH + zigWrapperLibs = attrs.buildInputs or []; + }); + + # For bundling with nix bundle for running outside of nix + # example: https://github.com/ralismark/nix-appimage + # apps.bundle = { + # type = "app"; + # program = "${packages.foreign}/bin/master"; + # }; + + # nix run . + apps.default = env.app [] "zig build serve -- \"$@\""; + + # nix run .#build + apps.build = env.app [] "zig build \"$@\""; + + # nix run .#stylesheet + apps.test = env.app [] "zig build stylesheet -- \"$@\""; + + # nix run .#zig2nix + apps.zig2nix = env.app [] "zig2nix \"$@\""; + + # nix develop + devShells.default = env.mkShell { + # Packages required for compiling, linking and running + # Libraries added here will be automatically added to the LD_LIBRARY_PATH and PKG_CONFIG_PATH + nativeBuildInputs = + [] + ++ packages.default.nativeBuildInputs + ++ packages.default.buildInputs + ++ packages.default.zigWrapperBins + ++ packages.default.zigWrapperLibs; + }; + })); +}