From affcea3dd9d84d32c1175a50e46e877133ef6070 Mon Sep 17 00:00:00 2001 From: Shelvacu Date: Sun, 29 Jun 2025 18:19:52 -0700 Subject: [PATCH 1/5] Fixup mkCfg Previously, dollar signs in the tf2 config str would be interpreted as bash variables during build --- tf2/packages/default.nix | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tf2/packages/default.nix b/tf2/packages/default.nix index 3b35ffe..fe4003d 100644 --- a/tf2/packages/default.nix +++ b/tf2/packages/default.nix @@ -14,15 +14,14 @@ let inherit hash name; }; - mkCfg = name: body: - pkgs.runCommand name {} '' - ${lib.toShellVar "name" name} - mkdir -p $out/cfg "$(dirname "$out/cfg/$name")" - tee "$out/cfg/$name.cfg" << SUPER_UNIQUE_EOF - // Generated by tf2.nix - - ${body} - SUPER_UNIQUE_EOF + mkCfg = path: body: + pkgs.runCommand path {} '' + ${lib.toShellVar "pathPart" path} + path="$out/cfg/$pathPart.cfg" + mkdir -p "$(dirname -- "$path")" + echo "// Generated by tf2.nix" >> "$path" + echo >> "$path" + echo ${lib.escapeShellArg body} >> "$path" ''; mergeTf2Configs = configs: From 1b61a16e8c19520ac85d9442dc121aecbe941015 Mon Sep 17 00:00:00 2001 From: Shelvacu Date: Sun, 29 Jun 2025 18:23:27 -0700 Subject: [PATCH 2/5] Expose everything under legacyPackages instead of packages every attribute in packages.{system}.* is expected to be a derivation (you can see this if you run nix flake check), legacyPackages is explicitly for nixpkgs and nixpkgs-style attrsets combining packages and functions and sets of packages --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 1a4b4a2..5ed8770 100644 --- a/flake.nix +++ b/flake.nix @@ -12,7 +12,7 @@ pkgs = import inputs.nixpkgs { inherit system; }; lib = pkgs.lib; in { - packages = import ./tf2/packages { + legacyPackages = import ./tf2/packages { inherit pkgs lib; }; }); From 307a217a1b5244dab508e9f42150d40a35fec186 Mon Sep 17 00:00:00 2001 From: Shelvacu Date: Sun, 29 Jun 2025 18:31:37 -0700 Subject: [PATCH 3/5] Expose tf2/packages/default.nix as a function, so a custom nixpkgs instantiation can be provided --- example/flake.nix | 4 ++-- flake.nix | 14 +++++++++----- tf2/packages/default.nix | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/example/flake.nix b/example/flake.nix index fb1cdb6..0ca9829 100644 --- a/example/flake.nix +++ b/example/flake.nix @@ -9,8 +9,8 @@ packages.x86_64-linux.default = let pkgs = import inputs.nixpkgs { system = "x86_64-linux"; }; - tf2pkgs = inputs.tf2-nix.packages.x86_64-linux; - in tf2pkgs.mergeTf2Configs (with tf2pkgs; [ + tf2Pkgs = inputs.tf2-nix.lib.mkTf2Pkgs { inherit pkgs; }; + in tf2Pkgs.mergeTf2Configs (with tf2Pkgs; [ mastercomfig.presets.medium-low mastercomfig.addons.flat-mouse mastercomfig.addons.no-tutorial diff --git a/flake.nix b/flake.nix index 5ed8770..81f054a 100644 --- a/flake.nix +++ b/flake.nix @@ -7,13 +7,17 @@ }; outputs = { self, ... }@inputs: + let + # keep it as an attrset arg for future expandability + mkTf2Pkgs = { pkgs }: import ./tf2/packages { inherit pkgs; }; + in inputs.flake-utils.lib.eachDefaultSystem (system: let pkgs = import inputs.nixpkgs { inherit system; }; - lib = pkgs.lib; in { - legacyPackages = import ./tf2/packages { - inherit pkgs lib; - }; - }); + legacyPackages = mkTf2Pkgs pkgs; + }) + // { + lib = { inherit mkTf2Pkgs; }; + }; } diff --git a/tf2/packages/default.nix b/tf2/packages/default.nix index fe4003d..7ab0e1b 100644 --- a/tf2/packages/default.nix +++ b/tf2/packages/default.nix @@ -1,6 +1,8 @@ -{ pkgs, lib }: +{ pkgs }: let + inherit (pkgs) lib; + mkTf2Config = pkgs.callPackage ../mkTf2Config.nix {}; fetchFromGameBanana = From 1b2a146025b0a685d68a2fb9dc7dceced0be2474 Mon Sep 17 00:00:00 2001 From: Shelvacu Date: Sun, 29 Jun 2025 19:03:14 -0700 Subject: [PATCH 4/5] Expose all derivations under packages.* so that `nix flake check` checks something useful --- flake.nix | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 81f054a..4c17f0a 100644 --- a/flake.nix +++ b/flake.nix @@ -14,8 +14,23 @@ inputs.flake-utils.lib.eachDefaultSystem (system: let pkgs = import inputs.nixpkgs { inherit system; }; + inherit (pkgs) lib; + tf2Pkgs = mkTf2Pkgs { inherit pkgs; }; in { - legacyPackages = mkTf2Pkgs pkgs; + legacyPackages = tf2Pkgs; + packages = lib.mergeAttrsList (lib.flip map [ + [] + [ "huds" ] + [ "maps" ] + [ "mastercomfig" "addons" ] + [ "mastercomfig" "presets" ] + ] (attrPath: + lib.pipe tf2Pkgs [ + (lib.getAttrFromPath attrPath) + (lib.filterAttrs (_: v: lib.isDerivation v)) + (lib.mapAttrs' (k: v: lib.nameValuePair (lib.concatStringsSep "_" (attrPath ++ [k])) v)) + ] + )); }) // { lib = { inherit mkTf2Pkgs; }; From 61c63737af14fad729f4e9af2260a046d1111a35 Mon Sep 17 00:00:00 2001 From: Shelvacu Date: Sun, 29 Jun 2025 19:16:52 -0700 Subject: [PATCH 5/5] Fix mkTf2Config derivation names ending with a dash - Also changed some of the source derivation names to keep our sanity --- tf2/mkTf2Config.nix | 3 ++- tf2/packages/huds/extras.nix | 2 +- tf2/packages/huds/hud-db/default.nix | 2 +- tf2/packages/maps/jump-academy/default.nix | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tf2/mkTf2Config.nix b/tf2/mkTf2Config.nix index 0a8138c..e7271a9 100644 --- a/tf2/mkTf2Config.nix +++ b/tf2/mkTf2Config.nix @@ -1,7 +1,7 @@ { stdenv, lib }: { pname -, version ? "" +, version ? null , custom ? [] , cfg ? [] , maps ? [] @@ -35,6 +35,7 @@ let then { src = builtins.head allSrcs; } else { srcs = allSrcs; sourceRoot = "."; }; in stdenv.mkDerivation ({ + inherit name; inherit pname version; # Adapted from stdenv's _defaultUnpack(). unpackCmd = '' diff --git a/tf2/packages/huds/extras.nix b/tf2/packages/huds/extras.nix index 2290f5d..b765111 100644 --- a/tf2/packages/huds/extras.nix +++ b/tf2/packages/huds/extras.nix @@ -5,7 +5,7 @@ pname = "deerhud"; custom = [ (fetchFromGitHub { - name = "deerhud"; + name = "deerhud-src"; owner = "DeerUwU"; repo = "deerhud-tf2"; rev = "78a24effbc66bc78b4bb557228eaa0195db3270c"; diff --git a/tf2/packages/huds/hud-db/default.nix b/tf2/packages/huds/hud-db/default.nix index 323b285..27f98c1 100644 --- a/tf2/packages/huds/hud-db/default.nix +++ b/tf2/packages/huds/hud-db/default.nix @@ -6,7 +6,7 @@ builtins.mapAttrs env.description = e.description; custom = [ (fetchFromGitHub (builtins.removeAttrs e.src ["__type"] // { - inherit name; + name = "${name}-src"; })) ]; }) diff --git a/tf2/packages/maps/jump-academy/default.nix b/tf2/packages/maps/jump-academy/default.nix index 131c22b..40e8ef8 100644 --- a/tf2/packages/maps/jump-academy/default.nix +++ b/tf2/packages/maps/jump-academy/default.nix @@ -6,6 +6,7 @@ builtins.mapAttrs env.description = e.description; maps = [ (fetchurl { + name = "${name}-src"; inherit (e.src) url hash; }) ];