-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
156 lines (135 loc) · 4.65 KB
/
flake.nix
File metadata and controls
156 lines (135 loc) · 4.65 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{
description = "opsops - SOPS(-Nix) Goodies";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs =
inputs@{ nixpkgs, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
./nix/flake-modules/read-yaml
];
systems = nixpkgs.lib.systems.flakeExposed;
perSystem =
{
config,
self',
inputs',
pkgs,
system,
readYAML,
...
}:
let
## Read package information:
package = readYAML ./package.yaml;
## Get our Haskell:
thisHaskell = pkgs.haskellPackages.override {
overrides = self: super: {
${package.name} = self.callCabal2nix package.name ./. { };
};
};
## Common build inputs for both development and CI environments:
buildInputsCommon = [
## Essential Haskell tools:
thisHaskell.cabal-install
thisHaskell.fourmolu
thisHaskell.hlint
thisHaskell.hpack
thisHaskell.stan
thisHaskell.weeder
## Other essentials:
pkgs.git
pkgs.nixfmt-rfc-style
pkgs.prettier
pkgs.shellcheck
pkgs.shfmt
pkgs.statix
pkgs.taplo
## Our development scripts:
(pkgs.callPackage ./nix/cabal-verify { })
];
## Development-only inputs:
buildInputsDevOnly = [
## Haskell development tools:
thisHaskell.haskell-language-server
thisHaskell.cabal-fmt
thisHaskell.cabal2nix
## Other development tools:
pkgs.docker-client
pkgs.nil
];
## Development shell:
devShell = thisHaskell.shellFor {
packages = p: [ p.${package.name} ];
withHoogle = false;
buildInputs = buildInputsCommon ++ buildInputsDevOnly;
};
## CI shell (minimal, fast):
ciShell = thisHaskell.shellFor {
packages = p: [ p.${package.name} ];
withHoogle = false;
buildInputs = buildInputsCommon;
};
thisPackage = pkgs.haskell.lib.justStaticExecutables (
thisHaskell.${package.name}.overrideAttrs (oldAttrs: {
nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ]) ++ [
pkgs.git
pkgs.installShellFiles
pkgs.makeWrapper
pkgs.ronn
];
postFixup = (oldAttrs.postFixup or "") + ''
## Create output directories:
mkdir -p $out/{bin}
## Wrap program to add PATHs to dependencies:
wrapProgram $out/bin/${package.name} --prefix PATH : ${
pkgs.lib.makeBinPath [
pkgs.bashInteractive # Added for bash-based CLI option completions
]
}
## Install completion scripts:
installShellCompletion --bash --name ${package.name}.bash <($out/bin/${package.name} --bash-completion-script "$out/bin/${package.name}")
installShellCompletion --fish --name ${package.name}.fish <($out/bin/${package.name} --fish-completion-script "$out/bin/${package.name}")
installShellCompletion --zsh --name _${package.name} <($out/bin/${package.name} --zsh-completion-script "$out/bin/${package.name}")
'';
})
);
thisDocker = pkgs.dockerTools.buildImage {
name = "${package.name}";
tag = "v${package.version}";
created = "now";
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [ pkgs.cacert ];
pathsToLink = [ "/etc" ];
};
runAsRoot = ''
#!${pkgs.runtimeShell}
${pkgs.dockerTools.shadowSetup}
groupadd -r users
useradd -r -g users patron
'';
config = {
User = "patron";
Entrypoint = [ "${thisPackage}/bin/${package.name}" ];
Cmd = null;
};
};
in
{
## Project packages output:
packages = {
"${package.name}" = thisPackage;
docker = thisDocker;
default = thisPackage;
};
## Project development shells:
devShells = {
default = devShell;
ci = ciShell;
};
};
};
}