-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add typed models for projects #507
base: main
Are you sure you want to change the base?
Changes from all commits
2ae638b
f66914d
0a26ef9
e753965
caea93e
36737d1
2acc591
3f1460b
c0ff4c2
ef50087
88c0826
0cb805c
f7665de
d4a6880
078bb72
71d2c13
3368459
b4e7fc3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,128 @@ | ||||||
{ | ||||||
lib, | ||||||
pkgs, | ||||||
sources, | ||||||
}: | ||||||
let | ||||||
yants = import sources.yants { }; | ||||||
|
||||||
inherit (yants) | ||||||
string | ||||||
list | ||||||
option | ||||||
attrs | ||||||
enum | ||||||
either | ||||||
struct | ||||||
drv | ||||||
path | ||||||
restrict | ||||||
; | ||||||
|
||||||
programType = struct "program" { | ||||||
name = string; | ||||||
source = drv; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We decided programs should also be NixOS modules (
Suggested change
|
||||||
documentation = optionalStruct { | ||||||
build = option string; | ||||||
tests = option string; | ||||||
}; | ||||||
examples = nonEmtpyAttrs (option exampleType); | ||||||
}; | ||||||
|
||||||
serviceType = struct "service" { | ||||||
name = string; | ||||||
documentation = optionalStruct { | ||||||
config = option string; | ||||||
}; | ||||||
examples = nonEmtpyAttrs (option exampleType); | ||||||
}; | ||||||
|
||||||
exampleType = struct "example" { | ||||||
description = option string; # TODO: should this be non-optional? | ||||||
path = either string path; | ||||||
eljamm marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
documentation = option string; | ||||||
tests = nonEmtpyAttrs drv; | ||||||
}; | ||||||
|
||||||
optionalStruct = attrs: option (struct attrs); | ||||||
nonEmtpyAttrs = t: restrict "non-empty-attrs" (a: a != { }) (attrs t); | ||||||
in | ||||||
rec { | ||||||
project = struct { | ||||||
name = string; | ||||||
metadata = optionalStruct { | ||||||
summary = option string; | ||||||
subgrants = list string; | ||||||
}; | ||||||
nixos = struct "nixos" { | ||||||
examples = option (attrs exampleType); | ||||||
tests = option (attrs (option drv)); | ||||||
modules = struct "modules" { | ||||||
programs = option (attrs (option programType)); | ||||||
services = option (attrs (option serviceType)); | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
|
||||||
example = project { | ||||||
name = "foobar"; | ||||||
nixos = rec { | ||||||
examples = { | ||||||
foobar-cli = { | ||||||
description = '' | ||||||
This is how you can run `foobar` in the terminal. | ||||||
''; | ||||||
path = ""; | ||||||
documentation = "https://foo.bar/docs"; | ||||||
tests = { | ||||||
# Each example must have at least one test. | ||||||
# If the line below is commented out, an error will be raised. | ||||||
inherit (tests) foobar-cli; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
tests = { | ||||||
# Set to `null`: needed, but not available | ||||||
basic = null; | ||||||
|
||||||
# Needs to be a derivation. Error raised otherwise. | ||||||
#simple = "This will fail."; | ||||||
|
||||||
foobar-cli = derivation { | ||||||
name = "myname"; | ||||||
builder = "mybuilder"; | ||||||
system = "mysystem"; | ||||||
}; | ||||||
}; | ||||||
modules = { | ||||||
# Attributes not defined in the data structure are not allowed. | ||||||
# Uncommenting the line below will raise an error. | ||||||
#hello = { }; | ||||||
|
||||||
programs = { | ||||||
# Set to `null`: needed, but not available | ||||||
foobar = null; | ||||||
|
||||||
foobar-cli = { | ||||||
name = "foobar-cli"; | ||||||
source = derivation { | ||||||
name = "foobar-cli-src"; | ||||||
builder = "mybuilder"; | ||||||
system = "mysystem"; | ||||||
}; | ||||||
# Each program must have at least one example. | ||||||
# Examples can be null to indicate that they're needed. | ||||||
examples = { | ||||||
inherit (examples) foobar-cli; | ||||||
|
||||||
# needed, not available | ||||||
foobar-tui = null; | ||||||
}; | ||||||
}; | ||||||
|
||||||
# Not set: not needed | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the need for a human-readable name yet, so we could leave that optional.