From 0ae421c265e665fc6621337b0c1216e548293690 Mon Sep 17 00:00:00 2001 From: seth Date: Tue, 20 Aug 2024 02:58:55 -0400 Subject: [PATCH] chore(nix): drop flake-parts The primary goals here include making the flake easier to contribute to by having it follow the standard boilerplate, while also limiting the size of our flake.lock to lower the chance of duplicate inputs for users Signed-off-by: seth --- flake.lock | 21 -------- flake.nix | 75 ++++++++++++++++++++------ nix/README.md | 10 +++- nix/dev.nix | 15 ------ nix/distribution.nix | 31 ----------- nix/{pkg/default.nix => unwrapped.nix} | 4 +- nix/{pkg => }/wrapper.nix | 0 7 files changed, 69 insertions(+), 87 deletions(-) delete mode 100644 nix/dev.nix delete mode 100644 nix/distribution.nix rename nix/{pkg/default.nix => unwrapped.nix} (97%) rename nix/{pkg => }/wrapper.nix (100%) diff --git a/flake.lock b/flake.lock index 3e9cd8e42..7d21aad14 100644 --- a/flake.lock +++ b/flake.lock @@ -16,26 +16,6 @@ "type": "github" } }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1722555600, - "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, "libnbtplusplus": { "flake": false, "locked": { @@ -71,7 +51,6 @@ "root": { "inputs": { "flake-compat": "flake-compat", - "flake-parts": "flake-parts", "libnbtplusplus": "libnbtplusplus", "nixpkgs": "nixpkgs" } diff --git a/flake.nix b/flake.nix index d64874e30..24227aca7 100644 --- a/flake.nix +++ b/flake.nix @@ -8,10 +8,7 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - flake-parts = { - url = "github:hercules-ci/flake-parts"; - inputs.nixpkgs-lib.follows = "nixpkgs"; - }; + libnbtplusplus = { url = "github:PrismLauncher/libnbtplusplus"; flake = false; @@ -39,18 +36,64 @@ }; outputs = - inputs: - inputs.flake-parts.lib.mkFlake { inherit inputs; } { - imports = [ - ./nix/dev.nix - ./nix/distribution.nix - ]; + { + self, + nixpkgs, + libnbtplusplus, + ... + }: + let + inherit (nixpkgs) lib; - systems = [ - "x86_64-linux" - "aarch64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; + # While we only officially support aarch and x86_64 on Linux and MacOS, + # we expose a reasonable amount of other systems for users who want to + # build for most exotic platforms + systems = lib.systems.flakeExposed; + + forAllSystems = lib.genAttrs systems; + nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); + in + { + devShells = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + in + { + default = pkgs.mkShell { + inputsFrom = [ self.packages.${system}.prismlauncher-unwrapped ]; + buildInputs = with pkgs; [ + ccache + ninja + ]; + }; + } + ); + + formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); + + overlays.default = + final: prev: + let + version = builtins.substring 0 8 self.lastModifiedDate or "dirty"; + in + { + prismlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix { inherit libnbtplusplus version; }; + + prismlauncher = final.callPackage ./nix/wrapper.nix { }; + }; + + packages = forAllSystems ( + system: + let + pkgs = nixpkgsFor.${system}; + + prismPackages = lib.makeScope pkgs.newScope (final: self.overlays.default final pkgs); + in + { + inherit (prismPackages) prismlauncher-unwrapped prismlauncher; + default = prismPackages.prismlauncher; + } + ); }; } diff --git a/nix/README.md b/nix/README.md index 2daeb73d3..d6068a968 100644 --- a/nix/README.md +++ b/nix/README.md @@ -44,11 +44,14 @@ Example: # Optional: Override the nixpkgs input of prismlauncher to use the same revision as the rest of your flake # Note that overriding any input of prismlauncher may break reproducibility # inputs.nixpkgs.follows = "nixpkgs"; + + # This is not required for Flakes + inputs.flake-compat.follows = ""; }; }; outputs = - { nixpkgs, prismlauncher }: + { nixpkgs, prismlauncher, ... }: { nixosConfigurations.foo = nixpkgs.lib.nixosSystem { modules = [ @@ -85,11 +88,14 @@ Example: # Optional: Override the nixpkgs input of prismlauncher to use the same revision as the rest of your flake # Note that overriding any input of prismlauncher may break reproducibility # inputs.nixpkgs.follows = "nixpkgs"; + + # This is not required for Flakes + inputs.flake-compat.follows = ""; }; }; outputs = - { nixpkgs, prismlauncher }: + { nixpkgs, prismlauncher, ... }: { nixosConfigurations.foo = nixpkgs.lib.nixosSystem { modules = [ diff --git a/nix/dev.nix b/nix/dev.nix deleted file mode 100644 index 32b1bd92b..000000000 --- a/nix/dev.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ - perSystem = - { pkgs, self', ... }: - { - devShells.default = pkgs.mkShell { - inputsFrom = [ self'.packages.prismlauncher-unwrapped ]; - buildInputs = with pkgs; [ - ccache - ninja - ]; - }; - - formatter = pkgs.nixfmt-rfc-style; - }; -} diff --git a/nix/distribution.nix b/nix/distribution.nix deleted file mode 100644 index 74e77da1b..000000000 --- a/nix/distribution.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ inputs, self, ... }: -{ - perSystem = - { lib, pkgs, ... }: - { - packages = - let - ourPackages = lib.makeScope pkgs.newScope (final: self.overlays.default final pkgs); - in - { - inherit (ourPackages) prismlauncher-unwrapped prismlauncher; - default = ourPackages.prismlauncher; - }; - }; - - flake = { - overlays.default = - final: prev: - let - version = builtins.substring 0 8 self.lastModifiedDate or "dirty"; - in - { - prismlauncher-unwrapped = prev.callPackage ./pkg { - inherit (inputs) libnbtplusplus; - inherit version; - }; - - prismlauncher = final.callPackage ./pkg/wrapper.nix { }; - }; - }; -} diff --git a/nix/pkg/default.nix b/nix/unwrapped.nix similarity index 97% rename from nix/pkg/default.nix rename to nix/unwrapped.nix index a5a57eaf0..f007c05b8 100644 --- a/nix/pkg/default.nix +++ b/nix/unwrapped.nix @@ -28,9 +28,9 @@ stdenv.mkDerivation { inherit version; src = lib.fileset.toSource { - root = ../../.; + root = ../.; fileset = lib.fileset.unions ( - map (fileName: ../../${fileName}) [ + map (fileName: ../${fileName}) [ "buildconfig" "cmake" "launcher" diff --git a/nix/pkg/wrapper.nix b/nix/wrapper.nix similarity index 100% rename from nix/pkg/wrapper.nix rename to nix/wrapper.nix