forked from peterldowns/nix-search-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
100 lines (91 loc) · 3.28 KB
/
flake.nix
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
96
97
98
99
100
{
description = "CLI for searching packages on search.nixos.org";
inputs = {
nixpkgs.url = github:nixos/nixpkgs/nixos-unstable;
flake-utils.url = github:numtide/flake-utils;
flake-compat.url = github:edolstra/flake-compat;
flake-compat.flake = false;
gomod2nix.url = "github:nix-community/gomod2nix";
gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
gomod2nix.inputs.utils.follows = "flake-utils";
};
outputs = inputs@{ ... }:
inputs.flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [
inputs.gomod2nix.overlays.default
];
pkgs = import inputs.nixpkgs {
inherit system overlays;
};
in
rec {
packages = rec {
nix-search = pkgs.buildGoApplication {
pname = "nix-search-cli";
version = "0.1.0";
src = ./.;
modules = ./gomod2nix.toml;
};
default = nix-search;
};
apps = rec {
nix-search = {
type = "app";
program = "${packages.nix-search}/bin/nix-search";
};
default = nix-search;
};
devShells = rec {
default = pkgs.mkShell {
packages = with pkgs; [
## golang
delve
go-outline
go
golangci-lint
gopkgs
gopls
gotools
## nix
gomod2nix
rnix-lsp
nixpkgs-fmt
## other tools
just
];
shellHook = ''
# The path to this repository
if [ -z $WORKSPACE_ROOT ]; then
shell_nix="''${IN_LORRI_SHELL:-$(pwd)/shell.nix}"
workspace_root=$(dirname "$shell_nix")
export WORKSPACE_ROOT="$workspace_root"
fi
# We put the $GOPATH/$GOCACHE/$GOENV in $TOOLCHAIN_ROOT,
# and ensure that the GOPATH's bin dir is on our PATH so tools
# can be installed with `go install`.
#
# Any tools installed explicitly with `go install` will take precedence
# over versions installed by Nix due to the ordering here.
export TOOLCHAIN_ROOT="$WORKSPACE_ROOT/.toolchain"
export GOROOT=
export GOCACHE="$TOOLCHAIN_ROOT/go/cache"
export GOENV="$TOOLCHAIN_ROOT/go/env"
export GOPATH="$TOOLCHAIN_ROOT/go/path"
export GOMODCACHE="$GOPATH/pkg/mod"
export PATH=$(go env GOPATH)/bin:$PATH
# This project is pure go and does not need CGO. We disable it
# here as well as in the Dockerfile and nix build scripts.
export CGO_ENABLED=0
'';
# Need to disable fortify hardening because GCC is not built with -oO,
# which means that if CGO_ENABLED=1 (which it is by default) then the golang
# debugger fails.
# see https://github.com/NixOS/nixpkgs/pull/12895/files
hardeningDisable = [ "fortify" ];
};
};
}
);
}