-
Notifications
You must be signed in to change notification settings - Fork 107
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
lib: init and use mkFlake and evalFlakeArgs #218
Conversation
Moved templates and devosOptionsDoc out of |
Dependent PR's: |
Can't build |
I want to filter packages by system, but I don't think we actually need the "flatten-tree" funcitonality anyhow, since pkgs/default.nix is already flat. Perhaps we could make it simpler and invert the logic, so that if a system isn't explicitly specified, instead of being filtered out as it is now, it is automatically included in all systems. This encourages packages that should be systemed to do so, or CI won't pass, while allowing derivations that can run on any system without issue do so automatically. |
type = path; | ||
default = "${self}/hosts"; | ||
defaultText = "\${self}/hosts"; | ||
apply = toString; |
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.
toString is necessary here otherwise for some reason the mk*
functions create a new store path with just that folder and then nix fails because of an access to a restricted store path. either way its better to pass these paths as strings.
37cf3da
to
afefcd4
Compare
Added a doc section, 'use devos as a library!' which is an updated version of the 'use-mkdevos' doc from the other PR. |
95f34a3
to
22dc867
Compare
lib/devos/mkHosts.nix
Outdated
@@ -1,6 +1,6 @@ | |||
{ lib, dev, nixos, inputs, self, ... }: | |||
|
|||
{ dir, extern, suites, overrides, multiPkgs, ... }: | |||
{ dir, devos, extern, suites, overrides, multiPkgs, ... }: |
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.
So users of mkflake can safely delete the core profile or cachix module.
lib/mkFlake/default.nix
Outdated
checks = | ||
let | ||
tests = nixos.lib.optionalAttrs (system == "x86_64-linux") | ||
(import "${devos}/tests" { inherit pkgs; self = devos; }); |
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 think passing devos
as self is optimal for now. We know devos will always have self.nixosConfigurations.NixOS
, while end user might delete the default hosts. And we still have test coverage of self
with deploy-rs checks. But in the future I think it would be good to pass both self
and devos
. And have a mix of testing devos's hosts, and the users hosts/profiles. But lets save for a future PR.
a7bbd57
to
ba81137
Compare
What's left to do here, before review? |
I just went through a few cleanups today and improved the option descriptions. This should be ready for review. I don't plan on adding anything else in the PR. |
default = "${self}/hosts"; | ||
defaultText = "\${self}/hosts"; |
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.
Defaults for all path options do end up adding some file system structure. I think its ok since it is a path option. But just wanted to note that.
lib/mkFlake/default.nix
Outdated
lib = import "${devos}/lib" { | ||
inherit self nixos; | ||
inputs = inputs // self.inputs; | ||
}; |
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.
Just added this, so we can also extend devos api to flake inputs. Creates opportunity to do things based on what input exists, allowing integrations to become optional.
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.
for example, // optionalAttrs (inputs ? home) { home-manager = ... }
module describing devos flake arguments
general lib function - not devos specific
this is where we create devos's template structure
generated mkFlake options documentation
bors try |
tryBuild failed: |
It is not generally useful for everybody to export devos-lib. We can reintroduce a lib-exportin interface, once we conceputualize the private library sharing use case properly.
currently, there is no need for a recursiveUpdate, and since flake requires flattened trees, there might never be a good enough reason to use it at the expense of introducing a dependency on lib.
evalFlakeArgs is a private function to mkFlake, so there is no reason expense going over the top level namespace. Unfortunately, keeping boundaries around future devos-lib, this also means we cannot introduce a dependency on pkgs, and vie versa we cannot introduce a dependency on devos-lib lighthartedly (without a clear api) on pkgs. While this is genuinly useful, we ight need to find a cleaner and more organized way to implement this in the future.
we should consequently avoid variable redefintions while traversing through layers and interfaces. self is a flake native term and refers to a handle to the flake repo itself.
since lib is structured after upstream lib (lists, attrs, strings), and it is even conceived as lib.makeExtensible, it does not appear in line to namespace devos specific library additions: not only is the name `dev` little self explaining, we also have the `os` namespace, for if library functions are devos specific. The rest are just confenience functions which might as well ladn upstream one day.
A series of "clenups"
More dependent PR's:
With those PR's, the current "black magic" will no longer be necessary. |
231: Move flake implementation logic to lib r=blaggacao a=Pacman99 This is a simpler version of #218 that moves flake logic to lib and adds a module to evaluate devos. This DOES NOT support out of tree usage, so if you were following any of the previous PR's, the doc sections/examples to use devos as a library will not work. There is work to make a cleaner api and only then will out of tree support work. Until then, this is still useful to simplify devos and clean up a lot of the implementation logic. Co-authored-by: Pacman99 <pachum99@gmail.com>
231: Move flake implementation logic to lib r=nrdxp a=Pacman99 This is a simpler version of #218 that moves flake logic to lib and adds a module to evaluate devos. This DOES NOT support out of tree usage, so if you were following any of the previous PR's, the doc sections/examples to use devos as a library will not work. There is work to make a cleaner api and only then will out of tree support work. Until then, this is still useful to simplify devos and clean up a lot of the implementation logic. Co-authored-by: Pacman99 <pachum99@gmail.com>
mostly implemented in #231 |
Add general lib functions to create a devos flake. These functions do not enforce a file system structure, but just provide an api to create a flake.
The options that have types do not allow paths, see this comment for my reasoning.
Module system allows for type checking and storing all data about the flake within one comprehensive evaluated module. It also allows for adding defaults, so folders and files are no longer required. You can safely delete the
userSuites
or just not pass modules if you aren't using those features, and devos won't error out like it does now.Then in devos's flake.nix we now call mkFlake and pass the arguments to enforce this template's file system structure.
I mentioned this in other places, but I do not want to change any of devos's api in this PR. So for example @blaggacao has brought up that extern might be somewhat necessary and could be changed. But I'm still going to keep extern in this PR since thats how devos works right now. Then after the result of #214 and/or #152 we can update mkFlake and devos's flake.nix appropriately in separate PR's.
Thank you @blaggacao for the great ideas! Credit goes to him for the idea of making mkFlake more general. It took a bit for me to understand, but this is way better.