From e3c69bc5e5e251be75d3e2019b593decd95139fb Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sat, 22 Mar 2025 00:42:59 +0100 Subject: [PATCH] rewrite to python: redo nix packaging --- .envrc | 1 + flake.lock | 27 +++++++++++++++++ flake.nix | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4e45c8a --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1762482733, + "narHash": "sha256-g/da4FzvckvbiZT075Sb1/YDNDr+tGQgh4N8i5ceYMg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e1ebeec86b771e9d387dd02d82ffdc77ac753abc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index e7784aa..3324d7c 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,84 @@ { - inputs = { }; - outputs = inputs@{ self, ...}: { - map-markers = import ./map-markers; - map-lib = import ./map-markers/lib.nix; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + outputs = { self, nixpkgs }: let + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in f system pkgs); + + inherit (nixpkgs) lib; + + in { + apps = forAllSystems (system: pkgs: let + mkApp = package: { + type = "app"; + program = lib.getExe package; + }; + in { + default = mkApp self.packages.${system}.default; + }); + + devShells = forAllSystems (_: pkgs: { + default = pkgs.mkShell { + packages = with pkgs; [ + uv + (python3.withPackages (ps: with ps; [])) + biome + ]; + }; + }); + + overlays.default = final: prev: self.packages.${final.system}; + + packages = forAllSystems (system: pkgs: { + default = self.packages.${system}.mckart; + + mckart = let + pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml); + in with pkgs.python3Packages; buildPythonPackage { + pname = pyproject.project.name; + version = pyproject.project.version; + src = lib.cleanSource ./.; + + format = "pyproject"; + + build-system = [ hatchling ]; + dependencies = []; + + meta.mainProgram = "mckart"; + }; + + bluemap-export = pkgs.runCommand "bluemap-export" { + buildInputs = [ (self.packages.${system}.mckart) ]; + } '' + mckart export-bluemap --output-dir "$out" + ''; + + mapcrafter-export = pkgs.runCommand "mapcrafter-export" { + buildInputs = [ + (self.packages.${system}.mckart) + pkgs.biome + ]; + + biomeConf = builtins.toJSON { + formatter = { + indentStyle = "space"; + lineWidth = 100; + }; + }; + passAsFile = [ "biomeConf" ]; + } '' + mckart export-mapcrafter --output-dir "$out" + cp "$biomeConfPath" ./biome.json + biome format --config-path=./biome.json "$out"/* --write + ''; + }); }; }