Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose flake interface that does not rely on overlays #124

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pkgs.buildGoApplication {

The quickest way to get started if using Nix Flakes is to use the Flake template:
``` bash
$ nix flake init -t github:tweag/gomod2nix#app
$ nix flake init -t github:nix-community/gomod2nix#app
```

## Basic usage
Expand Down
38 changes: 28 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 24 additions & 11 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
description = "Convert go.mod/go.sum to Nix packages";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/master";
inputs.flake-utils.url = "github:numtide/flake-utils";

inputs.utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, utils }:
outputs = { self, nixpkgs, flake-utils }:
{
overlays.default = import ./overlay.nix;

Expand All @@ -18,19 +17,33 @@
defaultTemplate = self.templates.app;

} //
(utils.lib.eachDefaultSystem
(flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
self.overlays.default
];
pkgs = nixpkgs.legacyPackages.${system};

# The current default sdk for macOS fails to compile go projects, so we use a newer one for now.
# This has no effect on other platforms.
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;
};
})
);
}
4 changes: 2 additions & 2 deletions overlay.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
final: prev:
let
# The newer Darwin SDK does not exist in current (nixos-22.05) stable
# branches, so just fallback to the default callPackage.
# The current default sdk for macOS fails to compile go projects, so we use a newer one for now.
# This has no effect on other platforms.
callPackage = final.darwin.apple_sdk_11_0.callPackage or final.callPackage;
in
{
Expand Down
6 changes: 4 additions & 2 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
];
}
)
, gomod2nix ? pkgs.gomod2nix
, mkGoEnv ? pkgs.mkGoEnv
}:

pkgs.mkShell {
NIX_PATH = "nixpkgs=${builtins.toString pkgs.path}";
nativeBuildInputs = [
pkgs.nixpkgs-fmt
pkgs.golangci-lint
pkgs.gomod2nix
(pkgs.mkGoEnv { pwd = ./.; })
gomod2nix
(mkGoEnv { pwd = ./.; })
];
}
3 changes: 2 additions & 1 deletion templates/app/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
];
}
)
, buildGoApplication ? pkgs.buildGoApplication
}:

pkgs.buildGoApplication {
buildGoApplication {
pname = "myapp";
version = "0.1";
pwd = ./.;
Expand Down
18 changes: 12 additions & 6 deletions templates/app/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.gomod2nix.url = "github:nix-community/gomod2nix";
inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils";

outputs = { self, nixpkgs, flake-utils, gomod2nix }:
(flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ gomod2nix.overlays.default ];
};
pkgs = nixpkgs.legacyPackages.${system};

# The current default sdk for macOS fails to compile go projects, so we use a newer one for now.
# This has no effect on other platforms.
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
in
{
packages.default = pkgs.callPackage ./. { };
devShells.default = import ./shell.nix { inherit pkgs; };
packages.default = callPackage ./. {
inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
};
devShells.default = callPackage ./shell.nix {
inherit (gomod2nix.legacyPackages.${system}) buildGoApplication mkGoEnv gomod2nix;
};
})
);
}
6 changes: 4 additions & 2 deletions templates/app/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
}