Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fix-recursive-sym…
Browse files Browse the repository at this point in the history
…linker
  • Loading branch information
xhalo32 committed Oct 31, 2023
2 parents 1ddc17b + f95720e commit 00c8e2f
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 35 deletions.
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
];
}

0 comments on commit 00c8e2f

Please sign in to comment.