forked from open-component-model/ocm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
127 lines (108 loc) · 4.27 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
121
122
123
124
125
126
127
{
description = "Nix flake for ocm";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; # doesn
};
outputs = { self, nixpkgs, ... }:
let
pname = "ocm";
# System types to support.
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
in
{
# Provide some binary packages for selected system types.
packages = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
inherit (pkgs) stdenv lib ;
in
{
${pname} = pkgs.buildGoModule.override { go = pkgs.go_1_23; } rec {
inherit pname self;
version = lib.fileContents ./VERSION;
gitCommit = if (self ? rev) then self.rev else self.dirtyRev;
state = if (self ? rev) then "clean" else "dirty";
# This vendorHash represents a derivative of all go.mod dependencies and needs to be adjusted with every change
vendorHash = "sha256-0jxArvCync+cw/gyyKPu4AQBnCvLdA28yFzPXvg0mxQ=";
src = ./.;
ldflags = [
"-s" "-w"
"-X ocm.software/ocm/api/version.gitVersion=${version}"
"-X ocm.software/ocm/api/version.gitTreeState=${state}"
"-X ocm.software/ocm/api/version.gitCommit=${gitCommit}"
# "-X ocm.software/ocm/api/version.buildDate=1970-01-01T0:00:00+0000"
];
CGO_ENABLED = 0;
subPackages = [
"cmds/ocm"
"cmds/helminstaller"
"cmds/demoplugin"
"cmds/ecrplugin"
];
nativeBuildInputs = [ pkgs.installShellFiles ];
postInstall = ''
installShellCompletion --cmd ${pname} \
--zsh <($out/bin/${pname} completion zsh) \
--bash <($out/bin/${pname} completion bash) \
--fish <($out/bin/${pname} completion fish)
'';
meta = with lib; {
description = "Open Component Model (OCM) is an open standard to describe software bills of delivery (SBOD)";
longDescription = ''
OCM is a technology-agnostic and machine-readable format focused on the software artifacts that must be delivered for software products.
The specification is also used to express metadata needed for security, compliance, and certification purpose.
'';
homepage = "https://ocm.software";
license = licenses.asl20;
platforms = supportedSystems;
};
};
});
# Add dependencies that are only needed for development
devShells = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
in
{
default = pkgs.mkShell {
buildInputs = with pkgs; [
go_1_23 # golang 1.23
gopls # go language server
gotools # go imports
go-tools # static checks
gnumake # standard make
];
};
});
# The default package for 'nix build'.
defaultPackage = forAllSystems (system: self.packages.${system}.${pname});
# These are the apps included in the default package.
apps = forAllSystems (system: rec {
${pname} = default;
default = {
type = "app";
program = self.packages.${system}.${pname} + "/bin/ocm";
};
helminstaller = {
type = "app";
program = self.packages.${system}.${pname} + "/bin/helminstaller";
};
demo = {
type = "app";
program = self.packages.${system}.${pname} + "/bin/demoplugin";
};
ecrplugin = {
type = "app";
program = self.packages.${system}.${pname} + "/bin/ecrplugin";
};
});
legacyPackages = forAllSystems (system: rec {
nixpkgs = nixpkgsFor.${system};
});
};
}