Merge pull request #139 from divnix/fix-136

profiles: simplify profiles to suites
This commit is contained in:
Timothy DeHerrera 2021-02-25 14:56:20 -07:00 committed by GitHub
commit 314b18e5f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 28 deletions

View file

@ -1,7 +1,7 @@
{ suites, ... }:
{
### root password is empty by default ###
imports = suites.core;
imports = suites.base;
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;

View file

@ -23,7 +23,7 @@ let
modules =
let
core = import ../profiles/core;
core = ../profiles/core;
modOverrides = { config, overrideModulesPath, ... }:
let

View file

@ -4,7 +4,7 @@ let
pathExists filter;
inherit (nixos.lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix
recursiveUpdate genAttrs nixosSystem mkForce;
recursiveUpdate genAttrs nixosSystem mkForce optionalAttrs;
# mapFilterAttrs ::
# (name -> value -> bool )
@ -58,15 +58,15 @@ let
});
/**
Synopsis: importDefaults _path_
Synopsis: mkProfileAttrs _path_
Recursively import the subdirs of _path_ containing a default.nix.
Example:
let profiles = importDefaults ./profiles; in
let profiles = mkProfileAttrs ./profiles; in
assert profiles ? core.default; 0
**/
importDefaults = dir:
mkProfileAttrs = dir:
let
imports =
let
@ -74,19 +74,21 @@ let
p = n: v:
v == "directory"
&& pathExists "${dir}/${n}/default.nix";
&& n != "profiles";
in
filterAttrs p files;
f = n: _:
{ default = import "${dir}/${n}/default.nix"; }
// importDefaults "${dir}/${n}";
optionalAttrs
(pathExists "${dir}/${n}/default.nix")
{ default = "${dir}/${n}"; }
// mkProfileAttrs "${dir}/${n}";
in
mapAttrs f imports;
in
{
inherit importDefaults mapFilterAttrs genAttrs' pkgImport
inherit mkProfileAttrs mapFilterAttrs genAttrs' pkgImport
pathsToImportedAttrs mkNodes;
overlays = pathsToImportedAttrs overlayPaths;

View file

@ -5,14 +5,16 @@ window manager. If you need some concrete examples, just checkout the
community [branch](https://github.com/divnix/devos/tree/community/profiles).
## Constraints
For the sake of consistency, there are a few minor constraints. First of all, a
profile should always be defined in a `default.nix`, and it should always be a
a function taking a single attribute set as an argument, and returning a NixOS
module which does not define any new module options. If you need to make new
module option declarations, just use [modules](../modules).
For the sake of consistency, a profile should always be defined in a
_default.nix_ containing a valid [nixos module](https://nixos.wiki/wiki/Module)
which ___does not___ declare any new
[module options](https://nixos.org/manual/nixos/stable/index.html#sec-option-declarations).
If you need to do that, use the [modules directory](../modules).
These restrictions help simplify the import logic used to pass profles to
[suites](../suites).
> ##### _Note:_
> [hercules-ci](../doc/integrations/hercules.md) expects all profiles to be
> defined in a _default.nix_. Similarly, [suites](../suites) expect a
> _default.nix_ as well.
### Example
#### Correct ✔
@ -40,6 +42,25 @@ program configurations such as your text editor, and shell configs. This way,
you can either pull in the whole development profile, or pick and choose
individual programs.
### Example
profiles/develop/default.nix:
```nix
{
imports = [ ./zsh ];
# some generic development concerns ...
}
```
profiles/develop/zsh/default.nix:
```nix
{ ... }:
{
programs.zsh.enable = true;
# zsh specific options ...
}
```
## Conclusion
Profiles are the most important concept in devos. They allow us to keep our
nix expressions self contained and modular. This way we can maximize reuse

View file

@ -1 +0,0 @@
../users/profiles

View file

@ -1,24 +1,24 @@
{ lib }:
let
inherit (builtins) mapAttrs isFunction;
inherit (lib.flk) importDefaults;
inherit (lib.flk) mkProfileAttrs profileMap;
profiles = importDefaults (toString ../profiles);
users = importDefaults (toString ../users);
profiles = mkProfileAttrs (toString ../profiles);
users = mkProfileAttrs (toString ../users);
allProfiles =
let
sansCore = lib.filterAttrs (n: _: n != "core") profiles;
in
lib.collect isFunction sansCore;
let defaults = lib.collect (x: x ? default) profiles;
in map (x: x.default) defaults;
allUsers = lib.collect isFunction users;
allUsers =
let defaults = lib.collect (x: x ? default) users;
in map (x: x.default) defaults;
suites = with profiles; rec {
core = [ users.nixos users.root ];
base = [ users.nixos users.root ];
};
in
mapAttrs (_: v: lib.flk.profileMap v) suites // {
mapAttrs (_: v: profileMap v) suites // {
inherit allProfiles allUsers;
}