From 86243e343604bbf210a971301a26d4b0e25565be Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 7 Jun 2026 07:49:44 +0900 Subject: [PATCH] flake.nix: init --- .gitignore | 3 ++ flake.lock | 27 +++++++++++++++ flake.nix | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e5c491e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Nix +result +result-* diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..bffd844 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1780243769, + "narHash": "sha256-x5UQuRsH3MqI0U9afaXSNqzTPSeZlRLvFAav2Ux1pNw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "331800de5053fcebacf6813adb5db9c9dca22a0c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a578610 --- /dev/null +++ b/flake.nix @@ -0,0 +1,99 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs }: + let + inherit (nixpkgs) lib; + + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + "armv7l-linux" + ]; + + forAllSystems = f: lib.genAttrs systems (system: f system nixpkgs.legacyPackages.${system}); + in { + apps = let + mkApp = program: description: { + type = "app"; + program = toString program; + meta = { + inherit description; + }; + }; + in forAllSystems (system: pkgs: { + default = self.apps.${system}.hanabi; + hanabi = mkApp (lib.getExe self.packages.${system}.hanabi) "Run the hanabi executable"; + }); + + devShells = forAllSystems (system: pkgs: { + default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + odin + nushell + ]; + }; + }); + + overlays = { + default = self.overlays.hanabi; + hanabi = final: prev: { + inherit (self.packages.${prev.stdenv.hostPlatform.system}) hanabi; + }; + }; + + packages = forAllSystems (system: pkgs: { + default = self.packages.${system}.hanabi; + hanabi = pkgs.stdenv.mkDerivation { + name = "hanabi"; + version = "unstable"; + src = ./src; + + nativeBuildInputs = with pkgs; [ odin ]; + + buildPhase = let + optionFormat = optionName: { + option = "-${optionName}"; + sep = ":"; + explicitBool = true; + }; + + buildOpts = lib.cli.toCommandLineShell optionFormat { + build-mode = "exe"; + out = "hanabi"; + o = "speed"; + lto = "thin"; + }; + in '' + runHook preBuild + + odin build . ${buildOpts} + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + install -Dm555 hanabi -t "$out/bin" + + runHook postInstall + ''; + + meta = { + license = lib.licenses.agpl3Only; + homepage = "https://git.pvv.ntnu.no/frero/hanabi"; + mainProgram = "hanabi"; + }; + }; + }); + + checks = forAllSystems (system: pkgs: { + inherit (self.packages.${system}) hanabi; + }); + }; +}