Merge pull request #47 from adisbladis/flake-template

templates: Add a flake template
This commit is contained in:
adisbladis 2022-05-30 19:21:37 +08:00 committed by GitHub
commit 90653f16ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 71 additions and 1 deletions

View file

@ -5,7 +5,11 @@ buildGoApplication {
pname = "gomod2nix";
version = "0.1";
src = lib.cleanSourceWith {
filter = name: type: (! lib.hasSuffix "tests" name) && (! lib.hasSuffix "builder" name);
filter = name: type: builtins.foldl' (v: s: v && ! lib.hasSuffix s name) true [
"tests"
"builder"
"templates"
];
src = lib.cleanSource ./.;
};
modules = ./gomod2nix.toml;

View file

@ -8,6 +8,15 @@
outputs = { self, nixpkgs, utils }:
{
overlays.default = import ./overlay.nix;
templates = {
app = {
path = ./templates/app;
description = "Gomod2nix packaged application";
};
};
defaultTemplate = self.templates.app;
} //
(utils.lib.eachDefaultSystem
(system:

1
templates/app/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/gomod2nix-template

10
templates/app/default.nix Normal file
View file

@ -0,0 +1,10 @@
{ buildGoApplication, go, lib }:
buildGoApplication {
inherit go;
pname = "myapp";
version = "0.1";
src = ./.;
modules = ./gomod2nix.toml;
subPackages = [ "." ];
}

23
templates/app/flake.nix Normal file
View file

@ -0,0 +1,23 @@
{
description = "A basic gomod2nix flake";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.gomod2nix.url = "github:tweag/gomod2nix";
outputs = { self, nixpkgs, flake-utils, gomod2nix }:
(flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ gomod2nix.overlays.default ];
};
in
{
packages.default = pkgs.callPackage ./. { };
devShells.default = import ./shell.nix { inherit pkgs; };
})
);
}

3
templates/app/go.mod Normal file
View file

@ -0,0 +1,3 @@
module example.com/gomod2nix-template
go 1.17

View file

@ -0,0 +1,3 @@
schema = 1
[mod]

9
templates/app/main.go Normal file
View file

@ -0,0 +1,9 @@
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello flake")
}

8
templates/app/shell.nix Normal file
View file

@ -0,0 +1,8 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
packages = [
pkgs.go
pkgs.gomod2nix
];
}