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.
This commit is contained in:
Jörg Thalheim 2023-09-13 07:43:01 +02:00
parent 3cbf3a51fe
commit cf42f710c1
5 changed files with 38 additions and 19 deletions

View file

@ -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;
};
})
);
}

View file

@ -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 = ./.; })
];
}

View file

@ -9,9 +9,10 @@
];
}
)
, buildGoApplication ? pkgs.buildGoApplication
}:
pkgs.buildGoApplication {
buildGoApplication {
pname = "myapp";
version = "0.1";
pwd = ./.;

View file

@ -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;
};
})
);
}

View file

@ -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
];
}