nix fuckery

This commit is contained in:
raf 2024-10-11 21:05:14 +03:00
parent 1b49477c4e
commit 017aadcf35
Signed by: NotAShelf
GPG key ID: AF26552424E53993
7 changed files with 159 additions and 79 deletions

View file

@ -1,20 +1,20 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "flake-parts": {
"inputs": { "inputs": {
"systems": "systems" "nixpkgs-lib": "nixpkgs-lib"
}, },
"locked": { "locked": {
"lastModified": 1726560853, "lastModified": 1727826117,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=",
"owner": "numtide", "owner": "hercules-ci",
"repo": "flake-utils", "repo": "flake-parts",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "numtide", "owner": "hercules-ci",
"repo": "flake-utils", "repo": "flake-parts",
"type": "github" "type": "github"
} }
}, },
@ -22,37 +22,34 @@
"locked": { "locked": {
"lastModified": 1728492678, "lastModified": 1728492678,
"narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=",
"owner": "nixos", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "NixOS",
"ref": "nixos-unstable", "ref": "nixos-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"root": { "nixpkgs-lib": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": { "locked": {
"lastModified": 1681028828, "lastModified": 1727825735,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=",
"owner": "nix-systems", "type": "tarball",
"repo": "default", "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz"
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
}, },
"original": { "original": {
"owner": "nix-systems", "type": "tarball",
"repo": "default", "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz"
"type": "github" }
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
} }
} }
}, },

View file

@ -1,60 +1,57 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; flake-parts.url = "github:hercules-ci/flake-parts";
flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
}; };
outputs = { outputs = {
self, self,
nixpkgs, flake-parts,
flake-utils, ...
}: } @ inputs:
flake-utils.lib.eachDefaultSystem (system: let flake-parts.lib.mkFlake {inherit inputs;} {
pkgs = nixpkgs.legacyPackages.${system}; systems = ["x86_64-linux"];
stdenv = pkgs.llvmPackages_19.libcxxStdenv; perSystem = {
cmake-version = "3.30.4"; 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 { # Set pkgs to the updated value, which is also exposed
pname = "gooey"; # as legacyPackages in the flake schema.
version = "0.0.1"; _module.args.pkgs = config.legacyPackages;
# inherit system;
src = ./.; # Generate packages automagically from ./nix/packages
nativeBuildInputs = [ # for each package that contains a package.nix - this
(pkgs.cmake.overrideAttrs { # is a flake-parts feature that makes our life easier.
version = "3.30.4"; packages = {
src = pkgs.fetchurl { sdl3-custom = callPackage ./nix/packages/SDL3 {};
url = "https://cmake.org/files/v${pkgs.lib.versions.majorMinor cmake-version}/cmake-${cmake-version}.tar.gz"; # cursed-libcxx-stdenv = callPackage ./nix/packages/cursed-libcxx-stdenv {};
hash = "sha256-x1nJcnTx56qq/LHw0mH53pvzpdbst+LfYWMkpG/nBLI="; gooey = callPackage ./nix/packages/gooey {
}; inherit self;
}) sdl3 = self'.packages.sdl3-custom;
pkgs.ninja };
]; };
buildInputs = [ # Generate an overlay containing each one of our packages that are collected
(pkgs.callPackage ./nix/SDL3.nix {}) # from ./nix/packages.
pkgs.llvmPackages_19.clang-tools # overlayAttrs = self.packages;
];
configurePhase = '' devShells.default = callPackage ./shells/default.nix {inherit (self'.packages) gooey;};
cmake -GNinja .
'';
buildPhase = ''
ninja
'';
installPhase = ''
mkdir -p $out/bin
mv gooey $out/bin
'';
}; };
in { };
packages.default = gooey;
devShells.default = pkgs.mkShell.override {inherit stdenv;} {
name = "gooey";
inputsFrom = [gooey];
CMAKE_GENERATOR = "Ninja";
};
});
} }

View file

@ -79,17 +79,17 @@ stdenv.mkDerivation (finalAttrs: {
xorg.libXi xorg.libXi
xorg.libXrandr xorg.libXrandr
] ]
++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Cocoa ]); ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [Cocoa]);
passthru = { passthru = {
tests.pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; }; tests.pkg-config = testers.hasPkgConfigModules {package = finalAttrs.finalPackage;};
}; };
meta = { meta = {
description = "Cross-platform development library (Pre-release version)"; description = "Cross-platform development library (Pre-release version)";
homepage = "https://libsdl.org"; homepage = "https://libsdl.org";
license = lib.licenses.zlib; license = lib.licenses.zlib;
maintainers = with lib.maintainers; [ getchoo ]; maintainers = with lib.maintainers; [getchoo];
pkgConfigModules = [ "sdl3" ]; pkgConfigModules = ["sdl3"];
}; };
}) })

View file

@ -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

View file

@ -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
'';
}

11
nix/shells/default.nix Normal file
View file

@ -0,0 +1,11 @@
{
mkShell,
llvmPackages_19,
gooey,
...
}:
mkShell.override {stdenv = llvmPackages_19.libcxxStdenv;} {
name = "gooey-dev-env";
inputsFrom = [gooey];
CMAKE_GENERATOR = "Ninja";
}