1

Nixos: Remove mkLink + mkEnableOpt and rename mkBoolOpt

This commit is contained in:
2024-10-12 17:31:01 +02:00
parent bd50e4539e
commit 4eddef07be
32 changed files with 156 additions and 172 deletions

View File

@ -4,6 +4,9 @@
lib,
...
}: {
# Import my own library functions.
# Those are defined as functions returning sets of library functions,
# so those functions have to be called when importing.
nixos = import ./nixos.nix {inherit inputs pkgs lib;};
modules = import ./modules.nix {inherit inputs pkgs lib;};
networking = import ./networking.nix {inherit inputs pkgs lib;};

View File

@ -1,63 +1,44 @@
# TODO: Easier mkLink/mkUnlink (include more hm.dag stuff into the function)
{
inputs,
pkgs,
lib,
...
}: rec {
# Conveniance wrapper for mkOption with boolean type
mkBoolOpt = def: desc:
# Convenience wrapper for "mkOption" with boolean type.
mkBoolOption = def: desc:
lib.mkOption {
type = lib.types.bool;
default = def;
description = desc;
};
# Alias for consistency
mkEnableOpt = lib.mkEnableOption;
# Like mkIf but the predicate is inverted
# Like "lib.mkIf" but the predicate is inverted.
# Returns "do" if "pred" is false.
mkElse = pred: do: (lib.mkIf (!pred) do);
# Creates a symlink if it doesn't exist
# If it exists renew the link
mkLink = src: dest: ''
if [ -L "${dest}" ]; then
rm ${dest}
fi
ln -sf ${src} ${dest}
'';
# Removes a symlink if it exists
mkUnlink = dest: ''
if [ -L "${dest}" ]; then
rm ${dest}
fi
'';
# Returns true if base contains element
# Returns "true" if "base" contains "element".
contains = base: element:
lib.any (x: x == element) base;
# Returns base without occurences of elements that are also in remove
# Returns "base" without occurences of elements that are also in "remove".
without = base: remove:
lib.filter (x: !(contains remove x)) base;
# For use with single element sets
# Used with attrSets with a single element.
# Returns the name of the single attr.
attrName = set: let
names = lib.attrNames set;
in (
in
if (names != [])
then (lib.head names)
else null
);
else null;
# For use with single element sets
# Used with attrSets with a single element.
# Returns the value of the single attr.
attrValue = set: let
values = lib.attrValues set;
in (
in
if (values != [])
then (lib.head values)
else null
);
else null;
}

View File

@ -14,36 +14,40 @@
lib.nixosSystem {
inherit system;
# Make our inputs available to the configuration.nix (for importing modules)
# specialArgs are propagated to all modules
# Values in "specialArgs" are propagated to all system modules.
specialArgs = {inherit inputs hostname mylib system username;};
modules = builtins.concatLists [
[
# Replace the pkgs to include overlays/unfree
# Replace the default "pkgs" with my configured version
# to allow installation of unfree software and my own overlays.
{nixpkgs.pkgs = pkgs;}
# Main config file for all configs/hosts
# Import the toplevel system configuration module.
../system
]
extraModules
# HM is installed as a system module
# HM is installed as a system module when using mkNixosConfigWithHomeManagerModule.
[
inputs.home-manager.nixosModules.home-manager
{
# extraSpecialArgs are propagated to all hm config modules
home-manager.extraSpecialArgs = {inherit inputs hostname username mylib;};
home-manager = {
# Values in "extraSpecialArgs" are propagated to all HM modules.
extraSpecialArgs = {inherit inputs hostname username mylib;};
# Use systems pkgs, disables nixpkgs.* options in home.nix
home-manager.useGlobalPkgs = true;
# Use the "pkgs" from the system configuration.
# This disables "nixpkgs.*" options in HM modules.
useGlobalPkgs = true;
# Enable installing packages through users.christoph.packages to /etc/profiles instead of ~/.nix-profile
home-manager.useUserPackages = true;
# Packages in "users.${username}.packages" will be installed
# to /etc/profiles instead of ~/.nix-profile.
useUserPackages = true;
# User specific config file
home-manager.users.${username}.imports = [../home/${username}];
# Import the user-specific HM toplevel module.
users.${username}.imports = [../home/${username}];
};
}
]
];
@ -58,16 +62,16 @@
lib.nixosSystem {
inherit system;
# Make our inputs available to the configuration.nix (for importing modules)
# specialArgs are propagated to all modules
# Values in "specialArgs" are propagated to all system modules.
specialArgs = {inherit inputs hostname mylib system;};
modules = builtins.concatLists [
[
# Replace the pkgs to include overlays/unfree
# Replace the default "pkgs" with my configured version
# to allow installation of unfree software and my own overlays.
{nixpkgs.pkgs = pkgs;}
# Main config file for all configs/hosts
# Import the toplevel system configuration module.
../system
]
@ -85,11 +89,12 @@
inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
# HM propagates these to every module
# Values in "extraSpecialArgs" are propagated to all HM modules.
extraSpecialArgs = {inherit inputs system mylib username hostname;};
modules = builtins.concatLists [
[
# Import the user-specific HM toplevel module.
../home/${username}
]