From cf42f710c1930163ffb404bd6f489d31705801ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 13 Sep 2023 07:43:01 +0200 Subject: [PATCH] expose flake interface that does not rely on overlays As creator of small tools, my flakes might often end up in other peoples projects. Overlays are a performance problem in those use cases because I would kept re-instantiating nixpkgs instances. Of course I could also expose my stuff as overlays as well. In that case I would need to merge downstream dependencies like go2modnix as well, which would polute their nixpkgs instance with unrelated stuff and also make it harder for my users to tell what random attributes came from which place. --- flake.nix | 28 +++++++++++++++++++++------- shell.nix | 6 ++++-- templates/app/default.nix | 3 ++- templates/app/flake.nix | 14 +++++++------- templates/app/shell.nix | 6 ++++-- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/flake.nix b/flake.nix index 85ee185..aa052e5 100644 --- a/flake.nix +++ b/flake.nix @@ -21,16 +21,30 @@ (utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { - inherit system; - overlays = [ - self.overlays.default - ]; + pkgs = nixpkgs.legacyPackages.${system}; + + # The newer Darwin SDK does not exist in current (nixos-22.05) stable + # branches, so just fallback to the default callPackage. + callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage; + + inherit (callPackage ./builder { + inherit gomod2nix; + }) mkGoEnv buildGoApplication; + gomod2nix = callPackage ./default.nix { + inherit mkGoEnv buildGoApplication; }; in { - packages.default = pkgs.callPackage ./. { }; - devShells.default = import ./shell.nix { inherit pkgs; }; + packages.default = gomod2nix; + legacyPackages = { + # we cannot put them in packages because they are builder functions + inherit mkGoEnv buildGoApplication; + # just have this here for convenience + inherit gomod2nix; + }; + devShells.default = callPackage ./shell.nix { + inherit mkGoEnv gomod2nix; + }; }) ); } diff --git a/shell.nix b/shell.nix index f80d988..f6229c6 100644 --- a/shell.nix +++ b/shell.nix @@ -8,6 +8,8 @@ ]; } ) +, gomod2nix ? pkgs.gomod2nix +, mkGoEnv ? pkgs.mkGoEnv }: pkgs.mkShell { @@ -15,7 +17,7 @@ pkgs.mkShell { nativeBuildInputs = [ pkgs.nixpkgs-fmt pkgs.golangci-lint - pkgs.gomod2nix - (pkgs.mkGoEnv { pwd = ./.; }) + gomod2nix + (mkGoEnv { pwd = ./.; }) ]; } diff --git a/templates/app/default.nix b/templates/app/default.nix index 2c29bbc..14ec4fe 100644 --- a/templates/app/default.nix +++ b/templates/app/default.nix @@ -9,9 +9,10 @@ ]; } ) +, buildGoApplication ? pkgs.buildGoApplication }: -pkgs.buildGoApplication { +buildGoApplication { pname = "myapp"; version = "0.1"; pwd = ./.; diff --git a/templates/app/flake.nix b/templates/app/flake.nix index 824ce7d..1238c4e 100644 --- a/templates/app/flake.nix +++ b/templates/app/flake.nix @@ -9,15 +9,15 @@ (flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { - inherit system; - overlays = [ gomod2nix.overlays.default ]; - }; - + pkgs = nixpkgs.legacyPackages.${system}; in { - packages.default = pkgs.callPackage ./. { }; - devShells.default = import ./shell.nix { inherit pkgs; }; + packages.default = pkgs.callPackage ./. { + inherit (gomod2nix.legacyPackages.${system}) buildGoApplication; + }; + devShells.default = pkgs.callPackage ./shell.nix { + inherit (gomod2nix.legacyPackages.${system}) buildGoApplication mkGoEnv gomod2nix; + }; }) ); } diff --git a/templates/app/shell.nix b/templates/app/shell.nix index b8e49a9..d4f21a8 100644 --- a/templates/app/shell.nix +++ b/templates/app/shell.nix @@ -9,14 +9,16 @@ ]; } ) +, mkGoEnv ? pkgs.mkGoEnv +, gomod2nix ? pkgs.gomod2nix }: let - goEnv = pkgs.mkGoEnv { pwd = ./.; }; + goEnv = mkGoEnv { pwd = ./.; }; in pkgs.mkShell { packages = [ goEnv - pkgs.gomod2nix + gomod2nix ]; }