From 017aadcf35a69ea448085a8a70783ded337526d0 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 11 Oct 2024 21:05:14 +0300 Subject: [PATCH] nix fuckery --- flake.lock | 51 +++++----- flake.nix | 93 +++++++++---------- ...nstall-directory-variants-in-pkg-con.patch | 0 nix/{SDL3.nix => packages/SDL3/default.nix} | 8 +- nix/packages/cursed-libcxx-stdenv/default.nix | 11 +++ nix/packages/gooey/default.nix | 64 +++++++++++++ nix/shells/default.nix | 11 +++ 7 files changed, 159 insertions(+), 79 deletions(-) rename nix/{ => packages/SDL3}/0001-cmake-use-FULL-install-directory-variants-in-pkg-con.patch (100%) rename nix/{SDL3.nix => packages/SDL3/default.nix} (89%) create mode 100644 nix/packages/cursed-libcxx-stdenv/default.nix create mode 100644 nix/packages/gooey/default.nix create mode 100644 nix/shells/default.nix diff --git a/flake.lock b/flake.lock index 243467a..7025270 100644 --- a/flake.lock +++ b/flake.lock @@ -1,20 +1,20 @@ { "nodes": { - "flake-utils": { + "flake-parts": { "inputs": { - "systems": "systems" + "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "hercules-ci", + "repo": "flake-parts", "type": "github" } }, @@ -22,37 +22,34 @@ "locked": { "lastModified": 1728492678, "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", - "owner": "nixos", + "owner": "NixOS", "repo": "nixpkgs", "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", "type": "github" }, "original": { - "owner": "nixos", + "owner": "NixOS", "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - } - }, - "systems": { + "nixpkgs-lib": { "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" }, "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index c10a1c3..c2d71c5 100644 --- a/flake.nix +++ b/flake.nix @@ -1,60 +1,57 @@ { inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; outputs = { self, - nixpkgs, - flake-utils, - }: - flake-utils.lib.eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages.${system}; - stdenv = pkgs.llvmPackages_19.libcxxStdenv; - cmake-version = "3.30.4"; + flake-parts, + ... + } @ inputs: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux"]; + perSystem = { + self', + inputs', + system, + config, + pkgs, + lib, + ... + }: let + inherit (pkgs) callPackage; + in { + # Customize the pkgs instance with our desired features + # and overlays. + legacyPackages = import inputs.nixpkgs { + inherit system; + config = { + overlays = [self.overlays.default]; # consume local overlay + }; + }; - gooey = stdenv.mkDerivation { - pname = "gooey"; - version = "0.0.1"; - # inherit system; + # Set pkgs to the updated value, which is also exposed + # as legacyPackages in the flake schema. + _module.args.pkgs = config.legacyPackages; - src = ./.; - nativeBuildInputs = [ - (pkgs.cmake.overrideAttrs { - version = "3.30.4"; - src = pkgs.fetchurl { - url = "https://cmake.org/files/v${pkgs.lib.versions.majorMinor cmake-version}/cmake-${cmake-version}.tar.gz"; - hash = "sha256-x1nJcnTx56qq/LHw0mH53pvzpdbst+LfYWMkpG/nBLI="; - }; - }) - pkgs.ninja - ]; + # Generate packages automagically from ./nix/packages + # for each package that contains a package.nix - this + # is a flake-parts feature that makes our life easier. + packages = { + sdl3-custom = callPackage ./nix/packages/SDL3 {}; + # cursed-libcxx-stdenv = callPackage ./nix/packages/cursed-libcxx-stdenv {}; + gooey = callPackage ./nix/packages/gooey { + inherit self; + sdl3 = self'.packages.sdl3-custom; + }; + }; - buildInputs = [ - (pkgs.callPackage ./nix/SDL3.nix {}) - pkgs.llvmPackages_19.clang-tools - ]; + # Generate an overlay containing each one of our packages that are collected + # from ./nix/packages. + # overlayAttrs = self.packages; - configurePhase = '' - cmake -GNinja . - ''; - - buildPhase = '' - ninja - ''; - - installPhase = '' - mkdir -p $out/bin - mv gooey $out/bin - ''; + devShells.default = callPackage ./shells/default.nix {inherit (self'.packages) gooey;}; }; - in { - packages.default = gooey; - devShells.default = pkgs.mkShell.override {inherit stdenv;} { - name = "gooey"; - inputsFrom = [gooey]; - CMAKE_GENERATOR = "Ninja"; - }; - }); + }; } diff --git a/nix/0001-cmake-use-FULL-install-directory-variants-in-pkg-con.patch b/nix/packages/SDL3/0001-cmake-use-FULL-install-directory-variants-in-pkg-con.patch similarity index 100% rename from nix/0001-cmake-use-FULL-install-directory-variants-in-pkg-con.patch rename to nix/packages/SDL3/0001-cmake-use-FULL-install-directory-variants-in-pkg-con.patch diff --git a/nix/SDL3.nix b/nix/packages/SDL3/default.nix similarity index 89% rename from nix/SDL3.nix rename to nix/packages/SDL3/default.nix index eafb252..0fc657f 100644 --- a/nix/SDL3.nix +++ b/nix/packages/SDL3/default.nix @@ -79,17 +79,17 @@ stdenv.mkDerivation (finalAttrs: { xorg.libXi xorg.libXrandr ] - ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Cocoa ]); + ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [Cocoa]); passthru = { - tests.pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; }; + tests.pkg-config = testers.hasPkgConfigModules {package = finalAttrs.finalPackage;}; }; meta = { description = "Cross-platform development library (Pre-release version)"; homepage = "https://libsdl.org"; license = lib.licenses.zlib; - maintainers = with lib.maintainers; [ getchoo ]; - pkgConfigModules = [ "sdl3" ]; + maintainers = with lib.maintainers; [getchoo]; + pkgConfigModules = ["sdl3"]; }; }) diff --git a/nix/packages/cursed-libcxx-stdenv/default.nix b/nix/packages/cursed-libcxx-stdenv/default.nix new file mode 100644 index 0000000..78a8adb --- /dev/null +++ b/nix/packages/cursed-libcxx-stdenv/default.nix @@ -0,0 +1,11 @@ +{llvmPackages_19, ...}: let + cursed-libcxx-stdenv = llvmPackages_19.libcxxStdenv.overrideAttrs (oa: { + postFixup = + (oa.postFixup or "") + + '' + ln -sf ${llvmPackages_19.libcxx}/lib/libc++.modules.json $out/resource-root/libc++.modules.json + ln -sf ${llvmPackages_19.libcxx}/share $out + ''; + }); +in + cursed-libcxx-stdenv diff --git a/nix/packages/gooey/default.nix b/nix/packages/gooey/default.nix new file mode 100644 index 0000000..c610892 --- /dev/null +++ b/nix/packages/gooey/default.nix @@ -0,0 +1,64 @@ +{ + self, + sdl3, # from self.packages + lib, + fetchurl, + cmake, + ninja, + llvmPackages_19, + ... +}: let + pname = "gooey"; + version = "0.0.1"; +in + llvmPackages_19.libcxxStdenv.mkDerivation { + inherit pname version; + src = builtins.path { + # reproducible source path + path = self; + name = "${pname}-${version}"; + }; + + enableParallelBuilding = true; + strictDeps = true; + + nativeBuildInputs = [ + ninja + (cmake.overrideAttrs { + version = "3.30.4"; + src = let + cmake-version = "3.30.4"; + in + fetchurl { + url = "https://cmake.org/files/v${lib.versions.majorMinor cmake-version}/cmake-${cmake-version}.tar.gz"; + hash = "sha256-x1nJcnTx56qq/LHw0mH53pvzpdbst+LfYWMkpG/nBLI="; + }; + }) + ]; + + buildInputs = [ + sdl3 + llvmPackages_19.clang-tools + ]; + + configurePhase = '' + runHook preConfigure + cmake -GNinja . + runHook postConfiguree + ''; + + buildPhase = '' + runHook preBuild + ninja + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + mv gooey $out/bin + + runHook postInstall + ''; + } diff --git a/nix/shells/default.nix b/nix/shells/default.nix new file mode 100644 index 0000000..8369f22 --- /dev/null +++ b/nix/shells/default.nix @@ -0,0 +1,11 @@ +{ + mkShell, + llvmPackages_19, + gooey, + ... +}: +mkShell.override {stdenv = llvmPackages_19.libcxxStdenv;} { + name = "gooey-dev-env"; + inputsFrom = [gooey]; + CMAKE_GENERATOR = "Ninja"; +}