-
Notifications
You must be signed in to change notification settings - Fork 108
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
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
919cab9
mkHosts: get devos arg for core and cachix
b01f5d1
lib: init evalFlakeArgs for mkFlake args
09ca1b6
lib: init mkFlake to create a devos flake
3e7b183
flake: use mkFlake
2161153
pkgs: add devosOptionsDoc - devos specific
c30cf5b
doc/start: add section for using mkflake
a868ed1
doc: init mkFlakeOptions.md
683c606
mkFlake: also pass self.inputs to lib
541bf89
mkHosts: try fix with toString
9e51359
mkFlake: do not export soon-to-be devoslib on each repo
fac0869
cleanup: ironing out flake code
2c348a6
flake.nix: recursiveUpdate is unecessary here
0026cee
lib: don't add evalFlake args into the top-level lib namespace
f68b94e
lib: self is self is self
1b7943b
lib: merge dev into lib
3e576ed
Merge branch 'mkflake' into da/mkFlake/simplify-2
Pacman99 fe7b0c7
Merge pull request #5 from blaggacao/da/mkFlake/simplify-2
Pacman99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
## extern | ||
Function with argument 'inputs' that contains all devos and ${self}'s inputs. | ||
The function should return an attribute set with modules, overlays, and | ||
specialArgs to be included across nixos and home manager configurations. | ||
Only attributes that are used should be returned. | ||
|
||
|
||
*_Type_*: | ||
function that evaluates to a(n) attrs | ||
|
||
*_Default_* | ||
``` | ||
"{ modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; }\n" | ||
``` | ||
|
||
|
||
## hosts | ||
Path to directory containing host configurations that will be exported | ||
to the 'nixosConfigurations' output. | ||
|
||
|
||
*_Type_*: | ||
path | ||
|
||
*_Default_* | ||
``` | ||
"${self}/hosts" | ||
``` | ||
|
||
|
||
## modules | ||
list of modules to include in confgurations and export in 'nixosModules' output | ||
|
||
|
||
*_Type_*: | ||
list of valid modules | ||
|
||
*_Default_* | ||
``` | ||
[] | ||
``` | ||
|
||
|
||
## overlays | ||
path to folder containing overlays which will be applied to pkgs and exported in | ||
the 'overlays' output | ||
|
||
|
||
*_Type_*: | ||
path | ||
|
||
*_Default_* | ||
``` | ||
"${self}/overlays" | ||
``` | ||
|
||
|
||
## overrides | ||
attrset of packages and modules that will be pulled from nixpkgs master | ||
|
||
*_Type_*: | ||
attribute set | ||
|
||
*_Default_* | ||
``` | ||
"{ modules = []; disabledModules = []; packages = {}; }" | ||
``` | ||
|
||
|
||
## packages | ||
Overlay for custom packages that will be included in treewide 'pkgs'. | ||
This should follow the standard nixpkgs overlay format - two argument function | ||
that returns an attrset. | ||
These packages will be exported to the 'packages' and 'legacyPackages' outputs. | ||
|
||
|
||
*_Type_*: | ||
Nixpkgs overlay | ||
|
||
*_Default_* | ||
``` | ||
"(final: prev: {})" | ||
``` | ||
|
||
|
||
## profiles | ||
path to profiles folder that can be collected into suites | ||
|
||
*_Type_*: | ||
path | ||
|
||
*_Default_* | ||
``` | ||
"${self}/profiles" | ||
``` | ||
|
||
|
||
## self | ||
The flake to create the devos outputs for | ||
|
||
*_Type_*: | ||
attribute set | ||
|
||
|
||
|
||
## suites | ||
Function with inputs 'users' and 'profiles' that returns attribute set | ||
with user and system suites. The former for Home Manager and the latter | ||
for nixos configurations. | ||
These can be accessed through the 'suites' specialArg in each config system. | ||
|
||
|
||
*_Type_*: | ||
function that evaluates to a(n) attrs | ||
|
||
*_Default_* | ||
``` | ||
"{ user = {}; system = {}; }" | ||
``` | ||
|
||
|
||
## userModules | ||
list of modules to include in home-manager configurations and export in | ||
'homeModules' output | ||
|
||
|
||
*_Type_*: | ||
list of valid modules | ||
|
||
*_Default_* | ||
``` | ||
[] | ||
``` | ||
|
||
|
||
## userProfiles | ||
path to user profiles folder that can be collected into userSuites | ||
|
||
*_Type_*: | ||
path | ||
|
||
*_Default_* | ||
``` | ||
"${self}/users/profiles" | ||
``` | ||
|
||
|
||
## users | ||
path to folder containing profiles that define system users | ||
|
||
|
||
*_Type_*: | ||
path | ||
|
||
*_Default_* | ||
``` | ||
"${self}/users" | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Use Devos as a library! | ||
You can also add devos as a flake input and use its library function, `mkFlake` to | ||
create your flake. This gives you the advantage of using nix flakes to sync with | ||
upstream changes in devos. | ||
|
||
You can either use the default template or use the 'mkflake' template which only | ||
includes the necessary folders for `mkFlake` usage. It can be pulled with: | ||
```sh | ||
nix flake init -t github:divnix/devos#mkflake | ||
``` | ||
|
||
Once you have a template, you need to add devos as a flake input, which would look | ||
like this: | ||
```nix | ||
inputs = { | ||
... | ||
devos.url = "github:divnix/devos"; | ||
}; | ||
``` | ||
> ##### Note: | ||
> - All devos inputs must still be included in your flake, due to a nix | ||
> [issue](https://github.com/NixOS/nix/pull/4641) with the `follows` attribute. | ||
> - You can append `/community` to access community modules [extern](../../extern). | ||
|
||
You can then call `mkFlake` to create your outputs. Here is a simple example: | ||
```nix | ||
outputs = { self, devos, ... }: devos.lib.mkFlake { | ||
inherit self; | ||
hosts = ./hosts; | ||
}; | ||
``` | ||
`mkFlake` has various arguments to include more devos concepts like suites and profiles. | ||
These options are documented in [mkFlakeOptions](../mkFlakeOptions.md). | ||
|
||
The devos template itself uses mkFlake to export its own outputs, so you can take | ||
a look at this repository's [flake.nix](../../flake.nix) for a more realistic use | ||
of `mkFlake`. | ||
|
||
You can now sync with upstream devos changes just like any other flake input. But | ||
you will no longer be able to edit devos's internals, since you are directly following | ||
upstream devos changes. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,79 +28,33 @@ | |
pkgs.inputs.nixpkgs.follows = "nixos"; | ||
}; | ||
|
||
outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: | ||
let | ||
inherit (self) lib; | ||
inherit (lib) os; | ||
|
||
extern = import ./extern { inherit inputs; }; | ||
overrides = import ./overrides; | ||
|
||
multiPkgs = os.mkPkgs { | ||
inherit extern overrides; | ||
}; | ||
|
||
suites = os.mkSuites { | ||
outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: | ||
let | ||
lib = import ./lib { inherit self nixos inputs; }; | ||
in lib.mkFlake { | ||
inherit self; | ||
hosts = ./hosts; | ||
packages = import ./pkgs; | ||
suites = import ./suites; | ||
users = os.mkProfileAttrs "${self}/users"; | ||
profiles = os.mkProfileAttrs "${self}/profiles"; | ||
userProfiles = os.mkProfileAttrs "${self}/users/profiles"; | ||
}; | ||
|
||
outputs = { | ||
nixosConfigurations = os.mkHosts { | ||
dir = "${self}/hosts"; | ||
overrides = import ./overrides; | ||
inherit multiPkgs suites extern; | ||
}; | ||
|
||
homeConfigurations = os.mkHomeConfigurations; | ||
|
||
nixosModules = | ||
let moduleList = import ./modules/module-list.nix; | ||
in lib.pathsToImportedAttrs moduleList; | ||
|
||
homeModules = | ||
let moduleList = import ./users/modules/module-list.nix; | ||
in lib.pathsToImportedAttrs moduleList; | ||
|
||
overlay = import ./pkgs; | ||
overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays); | ||
|
||
lib = import ./lib { inherit nixos self inputs; }; | ||
|
||
extern = import ./extern; | ||
overrides = import ./overrides; | ||
overlays = ./overlays; | ||
profiles = ./profiles; | ||
userProfiles = ./users/profiles; | ||
modules = import ./modules/module-list.nix; | ||
userModules = import ./users/modules/module-list.nix; | ||
} // { | ||
inherit lib; | ||
defaultTemplate = self.templates.flk; | ||
templates.flk.path = ./.; | ||
templates.flk.description = "flk template"; | ||
defaultTemplate = self.templates.flk; | ||
|
||
deploy.nodes = os.mkNodes deploy self.nixosConfigurations; | ||
templates.mkflake.path = | ||
let | ||
excludes = [ "lib" "tests" "cachix" "nix" "theme" ".github" "bors.toml" "cachix.nix" ]; | ||
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. Nice! |
||
filter = path: type: ! builtins.elem (baseNameOf path) excludes; | ||
in | ||
builtins.filterSource filter ./.; | ||
templates.mkflake.description = "template with necessary folders for mkFlake usage"; | ||
}; | ||
|
||
systemOutputs = utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = multiPkgs.${system}; | ||
# all packages that are defined in ./pkgs | ||
legacyPackages = os.mkPackages { inherit pkgs; }; | ||
in | ||
{ | ||
checks = | ||
let | ||
tests = nixos.lib.optionalAttrs (system == "x86_64-linux") | ||
(import ./tests { inherit self pkgs; }); | ||
deployHosts = nixos.lib.filterAttrs | ||
(n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) self.deploy.nodes; | ||
deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; | ||
in | ||
nixos.lib.recursiveUpdate tests deployChecks; | ||
|
||
inherit legacyPackages; | ||
packages = lib.filterPackages system legacyPackages; | ||
|
||
devShell = import ./shell { | ||
inherit self system extern overrides; | ||
}; | ||
} | ||
); | ||
in | ||
nixos.lib.recursiveUpdate outputs systemOutputs; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we import
./lib
as a "subflake", instead?inputs.devos.path = ./lib;
It makes this just an in-tree user of an otherwise independent lib and makes the step to carve it out into a separate repo absolutely trivial.
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.
Overall this is a good idea, but it would require a bit of refactoring that I would rather not include in this PR.