This repository has been archived by the owner on Aug 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
flake.nix
120 lines (89 loc) · 3.38 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
114
115
116
117
118
119
120
{
description = "(insert short project description here)";
# Nixpkgs / NixOS version to use.
inputs.nixpkgs.url = "nixpkgs/nixos-20.09";
# Upstream source tree(s).
inputs.hello-src = { url = git+https://git.savannah.gnu.org/git/hello.git; flake = false; };
inputs.gnulib-src = { url = git+https://git.savannah.gnu.org/git/gnulib.git; flake = false; };
outputs = { self, nixpkgs, hello-src, gnulib-src }:
let
# Generate a user-friendly version numer.
version = builtins.substring 0 8 hello-src.lastModifiedDate;
# System types to support.
supportedSystems = [ "x86_64-linux" ];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; });
in
{
# A Nixpkgs overlay.
overlay = final: prev: {
hello = with final; stdenv.mkDerivation rec {
name = "hello-${version}";
src = hello-src;
buildInputs = [ autoconf automake gettext gnulib perl gperf texinfo help2man ];
preConfigure = ''
mkdir -p .git # force BUILD_FROM_GIT
./bootstrap --gnulib-srcdir=${gnulib-src} --no-git --skip-po
'';
meta = {
homepage = "https://www.gnu.org/software/hello/";
description = "A program to show a familiar, friendly greeting";
};
};
};
# Provide some binary packages for selected system types.
packages = forAllSystems (system:
{
inherit (nixpkgsFor.${system}) hello;
});
# The default package for 'nix build'. This makes sense if the
# flake provides only one package or there is a clear "main"
# package.
defaultPackage = forAllSystems (system: self.packages.${system}.hello);
# A NixOS module, if applicable (e.g. if the package provides a system service).
nixosModules.hello =
{ pkgs, ... }:
{
nixpkgs.overlays = [ self.overlay ];
environment.systemPackages = [ pkgs.hello ];
#systemd.services = { ... };
};
# Tests run by 'nix flake check' and by Hydra.
checks = forAllSystems (system: {
inherit (self.packages.${system}) hello;
# Additional tests, if applicable.
test =
with nixpkgsFor.${system};
stdenv.mkDerivation {
name = "hello-test-${version}";
buildInputs = [ hello ];
unpackPhase = "true";
buildPhase = ''
echo 'running some integration tests'
[[ $(hello) = 'Hello, world!' ]]
'';
installPhase = "mkdir -p $out";
};
# A VM test of the NixOS module.
vmTest =
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
inherit system;
};
makeTest {
nodes = {
client = { ... }: {
imports = [ self.nixosModules.hello ];
};
};
testScript =
''
start_all()
client.wait_for_unit("multi-user.target")
client.succeed("hello")
'';
};
});
};
}