Skip to content

Commit 6024f11

Browse files
committed
all the pieces
1 parent 2550312 commit 6024f11

File tree

9 files changed

+119
-0
lines changed

9 files changed

+119
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
result
2+
gohello

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.PHONY: build
2+
build:
3+
go build
4+
5+
.PHONY: nix
6+
nix:
7+
nix-build -A gohello
8+
9+
.PHONY: shell
10+
shell:
11+
nix-shell
12+
13+
.PHONY: nixpin
14+
nixpin:
15+
#nix-shell -p npins --run "npins init"
16+
nix-shell --run "npins update"
17+
18+
.PHONY: nixfmt
19+
nixfmt:
20+
nix-shell --run "nixfmt *.nix"
21+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tiny Go program to test some build infrastructure. Uses Nix with npins for the build setup.

default.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
let
2+
sources = import ./npins/default.nix;
3+
pkgs = import sources.nixpkgs { };
4+
in
5+
{
6+
gohello = pkgs.buildGoModule {
7+
name = "gohello";
8+
# buildInputs = [ gocache ];
9+
src = pkgs.lib.sourceByRegex ./. [
10+
"go.(mod|sum)"
11+
".*\.go"
12+
];
13+
vendorHash = null; # uses ./vendor/
14+
doCheck = false;
15+
};
16+
17+
shell = pkgs.mkShellNoCC {
18+
packages = [
19+
pkgs.nixfmt-rfc-style
20+
pkgs.npins
21+
];
22+
};
23+
}

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/alicebob/gohello
2+
3+
go 1.22.0

main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func main() {
9+
fmt.Printf("Hello %s!\n", os.Getenv("USER"))
10+
}

npins/default.nix

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Generated by npins. Do not modify; will be overwritten regularly
2+
let
3+
data = builtins.fromJSON (builtins.readFile ./sources.json);
4+
version = data.version;
5+
6+
mkSource = spec:
7+
assert spec ? type; let
8+
path =
9+
if spec.type == "Git" then mkGitSource spec
10+
else if spec.type == "GitRelease" then mkGitSource spec
11+
else if spec.type == "PyPi" then mkPyPiSource spec
12+
else if spec.type == "Channel" then mkChannelSource spec
13+
else builtins.throw "Unknown source type ${spec.type}";
14+
in
15+
spec // { outPath = path; };
16+
17+
mkGitSource = { repository, revision, url ? null, hash, ... }:
18+
assert repository ? type;
19+
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
20+
# In the latter case, there we will always be an url to the tarball
21+
if url != null then
22+
(builtins.fetchTarball {
23+
inherit url;
24+
sha256 = hash; # FIXME: check nix version & use SRI hashes
25+
})
26+
else assert repository.type == "Git"; builtins.fetchGit {
27+
url = repository.url;
28+
rev = revision;
29+
# hash = hash;
30+
};
31+
32+
mkPyPiSource = { url, hash, ... }:
33+
builtins.fetchurl {
34+
inherit url;
35+
sha256 = hash;
36+
};
37+
38+
mkChannelSource = { url, hash, ... }:
39+
builtins.fetchTarball {
40+
inherit url;
41+
sha256 = hash;
42+
};
43+
in
44+
if version == 3 then
45+
builtins.mapAttrs (_: mkSource) data.pins
46+
else
47+
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"

npins/sources.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"pins": {
3+
"nixpkgs": {
4+
"type": "Channel",
5+
"name": "nixos-24.05",
6+
"url": "https://releases.nixos.org/nixos/24.05/nixos-24.05.556.fafeae3d248c/nixexprs.tar.xz",
7+
"hash": "1r06n8gq6ikm89svq95lq6s3p4aiv625wl46ncfdgv804p1fc9zs"
8+
}
9+
},
10+
"version": 3
11+
}

shell.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(import ./.).shell

0 commit comments

Comments
 (0)