From 469de64005c329518eca68328d6cc08ac8d87d7d Mon Sep 17 00:00:00 2001 From: robin Date: Fri, 26 Jun 2026 15:42:43 +0200 Subject: [PATCH] nix: rewrite flake --- flake.lock | 65 ++-------------- flake.nix | 201 ++++-------------------------------------------- nix/deps.nix | 84 ++++++++++++++++++++ nix/package.nix | 34 ++++++++ nix/shell.nix | 14 ++++ 5 files changed, 152 insertions(+), 246 deletions(-) create mode 100644 nix/deps.nix create mode 100644 nix/package.nix create mode 100644 nix/shell.nix diff --git a/flake.lock b/flake.lock index 3903442..6367799 100644 --- a/flake.lock +++ b/flake.lock @@ -1,79 +1,24 @@ { "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": 1779694939, - "narHash": "sha256-Ly4j75O8ICaSQx3uxPnwk2x7PMF0XQvn5r0c3yBA7FI=", + "lastModified": 1782467914, + "narHash": "sha256-pGvFkM8N0xEkIIXDe5YYfbEAvHrk4IxBrjB/x8OomhE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "f9d8b65950353691ab56561e7c73d2e1063d810b", + "rev": "e73de5be04e0eff4190a1432b946d469c794e7b4", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixpkgs-unstable", + "ref": "nixos-unstable", "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" - ] - }, - "locked": { - "lastModified": 1779682339, - "narHash": "sha256-mJ8Hc5CXfN2XSNBdLH96ZcjPsxhoMXSVXnzhA+T6anY=", - "owner": "Cloudef", - "repo": "zig2nix", - "rev": "ca301e15709429905caa1f6c3b5f37745187e936", - "type": "github" - }, - "original": { - "owner": "Cloudef", - "repo": "zig2nix", - "type": "github" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index 2770d13..ac25d6c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,194 +1,23 @@ { - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + description = "maivi"; - zig2nix = { - url = "github:Cloudef/zig2nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; }; outputs = - { self, zig2nix, ... }@inputs: + { self, nixpkgs }: let - inherit (zig2nix.inputs) flake-utils; + lib = nixpkgs.lib; + forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (s: f nixpkgs.legacyPackages.${s}); 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} { }; - - inherit (env) pkgs; - inherit (pkgs) lib; - in - { - # Produces clean binaries meant to be ship'd outside of nix - # nix build .#foreign - packages.foreign = self.packages.${system}.default.override (attrs: { - # Packages required for compiling - nativeBuildInputs = [ ]; - - # Packages required for linking - buildInputs = [ pkgs.pkg-config ]; - - # Smaller binaries and avoids shipping glibc. - zigPreferMusl = true; - - # Executables required for runtime - # These packages will be added to the PATH - zigWrapperBins = [ ]; - - # Libraries required for runtime - # These packages will be added to the LD_LIBRARY_PATH - zigWrapperLibs = attrs.buildInputs or [ ]; - }); - - # nix build . - packages.default = env.package { - src = lib.cleanSource ./.; - - postPatch = '' - tar --create --file=src/static.tar --directory=static . - ''; - - # Prefer nix friendly settings. - zigPreferMusl = false; - - # Executables required for runtime - # These packages will be added to the PATH - zigWrapperBins = [ ]; - - # Libraries required for runtime - # These packages will be added to the LD_LIBRARY_PATH - zigWrapperLibs = [ ]; - }; - - packages.derivation = pkgs.stdenv.mkDerivation (finalAttrs: { - pname = "maivi"; - version = "0.0.0"; - - src = ./.; - httpz = pkgs.fetchFromGitHub { - owner = "karlseguin"; - repo = "http.zig"; - rev = "9ef2ffe8d611ff2e1081e5cf39cb4632c145c5b9"; - hash = "sha256-3NK2HJbnHaeNEp1Gp/fqnT8ZPRa77HoJOUuIcQEo9EY="; - }; - logz = pkgs.fetchFromGitHub { - owner = "karlseguin"; - repo = "log.zig"; - rev = "b4a0b6b38d8fad1b94649046a967a700df5ce576"; - hash = "sha256-DiqN6Qy96pY6QFeuR/mMlKHDJrzziTdlYlq94qjnLgs="; - }; - metrics = pkgs.fetchFromGitHub { - owner = "karlseguin"; - repo = "metrics.zig"; - rev = "603954879849c331a26529b88254770089acac8b"; - hash = "sha256-G/VDCnFCA0S5K7XdhVlnlKz7YRAohWrNC9KgyydrGNY="; - }; - websocket = pkgs.fetchFromGitHub { - owner = "karlseguin"; - repo = "websocket.zig"; - rev = "4deaaef2b4475a63f19c5e2f43e38fd55464b118"; - hash = "sha256-lEZNQ+vJR29E6yovJhTsByJK3XZMSqsgF0PjgyFsIjY="; - }; - - nativeBuildInputs = [ pkgs.zig ]; - - postPatch = '' - tar --create --file=src/static.tar --directory=static . - - cp -r ${finalAttrs.httpz} ./httpz - cp -r ${finalAttrs.logz} ./logz - chmod -R u+w ./httpz ./logz - - substituteInPlace build.zig.zon \ - --replace-fail \ - '.url = "git+https://github.com/karlseguin/http.zig?ref=master#9ef2ffe8d611ff2e1081e5cf39cb4632c145c5b9",' \ - '.path = "./httpz",' \ - --replace-fail \ - '.url = "git+https://github.com/karlseguin/log.zig?ref=master#b4a0b6b38d8fad1b94649046a967a700df5ce576",' \ - '.path = "./logz",' \ - --replace-fail \ - '.hash = "httpz-0.0.0-PNVzrIowBwAFr_kqBN1W4KBMC2Ofutasj2ZfNAIcfTzF",' "" \ - --replace-fail \ - '.hash = "logz-0.0.0-O9YWXraFAgBQxWV4eh_4wp9axpoLhrzTIpYws4oxMLYh",' "" - - ln -s ${finalAttrs.metrics} ./httpz/metrics - ln -s ${finalAttrs.websocket} ./httpz/websocket - - substituteInPlace httpz/build.zig.zon \ - --replace-fail \ - '.url = "https://github.com/karlseguin/metrics.zig/archive/603954879849c331a26529b88254770089acac8b.tar.gz",' \ - '.path = "./metrics",' \ - --replace-fail \ - '.url = "https://github.com/karlseguin/websocket.zig/archive/4deaaef2b4475a63f19c5e2f43e38fd55464b118.tar.gz",' \ - '.path = "./websocket",' \ - --replace-fail \ - '.hash = "metrics-0.0.0-W7G4eP2_AQAdJGKMonHeZFaY4oU4ZXPFFTqFCFXItX3O",' "" \ - --replace-fail \ - '.hash = "websocket-0.1.0-ZPISdZJxAwAt6Ys_JpoHQQV3NpWCof_N9Jg-Ul2g7OoV",' "" - - ln -s ${finalAttrs.metrics} ./logz/metrics - - # wrong commit hash killing myself - # this is assuming logz can build using httpz's metrics dep - substituteInPlace logz/build.zig.zon \ - --replace-fail \ - '.url = "https://github.com/karlseguin/metrics.zig/archive/13d8706e1ae921a8cc0d2f88283c1b5412c73e2f.tar.gz",' \ - '.path = "./metrics",' \ - --replace-fail \ - '.hash = "metrics-0.0.0-W7G4eP2_AQBKsaql3dhLJ-pkf-RdP-zV3vflJy4N34jC",' "" - ''; - - meta = { - mainProgram = "maivi"; - }; - }); - - # For bundling with nix bundle for running outside of nix - # example: https://github.com/ralismark/nix-appimage - apps.bundle = { - type = "app"; - program = "${self.packages.${system}.foreign}/bin/default"; - }; - - # nix run . - apps.default = env.app [ ] "zig build run -- \"$@\""; - - # nix run .#build - apps.build = env.app [ ] "zig build \"$@\""; - - # nix run .#test - apps.test = env.app [ ] "zig build test -- \"$@\""; - - # nix run .#docs - apps.docs = env.app [ ] "zig build docs -- \"$@\""; - - # nix run .#zig2nix - apps.zig2nix = env.app [ ] "zig2nix \"$@\""; - - # nix develop - devShells.default = - let - inherit (self.packages.${system}) default; - in - 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 = [ - pkgs.just - pkgs.watchexec - pkgs.hl-log-viewer - ] - ++ default.nativeBuildInputs - ++ default.buildInputs - ++ default.zigWrapperBins - ++ default.zigWrapperLibs; - }; - } - ); + { + packages = forAllSystems (pkgs: { + default = pkgs.callPackage ./nix/package.nix { }; + }); + devShells = forAllSystems (pkgs: { + default = pkgs.callPackage ./nix/shell.nix { }; + }); + formatter = forAllSystems (pkgs: pkgs.callPackage ./nix/formatter.nix { }); + }; } diff --git a/nix/deps.nix b/nix/deps.nix new file mode 100644 index 0000000..374ea94 --- /dev/null +++ b/nix/deps.nix @@ -0,0 +1,84 @@ +{ + linkFarm, + fetchgit, + fetchzip, +}: +linkFarm "zig-packages" [ + # httpz ====================================================================== + + { + name = "httpz-0.0.0-PNVzrDC4BwANG-9UeHJ5udYPc19jZpm6LbkAtlAElOBk"; + path = fetchgit { + url = "https://github.com/karlseguin/http.zig.git"; + rev = "b0c3479b58f999f014862c35922eea1a56e5677a"; + hash = "sha256-NOmO1wtVgw7+tJk049zEIZyo2jv683//jAz6PALx2fI="; + }; + } + + { + name = "metrics-0.0.0-W7G4eIegAQD4XxA9Co7Atbw59u_2zvxYf406AZuoAHPM"; + path = fetchgit { + url = "https://github.com/karlseguin/metrics.zig.git"; + rev = "6de29b83a750a06c438d268543e0e3c3c1b309da"; + hash = "sha256-F0tnpGmcPtNIff+i9z9ZVWttLvAKQNXQzVAKnsSFV+o="; + }; + } + + { + name = "websocket-0.1.0-ZPISdUU6BAAPe0iZ_JHMVAXaBlz327xZRBrRY06-Vw5h"; + path = fetchgit { + url = "https://github.com/karlseguin/websocket.zig.git"; + rev = "3be6210f53297fb4b458d88562047ff4d69629a3"; + hash = "sha256-KcOI77ckcUsnFUrPs6qzETR2aQk8iMAj8QKYzdvCZIo="; + }; + } + + # fern ======================================================================= + + { + name = "fern-0.0.0-iF4X_ZB5AACpf_yE820FAV3m3OFVsQfUro0Z3fk4qqzS"; + path = fetchgit { + url = "https://git.koi.rip/koi/fern.git"; + rev = "0ffc3e4421010daad5e18272f2f82249def58694"; + hash = "sha256-Zu+v059p5dMJqt0oR7hZZwKZltW2VjbvcUB4Gc2HUHA="; + }; + } + + # ziglua====================================================================== + + { + name = "zlua-0.1.0-hGRpCwGVBQCZRZ2QEHLENoYjRj-nNjD500_BmMsXeqT4"; + path = fetchgit { + url = "https://github.com/natecraddock/ziglua.git"; + rev = "9a520d0bbaac378d2e926c76edb584da104941dc"; + hash = "sha256-dlIf+Piducah2YZ+BdPEtytiTTWbAxOKCaqXHsUtSB0="; + }; + } + + # luajit + { + name = "N-V-__8AAODpQgCVrpfzE2ze9FA_rOuByh3WKyIyk5iS_o9a"; + path = fetchzip { + url = "https://github.com/LuaJIT/LuaJIT/archive/18b087cd2cd4ddc4a79782bf155383a689d5093d.tar.gz"; + hash = "sha256-+TNzBOb1jUSuCixfiOCpCKmXqOmiXl6lFjfcWLnC0WY="; + }; + } + + { + name = "translate_c-0.0.0-Q_BUWpf0BgAwrh5AM-acJcslN_YPEhcoCVKbbNjwuUTJ"; + path = fetchgit { + url = "https://codeberg.org/ziglang/translate-c"; + rev = "46b5609b5ac4c0a896217d1d984f3ae50e4810b5"; + hash = "sha256-ZQf1yyG7Z2bVOVQskLBmTdZQ43/xKltgwra+AZirvO4="; + }; + } + + { + name = "aro-0.0.0-JSD1Qi7QNgDnfcrdEJf82v3o6MhZySjYVrtdfEf3E4Se"; + path = fetchgit { + url = "https://github.com/Vexu/arocc"; + rev = "5f5a050569a95ecc40a426f0c3666ae7ef987ede"; + hash = "sha256-f8Z0SXWx5Uia2TCMB5SUpcO8+xUnaWk32Oknva7xcxw="; + }; + } +] diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..4a279e3 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,34 @@ +{ + lib, + stdenv, + callPackage, + + zig, +}: +stdenv.mkDerivation { + pname = "maivi"; + version = "0.1.0"; + src = ../.; + + nativeBuildInputs = [ zig ]; + buildInputs = [ ]; + + doCheck = false; + checkPhase = '' + runHook preCheck + zig build test + runHook postCheck + ''; + + zigBuildFlags = [ + "--system" + "${callPackage ./deps.nix { }}" + ]; + + meta = { + homepage = "https://codeberg.org/comfysage/maivi"; + license = lib.licenses.asl20; + platforms = [ "x86_64-linux" ]; + mainProgram = "maivi"; + }; +} diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..acafd6c --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,14 @@ +{ + just, + watchexec, + hl-log-viewer, + + mkShellNoCC, +}: +mkShellNoCC { + packages = [ + just + watchexec + hl-log-viewer + ]; +} -- 2.51.2