Skip to content

Commit

Permalink
Try #218:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Apr 1, 2021
2 parents 01b0555 + 541bf89 commit 5171c64
Show file tree
Hide file tree
Showing 10 changed files with 486 additions and 74 deletions.
160 changes: 160 additions & 0 deletions doc/mkFlakeOptions.md
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"
```


1 change: 1 addition & 0 deletions doc/start/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ In addition, the [binary cache](../../cachix) is added for faster deployment.
> upstream changes.
## Next Steps:
- [Use Devos as a library!](./mkflake.md)
- [Make installable ISO](./iso.md)
- [Bootstrap Host](./bootstrapping.md)
- [Already on NixOS](./from-nixos.md)
Expand Down
42 changes: 42 additions & 0 deletions doc/start/mkflake.md
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.

2 changes: 1 addition & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 24 additions & 69 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,79 +28,34 @@
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 {
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";
outputs = inputs@{ deploy, nixos, nur, self, utils, ... }:
let
lib = import ./lib { inherit self nixos inputs; };

out = lib.mkFlake {
inherit self;
hosts = ./hosts;
packages = import ./pkgs;
suites = import ./suites;
extern = import ./extern;
overrides = import ./overrides;
inherit multiPkgs suites extern;
overlays = ./overlays;
profiles = ./profiles;
userProfiles = ./users/profiles;
modules = import ./modules/module-list.nix;
userModules = import ./users/modules/module-list.nix;
};

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; };

in nixos.lib.recursiveUpdate out {
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" ];
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;
}
3 changes: 3 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ lib.makeExtensible (final:
lists = callLibs ./lists.nix;
strings = callLibs ./strings.nix;

mkFlake = callLibs ./mkFlake;
evalFlakeArgs = callLibs ./mkFlake/evalArgs.nix;

inherit (attrs) mapFilterAttrs genAttrs' safeReadDir
pathsToImportedAttrs concatAttrs filterPackages;
inherit (lists) pathsIn;
Expand Down
6 changes: 3 additions & 3 deletions lib/devos/mkHosts.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, dev, nixos, inputs, self, ... }:

{ dir, extern, suites, overrides, multiPkgs, ... }:
{ dir, devos, extern, suites, overrides, multiPkgs, ... }:
let
defaultSystem = "x86_64-linux";

Expand All @@ -12,7 +12,7 @@ let
];

modules = {
core = "${self}/profiles/core";
core = toString ../../profiles/core;
modOverrides = { config, overrideModulesPath, ... }:
let
inherit (overrides) modules disabledModules;
Expand Down Expand Up @@ -61,7 +61,7 @@ let
# Everything in `./modules/list.nix`.
flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; };

cachix = ../../cachix.nix;
cachix = "${devos}/cachix.nix";
};

specialArgs = extern.specialArgs // { suites = suites.system; };
Expand Down
Loading

0 comments on commit 5171c64

Please sign in to comment.