From 794f2ed0111be7c921b8d6daa73e435c337641a4 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Mon, 20 Jan 2025 07:38:01 +0000 Subject: [PATCH] Refactor nix flake, based on overriding nixpkgs Now that umu-launcher-unwrapped is being maintained in nixpkgs, it can be used as a starting point for the nix package here. We just need to override a few things, such as the `src`, and handle any changes that have not yet made it into a release build. Ideally, we would also reuse the nixpkgs umu-launcher wrapper package. However, 1) it is currently not fully overridable and 2) we have a slightly different package-args API that needs to be maintained. The opportunity has been taken to clean up that package-args API: - Renamed `truststore` to `withTruststore` with a warning. - `cbor2` wasn't working, warn when it is used. - Added `withDeltaUpdates` Breaking changes: - The umu-launcher package in the overlay is no longer the unwrapped package (previously in `umu-launcher.nix`). - The derivation attrs for various packages are re-written from scratch, likely breaking users' custom overrides. Non-breaking changes: - The umu & umu-run packages have effectively been renamed umu-launcher. - The flake outputs for all systems supported by the nixpkgs package. - The package version is now derived from the flake's lastModifiedDate. --- README.md | 32 ++++++++++--- packaging/nix/combine.nix | 22 --------- packaging/nix/flake.nix | 62 ++++++++++++------------- packaging/nix/package.nix | 82 ++++++++++++++++++++++++++++++++++ packaging/nix/umu-launcher.nix | 61 ------------------------- packaging/nix/umu-run.nix | 18 -------- 6 files changed, 138 insertions(+), 139 deletions(-) delete mode 100644 packaging/nix/combine.nix create mode 100644 packaging/nix/package.nix delete mode 100644 packaging/nix/umu-launcher.nix delete mode 100644 packaging/nix/umu-run.nix diff --git a/README.md b/README.md index 3414d2a3..6bb8c0e8 100644 --- a/README.md +++ b/README.md @@ -155,21 +155,39 @@ and in your `configuration.nix` {inputs, pkgs, ... }: let inherit (pkgs.stdenv.hostPlatform) system; - umu = inputs.umu.packages.${system}.umu.override { + unu-launcher = inputs.umu.packages.${system}.default; +in +{ + environment.systemPackages = [ umu-launcher ]; +} +``` + +> [!TIP] +> It is common practice to override umu's `version` to `inputs.umu.shortRev` (the umu git commit). By default, the version is based on `inputs.umu`'s last modified date. +> e.g. `"git.2025.01.22.09.59.33"`. + +> [!TIP] +> `withTruststore` and `withDeltaUpdates` can be used to disable optional dependencies that are enabled by default. +> You can omit these, or set them to `false` if you do not want these dependencies. + +Example: +```nix +{inputs, pkgs, ... }: +let + inherit (pkgs.stdenv.hostPlatform) system; + umu-launcher = inputs.umu.packages.${system}.default.override { version = inputs.umu.shortRev; - truststore = true; - cbor2 = true; + withTruststore = false; + withDeltaUpdates = false; }; in { - environment.systemPackages = [ umu ]; + environment.systemPackages = [ umu-launcher ]; } ``` -> [!NOTE] -> truststore and cbor2 (for delta updates) are optional dependency which are enabled by default if you want to keep it that way you can remove the `truststore = true; cbor2 = true;` part > [!NOTE] -> The example above relies on having your flake's `inputs` passed through to your nixos configuration. +> The examples above rely on having your flake's `inputs` passed through to your nixos configuration. > This can be done with `specialArgs` or `_module.args`, e.g: > ```nix > { diff --git a/packaging/nix/combine.nix b/packaging/nix/combine.nix deleted file mode 100644 index 222121cc..00000000 --- a/packaging/nix/combine.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ - env, - package, - symlinkJoin, - version, - truststore, - cbor2, -}: -symlinkJoin { - name = "umu-run-bwrap"; - paths = [ - (package.override { - version = "${version}"; - truststore = truststore; - cbor2 = cbor2; - }) - (env.override {version = "${version}";}) - ]; - postBuild = '' - rm $out/bin/umu - ''; -} diff --git a/packaging/nix/flake.nix b/packaging/nix/flake.nix index 3392beed..3563be9d 100644 --- a/packaging/nix/flake.nix +++ b/packaging/nix/flake.nix @@ -9,43 +9,43 @@ self, nixpkgs, }: let - umu-launcher-src = builtins.toPath "${self}/../../"; - - pkgs = import nixpkgs { - system = "x86_64-linux"; - overlays = [self.overlays.default]; - }; - - version = "1.1.4"; + inherit (nixpkgs) lib; + + # Utility function for producing consistent rename warning messages + rename = old: new: lib.warn "`${old}` has been renamed to `${new}`"; + + # Package sets supported by umu-launcher-unwrapped + # { system = pkgs; } + supportedPkgs = + lib.filterAttrs + (system: pkgs: builtins.elem system pkgs.umu-launcher-unwrapped.meta.platforms) + nixpkgs.legacyPackages; + + # Generate a version string, based on the flake's lastModifiedDate + version = let + date = self.lastModifiedDate; + parts = builtins.match "(\[0-9\]{4})(\[0-9\]{2})(\[0-9\]{2})(\[0-9\]{2})(\[0-9\]{2})(\[0-9\]{2})" date; + in "git.${lib.concatStringsSep "." parts}"; in { - overlays.default = final: prev: let - py = prev.python3; - in { - umu-launcher = final.callPackage ./umu-launcher.nix { - inherit version; - umu-launcher = umu-launcher-src; - pyth1 = py; - }; - - umu-run = final.callPackage ./umu-run.nix { + overlays.default = final: prev: { + umu-launcher = final.callPackage ./package.nix { inherit version; - package = final.umu-launcher; - }; - - umu = final.callPackage ./combine.nix { - inherit version; - env = final.umu-run; - package = final.umu-launcher; - truststore = true; - cbor2 = true; + inherit (prev) umu-launcher-unwrapped; }; + umu = rename "umu" "umu-launcher" final.umu-launcher; + umu-run = rename "umu-run" "umu-launcher" final.umu-launcher; + inherit (final.umu-launcher.passthru) umu-launcher-unwrapped; }; formatter = builtins.mapAttrs (system: pkgs: pkgs.alejandra) nixpkgs.legacyPackages; - packages.x86_64-linux = { - inherit (pkgs) umu; - default = self.packages.x86_64-linux.umu; - }; + packages = + builtins.mapAttrs (system: pkgs: rec { + default = umu-launcher; + umu-launcher = pkgs.callPackage ./package.nix {inherit version;}; + umu = rename "packages.${system}.umu" "packages.${system}.umu-launcher" umu-launcher; + inherit (umu-launcher.passthru) umu-launcher-unwrapped; + }) + supportedPkgs; }; } diff --git a/packaging/nix/package.nix b/packaging/nix/package.nix new file mode 100644 index 00000000..e9ae63d3 --- /dev/null +++ b/packaging/nix/package.nix @@ -0,0 +1,82 @@ +{ + # Dependencies: + lib, + buildFHSEnv, + umu-launcher-unwrapped, + python3Packages, + rustPlatform, + cargo, + zstd, + # Public API: + version, + withTruststore ? args.truststore or true, + withDeltaUpdates ? true, + # Deprecated: + # NOTE: this relies on there not being a `pkgs.truststore` or `pkgs.cbor2`... + # If there was, callPackage would provide them, causing our warnings to false-positive. + truststore ? null, + cbor2 ? null, +} @ args: let + checked = { + withTruststore = + lib.warnIf (args ? truststore) + "umu-launcher: the argument `truststore` has been renamed to `withTruststore`." + withTruststore; + withDeltaUpdates = + lib.warnIf (args ? cbor2) + "umu-launcher: the argument `cbor2` has never had any effect. The new argument `withDeltaUpdates` should be used instead." + withDeltaUpdates; + }; + + overridden = umu-launcher-unwrapped.overridePythonAttrs (prev: { + src = ../../.; + inherit version; + + # We can drop old.patches and replace it with the patches we actually need + patches = [ + ./0-Makefile-no-vendor.patch + ]; + + nativeBuildInputs = + (prev.nativeBuildInputs or []) + ++ [ + rustPlatform.cargoSetupHook + cargo + ]; + + propagatedBuildInputs = + (prev.propagatedBuildInputs or []) + ++ lib.optionals checked.withTruststore [ + python3Packages.truststore + ] + ++ lib.optionals checked.withDeltaUpdates [ + python3Packages.cbor2 + python3Packages.xxhash + zstd + ]; + + cargoDeps = rustPlatform.importCargoLock { + lockFile = ../../Cargo.lock; + }; + }); +in + # We cannot override everything we need to, so re-implement the package + # See https://github.com/NixOS/nixpkgs/pull/375588 + # Tracker https://nixpk.gs/pr-tracker.html?pr=375588 + buildFHSEnv { + pname = "umu-launcher"; + inherit (overridden) version meta; + executableName = overridden.meta.mainProgram; + + targetPkgs = pkgs: [overridden]; + runScript = lib.getExe overridden; + + extraInstallCommands = '' + ln -s ${overridden}/lib $out/lib + ln -s ${overridden}/share $out/share + ''; + + # For debugging and to simplify the overlay, + # expose the overridden unwrapped package + passthru.umu-launcher-unwrapped = overridden; + } diff --git a/packaging/nix/umu-launcher.nix b/packaging/nix/umu-launcher.nix deleted file mode 100644 index a8350456..00000000 --- a/packaging/nix/umu-launcher.nix +++ /dev/null @@ -1,61 +0,0 @@ -{ - lib, - pyth1, - python3Packages, - umu-launcher, - pkgs, - version, - truststore ? true, - deltaUpdates ? { - cbor2 = true; - xxhash = true; - zstd = true; - }, - rustPlatform, - ... -}: -python3Packages.buildPythonPackage { - pname = "umu-launcher"; - version = "${version}"; - src = umu-launcher; - patches = [./0-Makefile-no-vendor.patch]; - pyproject = false; - depsBuildBuild = [ - pkgs.meson - pkgs.ninja - pkgs.scdoc - pkgs.git - pkgs.python3Packages.installer - # temporary fix, tracking https://github.com/NixOS/nixpkgs/issues/366359 - (pkgs.hatch.overridePythonAttrs {doCheck = false;}) - pkgs.python3Packages.build - pkgs.cargo - ]; - cargoDeps = rustPlatform.importCargoLock { - lockFile = ../../Cargo.lock; - }; - nativeBuildInputs = with rustPlatform; [cargoSetupHook]; - propagatedBuildInputs = - [ - pyth1 - pkgs.bubblewrap - pkgs.python3Packages.xlib - pkgs.python3Packages.urllib3 - ] - ++ lib.optional truststore pkgs.python3Packages.truststore - ++ lib.optional deltaUpdates.cbor2 pkgs.python3Packages.cbor2 - ++ lib.optional deltaUpdates.xxhash pkgs.python3Packages.xxhash - ++ lib.optional deltaUpdates.zstd pkgs.zstd; - makeFlags = ["PYTHON_INTERPRETER=${pyth1}/bin/python" "SHELL_INTERPRETER=/run/current-system/sw/bin/bash" "DESTDIR=build"]; - dontUseMesonConfigure = true; - dontUseNinjaBuild = true; - dontUseNinjaInstall = true; - dontUseNinjaCheck = true; - configureScript = "./configure.sh"; - configureFlags = ["--prefix=${placeholder "out"}"]; - postInstall = '' - cp -r build${pyth1}/* $out - cp -r build$out/* $out - mv $out/bin/umu-run $out/bin/umu - ''; -} diff --git a/packaging/nix/umu-run.nix b/packaging/nix/umu-run.nix deleted file mode 100644 index 81f6030f..00000000 --- a/packaging/nix/umu-run.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ - package, - buildFHSEnv, - writeShellScript, - version, - ... -}: -buildFHSEnv { - name = "umu-run"; - version = "${version}"; - targetPkgs = pkgs: [ - package - ]; - multiArch = true; - runScript = writeShellScript "umu-run-shell" '' - ${package}/bin/umu "$@" - ''; -}