From 21797b3a423115195775b6ed51666b35ababbe33 Mon Sep 17 00:00:00 2001 From: reo101 Date: Mon, 23 Jun 2025 08:11:42 +0300 Subject: [PATCH] feat(nix): add `flake.nix`, packaging `rootbeer` --- .gitignore | 1 + flake.lock | 64 ++++++++++++++++++++++++++++++ flake.nix | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 6d755b5..d693c60 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ docs/.doxygen/ docs/_build subprojects/* !subprojects/*.wrap +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6264eed --- /dev/null +++ b/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1749398372, + "narHash": "sha256-tYBdgS56eXYaWVW3fsnPQ/nFlgWi/Z2Ymhyu21zVM98=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9305fe4e5c2a6fcf5ba6a3ff155720fbe4076569", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1750506804, + "narHash": "sha256-VLFNc4egNjovYVxDGyBYTrvVCgDYgENp5bVi9fPTDYc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4206c4cb56751df534751b058295ea61357bbbaa", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ab2a85e --- /dev/null +++ b/flake.nix @@ -0,0 +1,111 @@ +{ + description = "A Nix flake for the tale/rootbeer system configuration tool"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + + systems = { + url = "github:nix-systems/default"; + }; + }; + + outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = import inputs.systems; + perSystem = { self', lib, pkgs, system, ... }: { + packages = { + rootbeer = let + # NOTE: as per <./meson.build> + version = "0.0.1"; + source-with-meson-deps = pkgs.stdenv.mkDerivation { + pname = "rootbeer-deps"; + inherit version; + + src = lib.cleanSource ./.; + + nativeBuildInputs = [ + pkgs.pkg-config + pkgs.meson + pkgs.cmake + pkgs.git + pkgs.cacert + pkgs.ninja + ]; + + outputHashAlgo = "sha256"; + outputHashMode = "recursive"; + outputHash = "sha256-DdbXF0LdCptpY5zDApOUDHonDlMjRl7ut9m/46Lj+74="; + + phases = [ + "installPhase" + ]; + + installPhase = '' + # Copy over the raw source in the output, since we'll do the vendoring work there + mkdir -p $out + cd $out + cp --no-preserve=mode -r $src/. . + + # Set the SSL certificate file for network access + export NIX_SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt + + # Download the subprojects the `meson` way (using networking, hence the FOD) + ${pkgs.lib.getExe pkgs.meson} subprojects download \ + cjson luajit + + # Clean up `git` metadata from the downloaded dependencies + find subprojects -type d -name .git -prune -execdir rm -r {} + + ''; + }; + in pkgs.stdenv.mkDerivation { + pname = "rootbeer"; + inherit version; + + src = source-with-meson-deps; + + nativeBuildInputs = [ + pkgs.pkg-config + pkgs.ninja + pkgs.meson + pkgs.autoPatchelfHook + ]; + + buildInputs = [ + ]; + + postInstall = '' + # Manually install the main executable, left in the `src` directory, for some reason + mkdir -p $out/bin + cp ./src/rootbeer_cli/rb $out/bin/ + + # Install provided libraries + # TODO: not sure what the structure of those should be for other consumers + mkdir -p $out/lib/rootbeer + cp -r ./src/librootbeer/. $out/lib/rootbeer/ + ''; + + meta = with pkgs.lib; { + description = "A tool to deterministically manage your system using Lua"; + homepage = "Deterministically manage your system using Lua!"; + # NOTE: as per <./meson.build> + license = licenses.mit; + platforms = platforms.all; + maintainers = with maintainers; [ ]; + }; + }; + + default = self'.packages.rootbeer; + }; + + devShells = { + default = pkgs.mkShell { + packages = self'.packages.rootbeer.buildInputs ++ self'.packages.rootbeer.nativeBuildInputs; + }; + }; + }; + }; +}