NixOS Module System | 149 Members | |
| 30 Servers |
| Sender | Message | Time |
|---|---|---|
| 10 Nov 2024 | ||
| 20:02:18 | ||
| I have an option whose default depends on a value defined in the config.
(I'm skipping a few details in the type here, not sure what is important or not).
Here is where the documentation code is evaluating the modules. So I tried changing the default to use I also tried adding a dummy module inside the
But that's not working either š What's working is if I use a hardcoded string for the default value of the options. Here is the PR introducing the changes leading to that error. This Github action shows the error. More specifically, here's the type definition and default setting that causes an issue. On a totally different topic, this PR introduces 2 contracts in the form of structural typing for backing up files and backing up databases. They are both implemented by Restic. The correct implementation of both contracts is enforced by 2 generic NixOS tests (here and here) and then the Restic implementation is verified here and here. | 23:28:04 | |
| * I have an option whose default depends on a value defined in the config.
(I'm skipping a few details in the type here, not sure what is important or not. There's a link to the PR with the full code further down).
Here is where the documentation code is evaluating the modules. So I tried changing the default to use I also tried adding a dummy module inside the
But that's not working either š What's working is if I use a hardcoded string for the default value of the options. Here is the PR introducing the changes leading to that error. This Github action shows the error. More specifically, here's the type definition and default setting that causes an issue. On a totally different topic, this PR introduces 2 contracts in the form of structural typing for backing up files and backing up databases. They are both implemented by Restic. The correct implementation of both contracts is enforced by 2 generic NixOS tests (here and here) and then the Restic implementation is verified here and here. | 23:28:39 | |
| * I have an option whose default depends on a value defined in the config.
(I'm skipping a few details in the type here, not sure what is important or not. There's a link to the PR with the full code further down).
Here is where the documentation code is evaluating the modules. So I tried changing the default to use I also tried adding a dummy module inside the
But that's not working either š What's working is if I use a hardcoded string for the default value of the options. Here is the PR introducing the changes leading to that error. This Github action shows the error. More specifically, here's the type definition and default setting that causes an issue. On a totally different topic, this PR introduces 2 contracts in the form of structural typing for backing up files and backing up databases. They are both implemented by Restic. The correct implementation of both contracts is enforced by 2 generic NixOS tests (here and here) and then the Restic implementation is verified here and here. | 23:32:16 | |
I've usually set defaultText to reflect where it's pulling it's default from. Would that work for you? | 23:32:48 | |
| Yessssssssss that worked!! | 23:36:06 | |
| I'm happy to go to bed on a positive note, I'll post the update tomorrow :) Thanks!! | 23:36:53 | |
| Great! | 23:37:30 | |
| 11 Nov 2024 | ||
| 08:05:18 | ||
Specifically, if your default is dynamic you probably want defaultText with a literalExpression or literalMD that demonstrates how the default is evaluated. | 13:28:36 | |
| 13 Nov 2024 | ||
| 22:15:46 | ||
| 14 Nov 2024 | ||
| ibizaman: I definitely agree on the fact that we need contracts, at the very least for cases where we have multiple implementations. However, I do not know what you attempted to do with On the other hand imagine the following:
This could be what is targetted by requesters which are looking for having a reverse proxy. But how does these contract get honored? We could add an | 15:10:05 | |
The default implementation of the requester could provide defaults such as "ngnix", but then a user could mkForce it to apache/httpd. | 15:11:53 | |
| nbp: thanks for the feedback! First I want to say I'm convinced these contracts will really help in nixpkgs but I'm still experimenting on the UX side. So don't take my I considered enums at the start, but the problem I have with those is it's not easily extendable by the end user without modifying nixpkgs directly. At least I don't think so? What I have currently is the following. My "best" and most recent contracts are currently the backup and database backup contracts. The former is for backing up files, the latter for backing up the output of a command (like pg_dump) without going through an intermediate file. (writing this down, I should probably find a better name than database backup) This is the backup contract and the database backup one I have now. They're both just attrsets with some pre-defined schema: A requester of the backup contract, for example Nextcloud which wants to be backed up, would then provide a A provider of the backup contract, for example Restic, would provide an attribute that uses the Putting both sides of the contract together is the end user's responsibility. Here, for backing up Nextcloud files with Restic, it looks like so:
Assuming
The beauty here is that if you had a Vaultwarden instance you want to backup, you can just add the following snippet without knowing anything about how to backup Vaultwarden:
Similarly, if you wanted to also use BorgBackup to backup Nextcloud and Vaultwarden, you can also just copy paste the snippets and just
If you're curious, backing up Vaultwarden is not necessarily complicated. But still, hiding it from the end user is nice. But now comes the even better part IMO. How do you make sure the Restic and BorgBackup are equivalent (from the contract perspective)? With generic tests! Here's the one for backup contract and here's the one for database backup contract. They are generic because they're a function taking in a location to a module so you plug it in a module that provides the contract and the test will make sure it has the same behavior. Of course you actually need to call that function to test something and that is done here and here respectively for the backup and database backup contract. These generic tests have a lot of value IMO. So yeah, that's where I'm at with contracts. If you spelunk in the code of the project, you'll see I have a contract for secrets and ssl. They predate this One last thing, you'll note that the restore script and backup service in the | 16:27:03 | |
| * nbp: thanks for the feedback! First I want to say I'm convinced these contracts will really help in nixpkgs but I'm still experimenting on the UX side. So don't take my I considered enums at the start, but the problem I have with those is it's not easily extendable by the end user without modifying nixpkgs directly. At least I don't think so? What I have currently is the following. My "best" and most recent contracts are currently the backup and database backup contracts. The former is for backing up files, the latter for backing up the output of a command (like pg_dump) without going through an intermediate file. (writing this down, I should probably find a better name than database backup) This is the backup contract and the database backup one I have now. They're both just attrsets with some pre-defined schema: A requester of the backup contract, for example Nextcloud which wants to be backed up, would then provide a A provider of the backup contract, for example Restic, would provide an attribute that uses the Putting both sides of the contract together is the end user's responsibility. Here, for backing up Nextcloud files with Restic, it looks like so:
Assuming
The beauty here is that if you had a Vaultwarden instance you want to backup, you can just add the following snippet without knowing anything about how to backup Vaultwarden:
Similarly, if you wanted to also use BorgBackup to backup Nextcloud and Vaultwarden, you can also just copy paste the snippets and just
If you're curious, backing up Vaultwarden is not necessarily complicated. But still, hiding it from the end user is nice. But now comes the even better part IMO. How do you make sure the Restic and BorgBackup are equivalent (from the contract perspective)? With generic tests! Here's the one for backup contract and here's the one for database backup contract. They are generic because they're a function taking in a location to a module so you plug it in a module that provides the contract and the test will make sure it has the same behavior. Of course you actually need to call that function to test something and that is done here and here respectively for the backup and database backup contract. These generic tests have a lot of value IMO. So yeah, that's where I'm at with contracts. If you spelunk in the code of the project, you'll see I have a contract for secrets and ssl. They predate this One last thing, you'll note that the restore script and backup service in the | 16:28:45 | |
| * nbp: thanks for the feedback! First I want to say I'm convinced these contracts will really help in nixpkgs but I'm still experimenting on the UX side. So don't take my I considered enums at the start, but the problem I have with those is it's not easily extendable by the end user without modifying nixpkgs directly. At least I don't think so? What I have currently is the following. My "best" and most recent contracts are currently the backup and database backup contracts. The former is for backing up files, the latter for backing up the output of a command (like pg_dump) without going through an intermediate file. (writing this down, I should probably find a better name than database backup) This is the backup contract and the database backup one I have now. They're both just attrsets with some pre-defined schema: A requester of the backup contract, for example Nextcloud which wants to be backed up, would then provide a A provider of the backup contract, for example Restic, would provide an attribute that uses the Putting both sides of the contract together is the end user's responsibility. Here, for backing up Nextcloud files with Restic, it looks like so:
Assuming
The beauty here is that if you had a Vaultwarden instance you want to backup, you can just add the following snippet without knowing anything about how to backup Vaultwarden:
Similarly, if you wanted to also use BorgBackup to backup Nextcloud and Vaultwarden, you can also just copy paste the snippets and just
If you're curious, backing up Vaultwarden is not necessarily complicated. But still, hiding it from the end user is nice. But now comes the even better part IMO. How do you make sure the Restic and BorgBackup are equivalent (from the contract perspective)? With generic tests! Here's the one for backup contract and here's the one for database backup contract. They are generic because they're a function taking in a location to a module so you plug it in a module that provides the contract and the test will make sure it has the same behavior. Of course you actually need to call that function to test something and that is done here and here respectively for the backup and database backup contract. These generic tests have a lot of value IMO. So yeah, that's where I'm at with contracts. If you spelunk in the code of the project, you'll see I have a contract for secrets and ssl. They predate this One last thing, you'll note that the restore script and backup service in the | 16:31:16 | |
| * nbp: thanks for the feedback! First I want to say I'm convinced these contracts will really help in nixpkgs but I'm still experimenting on the UX side. So don't take my I considered enums at the start, but the problem I have with those is it's not easily extendable by the end user without modifying nixpkgs directly. At least I don't think so? What I have currently is the following. My "best" and most recent contracts are currently the backup and database backup contracts. The former is for backing up files, the latter for backing up the output of a command (like pg_dump) without going through an intermediate file. (writing this down, I should probably find a better name than database backup) This is the backup contract and the database backup one I have now. They're both just attrsets with some pre-defined schema: A requester of the backup contract, for example Nextcloud which wants to be backed up, would then provide a A provider of the backup contract, for example Restic, would provide an attribute that uses the Putting both sides of the contract together is the end user's responsibility. Here, for backing up Nextcloud files with Restic, it looks like so:
Assuming
The beauty here is that if you had a Vaultwarden instance you want to backup, you can just add the following snippet without knowing anything about how to backup Vaultwarden:
Similarly, if you wanted to also use BorgBackup to backup Nextcloud and Vaultwarden, you can also just copy paste the snippets and just
Of course, you'd need to configure Nextcloud, Vaultwarden, Restic and BorgBackup with specific options. But this snippet is just showing the pluming going on. If you're curious, backing up Vaultwarden is not necessarily complicated. But still, hiding it from the end user is nice. But now comes the even better part IMO. How do you make sure the Restic and BorgBackup are equivalent (from the contract perspective)? With generic tests! Here's the one for backup contract and here's the one for database backup contract. They are generic because they're a function taking in a location to a module so you plug it in a module that provides the contract and the test will make sure it has the same behavior. Of course you actually need to call that function to test something and that is done here and here respectively for the backup and database backup contract. These generic tests have a lot of value IMO. So yeah, that's where I'm at with contracts. If you spelunk in the code of the project, you'll see I have a contract for secrets and ssl. They predate this One last thing, you'll note that the restore script and backup service in the | 16:33:13 | |
| * nbp: thanks for the feedback! First I want to say I'm convinced these contracts will really help in nixpkgs but I'm still experimenting on the UX side. So don't take my I considered enums at the start, but the problem I have with those is it's not easily extendable by the end user without modifying nixpkgs directly. At least I don't think so? What I have currently is the following. My "best" and most recent contracts are currently the backup and database backup contracts. The former is for backing up files, the latter for backing up the output of a command (like pg_dump) without going through an intermediate file. (writing this down, I should probably find a better name than database backup) This is the backup contract and the database backup one I have now. They're both just attrsets with some pre-defined schema: A requester of the backup contract, for example Nextcloud which wants to be backed up, would then provide a A provider of the backup contract, for example Restic, would provide an attribute that uses the Putting both sides of the contract together is the end user's responsibility. Here, for backing up Nextcloud files with Restic, it looks like so:
Assuming
The beauty here is that if you had a Vaultwarden instance you want to backup, you can just add the following snippet without knowing anything about how to backup Vaultwarden:
Similarly, if you wanted to also use BorgBackup to backup Nextcloud and Vaultwarden, you can also just copy paste the snippets and just
Of course, you'd need to configure Nextcloud, Vaultwarden, Restic and BorgBackup with specific options. But this snippet is just showing the pluming going on. If you're curious, backing up Vaultwarden is not necessarily complicated. But still, hiding it from the end user is nice. Using the database backup contract is as easy:
Here's the PostgreSQL provider side if you're curious. But now comes the even better part IMO. How do you make sure the Restic and BorgBackup are equivalent (from the contract perspective)? With generic tests! Here's the one for backup contract and here's the one for database backup contract. They are generic because they're a function taking in a location to a module so you plug it in a module that provides the contract and the test will make sure it has the same behavior. Of course you actually need to call that function to test something and that is done here and here respectively for the backup and database backup contract. These generic tests have a lot of value IMO. So yeah, that's where I'm at with contracts. If you spelunk in the code of the project, you'll see I have a contract for secrets and ssl. They predate this One last thing, you'll note that the restore script and backup service in the | 16:35:34 | |
| * nbp: thanks for the feedback! First I want to say I'm convinced these contracts will really help in nixpkgs but I'm still experimenting on the UX side. So don't take my I considered enums at the start, but the problem I have with those is it's not easily extendable by the end user without modifying nixpkgs directly. At least I don't think so? What I have currently is the following. My "best" and most recent contracts are currently the backup and database backup contracts. The former is for backing up files, the latter for backing up the output of a command (like pg_dump) without going through an intermediate file. (writing this down, I should probably find a better name than database backup) This is the backup contract and the database backup one I have now. They're both just attrsets with some pre-defined schema: A requester of the backup contract, for example Nextcloud which wants to be backed up, would then provide a A provider of the backup contract, for example Restic, would provide an attribute that uses the Putting both sides of the contract together is the end user's responsibility. Here, for backing up Nextcloud files with Restic, it looks like so:
Assuming
The beauty here is that if you had a Vaultwarden instance you want to backup, you can just add the following snippet without knowing anything about how to backup Vaultwarden:
Similarly, if you wanted to also use BorgBackup to backup Nextcloud and Vaultwarden, you can also just copy paste the snippets and just
Of course, you'd need to configure Nextcloud, Vaultwarden, Restic and BorgBackup with specific options. But this snippet is just showing the pluming going on. If you're curious, backing up Vaultwarden is not necessarily complicated. But still, hiding it from the end user is nice. Using the database backup contract is as easy:
Here's the PostgreSQL provider side if you're curious. But now comes the even better part IMO. How do you make sure the Restic and BorgBackup are equivalent (from the contract perspective)? With generic tests! Here's the one for backup contract and here's the one for database backup contract. They are generic because they're a function taking in a location to a module so you plug in a module that provides the contract and the test will make sure it has the same behavior. Of course you actually need to call that function to test something and that is done here and here respectively for the backup and database backup contract. These generic tests have a lot of value IMO. So yeah, that's where I'm at with contracts. If you spelunk in the code of the project, you'll see I have a contract for secrets and ssl. They predate this One last thing, you'll note that the restore script and backup service in the | 16:36:21 | |
| * nbp: thanks for the feedback! First I want to say I'm convinced these contracts will really help in nixpkgs but I'm still experimenting on the UX side. So don't take my I considered enums at the start, but the problem I have with those is it's not easily extendable by the end user without modifying nixpkgs directly. At least I don't think so? What I have currently is the following. My "best" and most recent contracts are currently the backup and database backup contracts. The former is for backing up files, the latter for backing up the output of a command (like pg_dump) without going through an intermediate file. (writing this down, I should probably find a better name than database backup) This is the backup contract and the database backup one I have now. They're both just attrsets with some pre-defined schema: A requester of the backup contract, for example Nextcloud which wants to be backed up, would then provide a A provider of the backup contract, for example Restic, would provide an attribute that uses the Putting both sides of the contract together is the end user's responsibility. Here, for backing up Nextcloud files with Restic, it looks like so:
Assuming
The beauty here is that if you had a Vaultwarden instance you want to backup, you can just add the following snippet without knowing anything about how to backup Vaultwarden:
Similarly, if you wanted to also use BorgBackup to backup Nextcloud and Vaultwarden, you can also just copy paste the snippets and just
Of course, you'd need to configure Nextcloud, Vaultwarden, Restic and BorgBackup with specific options. But this snippet is just showing the pluming going on. If you're curious, backing up Vaultwarden is not necessarily complicated. But still, hiding it from the end user is nice. Using the database backup contract is as easy:
Here's the PostgreSQL provider side if you're curious. But now comes the even better part IMO. How do you make sure the Restic and BorgBackup are equivalent (from the contract perspective)? With generic tests! Here's the one for backup contract and here's the one for database backup contract. They are generic because they're a function taking in a location to a module so you plug in a module that provides the contract and the test will make sure it has the same behavior. Of course you actually need to call that function to test something and that is done here for the backup and database backup contract. These generic tests have a lot of value IMO. So yeah, that's where I'm at with contracts. If you spelunk in the code of the project, you'll see I have a contract for secrets and ssl. They predate this One last thing, you'll note that the restore script and backup service in the | 16:36:46 | |
| enum are externally extendable in the module system. This is how desktopManagers / windowManagers are handled. | 16:40:38 | |
| * enum are externally extendable in the module system. This is how desktopManagers / windowManagers are handled. Or why they got added a while back.
makes sense, as opposed to many other languages, because options can be extended by multiple modules. Thus if all providers were to add extra declarations, you could have an option which enumerate all services which could be used as a provider. | 16:48:23 | |
| Here is an example, where a module declare an And another module provide an implementation for it: | 16:59:10 | |
The module which declare the enum [] is equivalent to a contract and the module which declares it as enum [ "its-own-name" ] is equivalent to a provider. | 17:02:09 | |
| Thatās interesting. I have no idea how to compare both solutions, whatās their respective drawbacks and advantages. I took the structural typing approach because I knew that from my programming in Python and Go and it sticked with me. One potential drawback is discoverability although thereās surely a way to remediate to that. | 19:12:56 | |
| 15 Nov 2024 | ||
| 10:17:04 | ||
| 15:08:21 | ||
| 17 Nov 2024 | ||
| 02:28:12 | ||
| 02:38:28 | ||
| Apologies in advance for the massive text block, I'm gonna drop this here because I suspect I'll eventually get more visibility from people who can answer this. | 02:56:13 | |