mirror of
https://github.com/RGBCube/hjem
synced 2025-10-13 21:22:17 +00:00
lib: liberate from the module system (fixes #52)
This commit is contained in:
parent
565a15366d
commit
e026bdfcf6
4 changed files with 159 additions and 135 deletions
20
flake.nix
20
flake.nix
|
@ -21,7 +21,19 @@
|
||||||
forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux"];
|
forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux"];
|
||||||
in {
|
in {
|
||||||
nixosModules = {
|
nixosModules = {
|
||||||
hjem = ./modules/nixos;
|
hjem = {
|
||||||
|
imports = [
|
||||||
|
self.nixosModules.hjem-lib
|
||||||
|
./modules/nixos
|
||||||
|
];
|
||||||
|
};
|
||||||
|
hjem-lib = {
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
_module.args.hjem-lib = import ./lib.nix {inherit lib pkgs;};
|
||||||
|
};
|
||||||
default = self.nixosModules.hjem;
|
default = self.nixosModules.hjem;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,5 +97,11 @@
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
hjem-lib = forAllSystems (system:
|
||||||
|
import ./lib.nix {
|
||||||
|
inherit (nixpkgs) lib;
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
22
lib.nix
22
lib.nix
|
@ -1,21 +1,22 @@
|
||||||
{
|
{
|
||||||
config,
|
|
||||||
lib,
|
lib,
|
||||||
osOptions,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
|
||||||
}: let
|
}: let
|
||||||
inherit (builtins) isList;
|
inherit (builtins) isList;
|
||||||
inherit (lib.modules) mkDefault mkDerivedConfig mkIf mkMerge;
|
inherit (lib.modules) mkDefault mkDerivedConfig mkIf mkMerge;
|
||||||
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
inherit (lib.options) literalExpression mkEnableOption mkOption;
|
||||||
inherit (lib.strings) concatMapStringsSep hasPrefix;
|
inherit (lib.strings) concatMapStringsSep hasPrefix;
|
||||||
inherit (lib.types) addCheck anything attrsOf bool either functionTo lines nullOr path str submodule;
|
inherit (lib.types) addCheck anything attrsOf bool either functionTo int lines listOf nullOr oneOf path str submodule;
|
||||||
cfg = config;
|
|
||||||
in {
|
in {
|
||||||
_module.args.hjem = {
|
# inlined from https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/config/shells-environment.nix
|
||||||
envVarType = osOptions.environment.variables.type;
|
# using osOptions precludes using hjem (or this type) standalone
|
||||||
|
envVarType = attrsOf (nullOr (oneOf [(listOf (oneOf [int str path])) int str path]));
|
||||||
|
|
||||||
fileTypeRelativeTo = rootDir:
|
fileTypeRelativeTo = {
|
||||||
|
rootDir,
|
||||||
|
clobberDefault,
|
||||||
|
clobberDefaultText,
|
||||||
|
}:
|
||||||
submodule ({
|
submodule ({
|
||||||
name,
|
name,
|
||||||
target,
|
target,
|
||||||
|
@ -92,8 +93,8 @@ in {
|
||||||
|
|
||||||
clobber = mkOption {
|
clobber = mkOption {
|
||||||
type = bool;
|
type = bool;
|
||||||
default = cfg.clobberFiles;
|
default = clobberDefault;
|
||||||
defaultText = literalExpression "config.hjem.clobberByDefault";
|
defaultText = clobberDefaultText;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to "clobber" existing target paths.
|
Whether to "clobber" existing target paths.
|
||||||
|
|
||||||
|
@ -143,5 +144,4 @@ in {
|
||||||
if isList env
|
if isList env
|
||||||
then concatMapStringsSep ":" toString env
|
then concatMapStringsSep ":" toString env
|
||||||
else toString env;
|
else toString env;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,14 @@
|
||||||
# be avoided here.
|
# be avoided here.
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
hjem,
|
hjem-lib,
|
||||||
lib,
|
lib,
|
||||||
|
name,
|
||||||
options,
|
options,
|
||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (hjem) envVarType fileTypeRelativeTo toEnv;
|
inherit (hjem-lib) envVarType toEnv;
|
||||||
inherit (lib.attrsets) mapAttrsToList;
|
inherit (lib.attrsets) mapAttrsToList;
|
||||||
inherit (lib.strings) concatLines;
|
inherit (lib.strings) concatLines;
|
||||||
inherit (lib.modules) mkIf;
|
inherit (lib.modules) mkIf;
|
||||||
|
@ -18,13 +19,17 @@
|
||||||
inherit (lib.types) attrsOf bool listOf package path str;
|
inherit (lib.types) attrsOf bool listOf package path str;
|
||||||
|
|
||||||
cfg = config;
|
cfg = config;
|
||||||
|
fileTypeRelativeTo' = rootDir:
|
||||||
|
hjem-lib.fileTypeRelativeTo {
|
||||||
|
inherit rootDir;
|
||||||
|
clobberDefault = cfg.clobberFiles;
|
||||||
|
clobberDefaultText = literalExpression "config.hjem.users.${name}.clobberFiles";
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
imports = [
|
imports = [
|
||||||
# Makes "assertions" option available without having to duplicate the work
|
# Makes "assertions" option available without having to duplicate the work
|
||||||
# already done in the Nixpkgs module.
|
# already done in the Nixpkgs module.
|
||||||
(pkgs.path + "/nixos/modules/misc/assertions.nix")
|
(pkgs.path + "/nixos/modules/misc/assertions.nix")
|
||||||
|
|
||||||
../../lib.nix
|
|
||||||
];
|
];
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
@ -63,7 +68,7 @@ in {
|
||||||
|
|
||||||
files = mkOption {
|
files = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
type = attrsOf (fileTypeRelativeTo cfg.directory);
|
type = attrsOf (fileTypeRelativeTo' cfg.directory);
|
||||||
example = {".config/foo.txt".source = "Hello World";};
|
example = {".config/foo.txt".source = "Hello World";};
|
||||||
description = "Files to be managed by Hjem";
|
description = "Files to be managed by Hjem";
|
||||||
};
|
};
|
||||||
|
@ -84,7 +89,7 @@ in {
|
||||||
};
|
};
|
||||||
files = mkOption {
|
files = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
type = attrsOf (fileTypeRelativeTo cfg.xdg.cache.directory);
|
type = attrsOf (fileTypeRelativeTo' cfg.xdg.cache.directory);
|
||||||
example = {"foo.txt".source = "Hello World";};
|
example = {"foo.txt".source = "Hello World";};
|
||||||
description = "Cache files to be managed by Hjem";
|
description = "Cache files to be managed by Hjem";
|
||||||
};
|
};
|
||||||
|
@ -105,7 +110,7 @@ in {
|
||||||
};
|
};
|
||||||
files = mkOption {
|
files = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
type = attrsOf (fileTypeRelativeTo cfg.xdg.config.directory);
|
type = attrsOf (fileTypeRelativeTo' cfg.xdg.config.directory);
|
||||||
example = {"foo.txt".source = "Hello World";};
|
example = {"foo.txt".source = "Hello World";};
|
||||||
description = "Config files to be managed by Hjem";
|
description = "Config files to be managed by Hjem";
|
||||||
};
|
};
|
||||||
|
@ -126,7 +131,7 @@ in {
|
||||||
};
|
};
|
||||||
files = mkOption {
|
files = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
type = attrsOf (fileTypeRelativeTo cfg.xdg.data.directory);
|
type = attrsOf (fileTypeRelativeTo' cfg.xdg.data.directory);
|
||||||
example = {"foo.txt".source = "Hello World";};
|
example = {"foo.txt".source = "Hello World";};
|
||||||
description = "data files to be managed by Hjem";
|
description = "data files to be managed by Hjem";
|
||||||
};
|
};
|
||||||
|
@ -147,7 +152,7 @@ in {
|
||||||
};
|
};
|
||||||
files = mkOption {
|
files = mkOption {
|
||||||
default = {};
|
default = {};
|
||||||
type = attrsOf (fileTypeRelativeTo cfg.xdg.state.directory);
|
type = attrsOf (fileTypeRelativeTo' cfg.xdg.state.directory);
|
||||||
example = {"foo.txt".source = "Hello World";};
|
example = {"foo.txt".source = "Hello World";};
|
||||||
description = "state files to be managed by Hjem";
|
description = "state files to be managed by Hjem";
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
|
hjem-lib,
|
||||||
lib,
|
lib,
|
||||||
options,
|
options,
|
||||||
pkgs,
|
pkgs,
|
||||||
|
@ -10,7 +11,7 @@
|
||||||
inherit (lib.options) literalExpression mkOption;
|
inherit (lib.options) literalExpression mkOption;
|
||||||
inherit (lib.strings) optionalString;
|
inherit (lib.strings) optionalString;
|
||||||
inherit (lib.trivial) pipe;
|
inherit (lib.trivial) pipe;
|
||||||
inherit (lib.types) attrs attrsOf bool listOf nullOr package raw submoduleWith either singleLineStr;
|
inherit (lib.types) attrs attrsOf bool either listOf nullOr package raw singleLineStr submoduleWith;
|
||||||
inherit (lib.meta) getExe;
|
inherit (lib.meta) getExe;
|
||||||
inherit (builtins) filter attrNames attrValues mapAttrs getAttr concatLists concatStringsSep typeOf toJSON concatMap;
|
inherit (builtins) filter attrNames attrValues mapAttrs getAttr concatLists concatStringsSep typeOf toJSON concatMap;
|
||||||
|
|
||||||
|
@ -78,7 +79,7 @@
|
||||||
specialArgs =
|
specialArgs =
|
||||||
cfg.specialArgs
|
cfg.specialArgs
|
||||||
// {
|
// {
|
||||||
inherit pkgs;
|
inherit hjem-lib pkgs;
|
||||||
osConfig = config;
|
osConfig = config;
|
||||||
osOptions = options;
|
osOptions = options;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue