-
Notifications
You must be signed in to change notification settings - Fork 7
/
flake.nix
113 lines (110 loc) · 3.56 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
101
102
103
104
105
106
107
108
109
110
111
112
113
{
description = "General purpose file previewer designed for Ranger, Lf to make scope.sh redundant";
# To make user overrides of the nixpkgs flake not take effect
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
# https://nixos.wiki/wiki/Flakes#Using_flakes_project_from_a_legacy_Nix
inputs.flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
inputs.gomod2nix = {
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
inputs.gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self
, nixpkgs
, flake-utils
, flake-compat
, gitignore
, gomod2nix
}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
gomod2nix.overlays.default
];
};
inherit (gitignore.lib) gitignoreFilterWith;
# https://discourse.nixos.org/t/passing-git-commit-hash-and-tag-to-build-with-flakes/11355/2
version_rev = if (self ? rev) then (builtins.substring 0 8 self.rev) else "dirty";
version = "${pkgs.lib.fileContents ./VERSION}-${version_rev}-flake";
# Used also in the devShell
MAGIC_DB = "${pkgs.pkgsStatic.file}/share/misc/magic.mgc";
src = pkgs.lib.cleanSourceWith {
filter = gitignoreFilterWith {
basePath = ./.;
extraRules = ''
### Nix related
flake*
*.nix
.envrc
.direnv
### Makefile related files
./Makefile
./newVersionFile
./newTag
./releaseAssets
./releaseAssetsUploaded
# built by go build or simply with `make`
./pistol
./pistol.1
./README.html
# Evaluated here in this flake.nix but not used for the build itself
VERSION
### CI files
renovate.json5
### Git files
.gitignore
'';
};
src = ./.;
};
pkgArgs = {
inherit version src;
};
pistol = pkgs.callPackage ./pkg.nix pkgArgs;
pistol-static-native = pkgs.pkgsStatic.callPackage ./pkg.nix pkgArgs;
pistol-static-linux-x86_64 = pkgs.pkgsCross.gnu64.pkgsStatic.callPackage ./pkg.nix pkgArgs;
pistol-static-linux-aarch64 = pkgs.pkgsCross.aarch64-multiplatform-musl.pkgsStatic.callPackage ./pkg.nix pkgArgs;
pistol-static-linux-armv7l = pkgs.pkgsCross.armv7l-hf-multiplatform.pkgsStatic.callPackage ./pkg.nix pkgArgs;
pistol-static-linux-arm = pkgs.pkgsCross.arm-embedded.pkgsStatic.callPackage ./pkg.nix pkgArgs;
in {
devShell = pkgs.mkShell {
nativeBuildInputs = [
pkgs.go
pkgs.file
# For make check
pkgs.elinks
pkgs.gomod2nix
];
# Only useful if I need to play with static compilation out side of
# Nix, mostly it is never used.
inherit MAGIC_DB;
};
packages = {
inherit
pistol
pistol-static-native
pistol-static-linux-x86_64
pistol-static-linux-aarch64
pistol-static-linux-armv7l
#pistol-static-linux-arm # Currently broken
;
};
defaultPackage = pistol;
apps.pistol = {
type = "app";
program = "${pistol}/bin/pistol";
};
defaultApp = self.apps.${system}.pistol;
}
);
}