Skip to content

Commit

Permalink
Refactor nix flake, based on overriding nixpkgs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MattSturgeon committed Jan 22, 2025
1 parent 83890ba commit 794f2ed
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 139 deletions.
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
> {
Expand Down
22 changes: 0 additions & 22 deletions packaging/nix/combine.nix

This file was deleted.

62 changes: 31 additions & 31 deletions packaging/nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
82 changes: 82 additions & 0 deletions packaging/nix/package.nix
Original file line number Diff line number Diff line change
@@ -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;
}
61 changes: 0 additions & 61 deletions packaging/nix/umu-launcher.nix

This file was deleted.

18 changes: 0 additions & 18 deletions packaging/nix/umu-run.nix

This file was deleted.

0 comments on commit 794f2ed

Please sign in to comment.