forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
95 lines (87 loc) · 2.82 KB
/
flake.nix
File metadata and controls
95 lines (87 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
description = "A basic gomod2nix flake";
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
inputs.gomod2nix.url = "github:nix-community/gomod2nix";
inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.url = "github:nix-systems/default";
outputs =
{
self,
nixpkgs,
gomod2nix,
systems,
}:
let
eachSystem =
f:
nixpkgs.lib.genAttrs (import systems) (
system:
f rec {
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
gomod2nixPkgs = gomod2nix.legacyPackages.${system};
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
}
);
in
{
packages = eachSystem ({ callPackage, gomod2nixPkgs, ... }: {
default = callPackage ./. { inherit (gomod2nixPkgs) buildGoApplication; };
}
);
devShells = eachSystem ({ callPackage, gomod2nixPkgs, ... }: {
default = callPackage ./shell.nix { inherit (gomod2nixPkgs) mkGoEnv gomod2nix; };
}
);
checks = eachSystem ({ pkgs, system, ... }:
let
sourceFiles = pkgs.lib.fileset.toSource {
root = ./.;
fileset = pkgs.lib.fileset.unions [
./go.mod
./go.sum
./GNUmakefile
./stdlib.sh
./version.txt
./README.md
(pkgs.lib.fileset.fileFilter (file: file.hasExt "go") ./.)
./test
./internal
./pkg
(pkgs.lib.fileset.fileFilter (file: file.name == ".envrc") ./.)
];
};
in {
package = self.packages.${system}.default;
tests = self.packages.${system}.default.overrideAttrs (old: {
src = sourceFiles;
nativeBuildInputs = (old.nativeBuildInputs or []) ++ self.devShells.${system}.default.nativeBuildInputs;
buildPhase = ''
export GOLANGCI_LINT_CACHE=$TMPDIR/golangci-cache
export XDG_CACHE_HOME=$TMPDIR/cache
export HOME=$TMPDIR/home
mkdir -p $GOLANGCI_LINT_CACHE $XDG_CACHE_HOME $HOME
# Patch shebangs in test files
patchShebangs test/
make test
'';
installPhase = ''
mkdir -p $out
touch $out/tests-passed
'';
});
dist = self.packages.${system}.default.overrideAttrs (old: {
src = sourceFiles;
nativeBuildInputs = (old.nativeBuildInputs or []) ++ self.devShells.${system}.default.nativeBuildInputs;
buildPhase = ''
make dist
'';
installPhase = ''
mkdir -p $out
cp -r dist/* $out/
'';
});
}
);
};
}