mirror of
https://gitlab.com/rensa-nix/utils.git
synced 2025-12-10 22:50:12 +01:00
chore: initial commit
This commit is contained in:
commit
e832157e68
14 changed files with 666 additions and 0 deletions
5
lib/default.nix
Normal file
5
lib/default.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
args: {
|
||||
mkSystem = import ./mkSystem.nix args;
|
||||
mkHome = import ./mkHome.nix args;
|
||||
mkDisk = import ./mkDisk.nix args;
|
||||
}
|
||||
5
lib/flake.nix
Normal file
5
lib/flake.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
outputs = i: {
|
||||
lib = import ./.;
|
||||
};
|
||||
}
|
||||
32
lib/mkDisk.nix
Normal file
32
lib/mkDisk.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{lib}: userConfig: let
|
||||
inherit (lib) evalModules types assertMsg isAttrs;
|
||||
|
||||
evaled = evalModules {
|
||||
modules = [
|
||||
./ren-module.nix
|
||||
userConfig
|
||||
{
|
||||
config._module.check = true;
|
||||
config._module.freeformType = types.unspecified;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
disko = assert assertMsg (isAttrs evaled.config.ren.disko) "disko input unset"; evaled.config.ren.disko;
|
||||
diskoLib = import "${disko}/lib" {inherit lib;};
|
||||
|
||||
diskConfig = evalModules {
|
||||
modules = [
|
||||
./ren-module.nix
|
||||
userConfig
|
||||
{
|
||||
# required since its a type, not a module
|
||||
freeformType = diskoLib.toplevel;
|
||||
}
|
||||
];
|
||||
};
|
||||
in {
|
||||
innerConfig = builtins.removeAttrs diskConfig.config ["ren"];
|
||||
inherit (diskConfig) config options;
|
||||
scripts = diskConfig.config._scripts {inherit (evaled.config.ren) pkgs;};
|
||||
}
|
||||
35
lib/mkHome.nix
Normal file
35
lib/mkHome.nix
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{lib}: userConfig: let
|
||||
inherit (lib) evalModules types assertMsg isAttrs toString;
|
||||
evaled = evalModules {
|
||||
modules = [
|
||||
./ren-module.nix
|
||||
userConfig
|
||||
{
|
||||
config._module.check = true;
|
||||
config._module.freeformType = types.unspecified;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
home-manager = assert assertMsg (isAttrs evaled.config.ren.home-manager) "home-manager input unset"; evaled.config.ren.home-manager;
|
||||
hmLib = import (home-manager + /modules/lib/stdlib-extended.nix) lib;
|
||||
hmModules = import (home-manager + /modules/modules.nix) {
|
||||
inherit (evaled.config.ren) pkgs;
|
||||
lib = hmLib;
|
||||
check = true;
|
||||
useNixpkgsModule = false;
|
||||
};
|
||||
|
||||
homeConfig = hmLib.evalModules {
|
||||
specialArgs = {
|
||||
modulesPath = toString (evaled.config.bee.home + /modules);
|
||||
};
|
||||
modules = [./ren-module.nix userConfig] ++ hmModules;
|
||||
};
|
||||
in {
|
||||
innerConfig = {
|
||||
imports = [userConfig ./ren-module.nix];
|
||||
};
|
||||
inherit (homeConfig) options config;
|
||||
inherit (homeConfig.config.home) activationPackage;
|
||||
}
|
||||
77
lib/mkSystem.nix
Normal file
77
lib/mkSystem.nix
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
{lib}: userConfig: let
|
||||
inherit (lib) evalModules types assertMsg isAttrs optionals mkDefault;
|
||||
|
||||
evaled = evalModules {
|
||||
modules = [
|
||||
./ren-module.nix
|
||||
userConfig
|
||||
{
|
||||
config._module.check = true;
|
||||
config._module.freeformType = types.unspecified;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
isDarwin = evaled.options.ren.nix-darwin.isDefined;
|
||||
nix-darwin = assert assertMsg (isAttrs evaled.config.ren.nix-darwin) "nix-darwin input unset"; evaled.config.ren.nix-darwin;
|
||||
|
||||
baseModules = [./ren-module.nix userConfig];
|
||||
|
||||
nixosModules = import (evaled.config.ren.pkgs.path + "/nixos/modules/module-list.nix");
|
||||
darwinModules = import (evaled.config.ren.nix-darwin + "/modules/module-list.nix");
|
||||
|
||||
extraNixosConfig = {
|
||||
nixpkgs = {
|
||||
inherit (evaled.config.ren) system pkgs;
|
||||
};
|
||||
imports =
|
||||
# add home-manager if the input is passed
|
||||
optionals (evaled.options.ren.home-manager.isDefined) [
|
||||
evaled.config.ren.home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = mkDefault true;
|
||||
home-manager.useUserPackages = mkDefault false;
|
||||
}
|
||||
]
|
||||
# add nixos-wsl if the input is passed
|
||||
++ optionals (evaled.options.ren.nixos-wsl.isDefined) [
|
||||
evaled.config.ren.nixos-wsl.nixosModules.wsl
|
||||
{
|
||||
wsl.enable = mkDefault true;
|
||||
}
|
||||
]
|
||||
# add disko if the input is passed
|
||||
++ optionals (evaled.options.ren.disko.isDefined) [
|
||||
evaled.config.ren.disko.nixosModules.disko
|
||||
];
|
||||
};
|
||||
extraDarwinConfig = {
|
||||
# add home-manager if the input is passed
|
||||
imports = optionals (evaled.options.ren.home-manager.isDefined) [
|
||||
evaled.config.ren.home-manager.darwinModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = mkDefault true;
|
||||
home-manager.useUserPackages = mkDefault false;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
systemConfig = import (evaled.config.ren.pkgs.path + "/nixos/lib/eval-config.nix") {
|
||||
system = null;
|
||||
modules = baseModules ++ [extraNixosConfig] ++ nixosModules;
|
||||
};
|
||||
darwinConfig = nix-darwin.lib.darwinSystem {
|
||||
inherit (evaled.config.ren) system pkgs;
|
||||
modules = baseModules ++ [extraDarwinConfig] ++ darwinModules;
|
||||
};
|
||||
in
|
||||
(
|
||||
if isDarwin
|
||||
then darwinConfig
|
||||
else systemConfig
|
||||
)
|
||||
// {
|
||||
innerConfig = {
|
||||
imports = [userConfig ./ren-module.nix];
|
||||
};
|
||||
}
|
||||
50
lib/ren-module.nix
Normal file
50
lib/ren-module.nix
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkOption mkOptionType types isAttrs hasAttr;
|
||||
mkInputOption = description:
|
||||
mkOption {
|
||||
type = mkOptionType {
|
||||
name = "input";
|
||||
description = "a flake input";
|
||||
check = x: (isAttrs x) && (hasAttr "sourceInfo" x);
|
||||
};
|
||||
description = ''
|
||||
The flake input for ${description}.
|
||||
|
||||
Example:
|
||||
ren.home-manager = inputs.home-manager;
|
||||
'';
|
||||
};
|
||||
in {
|
||||
options.ren = {
|
||||
system = mkOption {
|
||||
type = types.str;
|
||||
description = ''
|
||||
The system architecture (e.g., 'x86_64-linux', 'aarch64-darwin').
|
||||
'';
|
||||
};
|
||||
|
||||
home-manager = mkInputOption "Home Manager";
|
||||
disko = mkInputOption "Disko";
|
||||
nixos-wsl = mkInputOption "NixOS-WSL";
|
||||
nix-darwin = mkInputOption "nix-darwin";
|
||||
|
||||
pkgs = mkOption {
|
||||
type = mkOptionType {
|
||||
name = "packages";
|
||||
description = "instance of nixpkgs";
|
||||
check = x: (isAttrs x) && (hasAttr "path" x);
|
||||
};
|
||||
description = ''
|
||||
An instantiated nixpkgs set. Used for general pkgs and to get NixOS systems' modules.
|
||||
'';
|
||||
apply = x:
|
||||
if (hasAttr "${config.ren.system or "unset"}" x)
|
||||
then x.${config.ren.system}
|
||||
else x;
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue