profiles: simplify profiles to suites
* Leave importing to nixpkgs module implentation. Provide a path instead; resolves #136. * Allow profiles which are not lambdas but simple attribute sets, relaxing the constraints a bit. * Update profile README.md * defaultImports -> mkProfileAttrs: allow importing subprofiles even if parent directory does not contain a default.nix.
This commit is contained in:
parent
7d87e5abc3
commit
1651913910
6 changed files with 50 additions and 28 deletions
|
@ -1,7 +1,7 @@
|
||||||
{ suites, ... }:
|
{ suites, ... }:
|
||||||
{
|
{
|
||||||
### root password is empty by default ###
|
### root password is empty by default ###
|
||||||
imports = suites.core;
|
imports = suites.base;
|
||||||
|
|
||||||
boot.loader.systemd-boot.enable = true;
|
boot.loader.systemd-boot.enable = true;
|
||||||
boot.loader.efi.canTouchEfiVariables = true;
|
boot.loader.efi.canTouchEfiVariables = true;
|
||||||
|
|
|
@ -23,7 +23,7 @@ let
|
||||||
|
|
||||||
modules =
|
modules =
|
||||||
let
|
let
|
||||||
core = import ../profiles/core;
|
core = ../profiles/core;
|
||||||
|
|
||||||
modOverrides = { config, overrideModulesPath, ... }:
|
modOverrides = { config, overrideModulesPath, ... }:
|
||||||
let
|
let
|
||||||
|
|
|
@ -4,7 +4,7 @@ let
|
||||||
pathExists filter;
|
pathExists filter;
|
||||||
|
|
||||||
inherit (nixos.lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix
|
inherit (nixos.lib) fold filterAttrs hasSuffix mapAttrs' nameValuePair removeSuffix
|
||||||
recursiveUpdate genAttrs nixosSystem mkForce;
|
recursiveUpdate genAttrs nixosSystem mkForce optionalAttrs;
|
||||||
|
|
||||||
# mapFilterAttrs ::
|
# mapFilterAttrs ::
|
||||||
# (name -> value -> bool )
|
# (name -> value -> bool )
|
||||||
|
@ -58,15 +58,15 @@ let
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Synopsis: importDefaults _path_
|
Synopsis: mkProfileAttrs _path_
|
||||||
|
|
||||||
Recursively import the subdirs of _path_ containing a default.nix.
|
Recursively import the subdirs of _path_ containing a default.nix.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
let profiles = importDefaults ./profiles; in
|
let profiles = mkProfileAttrs ./profiles; in
|
||||||
assert profiles ? core.default; 0
|
assert profiles ? core.default; 0
|
||||||
**/
|
**/
|
||||||
importDefaults = dir:
|
mkProfileAttrs = dir:
|
||||||
let
|
let
|
||||||
imports =
|
imports =
|
||||||
let
|
let
|
||||||
|
@ -74,19 +74,21 @@ let
|
||||||
|
|
||||||
p = n: v:
|
p = n: v:
|
||||||
v == "directory"
|
v == "directory"
|
||||||
&& pathExists "${dir}/${n}/default.nix";
|
&& n != "profiles";
|
||||||
in
|
in
|
||||||
filterAttrs p files;
|
filterAttrs p files;
|
||||||
|
|
||||||
f = n: _:
|
f = n: _:
|
||||||
{ default = import "${dir}/${n}/default.nix"; }
|
optionalAttrs
|
||||||
// importDefaults "${dir}/${n}";
|
(pathExists "${dir}/${n}/default.nix")
|
||||||
|
{ default = "${dir}/${n}"; }
|
||||||
|
// mkProfileAttrs "${dir}/${n}";
|
||||||
in
|
in
|
||||||
mapAttrs f imports;
|
mapAttrs f imports;
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit importDefaults mapFilterAttrs genAttrs' pkgImport
|
inherit mkProfileAttrs mapFilterAttrs genAttrs' pkgImport
|
||||||
pathsToImportedAttrs mkNodes;
|
pathsToImportedAttrs mkNodes;
|
||||||
|
|
||||||
overlays = pathsToImportedAttrs overlayPaths;
|
overlays = pathsToImportedAttrs overlayPaths;
|
||||||
|
|
|
@ -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).
|
community [branch](https://github.com/divnix/devos/tree/community/profiles).
|
||||||
|
|
||||||
## Constraints
|
## Constraints
|
||||||
For the sake of consistency, there are a few minor constraints. First of all, a
|
For the sake of consistency, a profile should always be defined in a
|
||||||
profile should always be defined in a `default.nix`, and it should always be a
|
_default.nix_ containing a valid [nixos module](https://nixos.wiki/wiki/Module)
|
||||||
a function taking a single attribute set as an argument, and returning a NixOS
|
which ___does not___ declare any new
|
||||||
module which does not define any new module options. If you need to make new
|
[module options](https://nixos.org/manual/nixos/stable/index.html#sec-option-declarations).
|
||||||
module option declarations, just use [modules](../modules).
|
If you need to do that, use the [modules directory](../modules).
|
||||||
|
|
||||||
These restrictions help simplify the import logic used to pass profles to
|
> ##### _Note:_
|
||||||
[suites](../suites).
|
> [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
|
### Example
|
||||||
#### Correct ✔
|
#### 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
|
you can either pull in the whole development profile, or pick and choose
|
||||||
individual programs.
|
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
|
## Conclusion
|
||||||
Profiles are the most important concept in devos. They allow us to keep our
|
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
|
nix expressions self contained and modular. This way we can maximize reuse
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
../users/profiles
|
|
|
@ -1,24 +1,24 @@
|
||||||
{ lib }:
|
{ lib }:
|
||||||
let
|
let
|
||||||
inherit (builtins) mapAttrs isFunction;
|
inherit (builtins) mapAttrs isFunction;
|
||||||
inherit (lib.flk) importDefaults;
|
inherit (lib.flk) mkProfileAttrs profileMap;
|
||||||
|
|
||||||
profiles = importDefaults (toString ../profiles);
|
profiles = mkProfileAttrs (toString ../profiles);
|
||||||
users = importDefaults (toString ../users);
|
users = mkProfileAttrs (toString ../users);
|
||||||
|
|
||||||
allProfiles =
|
allProfiles =
|
||||||
let
|
let defaults = lib.collect (x: x ? default) profiles;
|
||||||
sansCore = lib.filterAttrs (n: _: n != "core") profiles;
|
in map (x: x.default) defaults;
|
||||||
in
|
|
||||||
lib.collect isFunction sansCore;
|
|
||||||
|
|
||||||
allUsers = lib.collect isFunction users;
|
allUsers =
|
||||||
|
let defaults = lib.collect (x: x ? default) users;
|
||||||
|
in map (x: x.default) defaults;
|
||||||
|
|
||||||
|
|
||||||
suites = with profiles; rec {
|
suites = with profiles; rec {
|
||||||
core = [ users.nixos users.root ];
|
base = [ users.nixos users.root ];
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
mapAttrs (_: v: lib.flk.profileMap v) suites // {
|
mapAttrs (_: v: profileMap v) suites // {
|
||||||
inherit allProfiles allUsers;
|
inherit allProfiles allUsers;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue