added comments for casual readers
This commit is contained in:
@@ -1,12 +1,25 @@
|
|||||||
{inputs, ...}: {
|
{inputs, ...}: {
|
||||||
|
# PerSystem, gives access to self' and inputs', as well as some helper functions
|
||||||
perSystem = {pkgs, ...}: {
|
perSystem = {pkgs, ...}: {
|
||||||
|
# Define packages as you would in a normal flake
|
||||||
packages = {
|
packages = {
|
||||||
|
# Most basic package definition, gives #example output that runs pkgs.hello
|
||||||
|
# All packages are outputs, and all outputs can be built, run and cached, etc.
|
||||||
example = pkgs.hello;
|
example = pkgs.hello;
|
||||||
|
# Universal wrapper, use this to quickly add flags to a program
|
||||||
bash = inputs.wrappers.lib.wrapPackage {
|
bash = inputs.wrappers.lib.wrapPackage {
|
||||||
|
# Always inherit pkgs
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
|
# Set package, could be anything
|
||||||
package = pkgs.bash;
|
package = pkgs.bash;
|
||||||
|
# Flag set, once again can be anything
|
||||||
|
# Nix doesn't know what flags are valid, it will accept any two valid nix objects
|
||||||
|
# Data types are irrelevant, can be paths, ints, bools, etc.
|
||||||
flags = {
|
flags = {
|
||||||
"--rcfile" = ./bashrc;
|
"--rcfile" = ./bashrc;
|
||||||
|
# to add the same flag twice, make the right hand side a set
|
||||||
|
# "--someflag" = {"firstTime", "secondTime"}
|
||||||
|
# You cannot repeat the left hand side
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,24 +1,50 @@
|
|||||||
{
|
{
|
||||||
inputs,
|
inputs,
|
||||||
|
# moduleWithSystem allows for using self' in modules
|
||||||
moduleWithSystem,
|
moduleWithSystem,
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
|
# enclose moduleWithSystem expression in (), so the final expression is one object
|
||||||
flake.nixosModules.zsh = moduleWithSystem ({
|
flake.nixosModules.zsh = moduleWithSystem ({
|
||||||
pkgs,
|
pkgs,
|
||||||
|
# Self' allows accessing packages without having to point to the os string
|
||||||
self',
|
self',
|
||||||
...
|
...
|
||||||
}: {config, ...}: let
|
}:
|
||||||
|
# This is a "double expression", being written like {...}: {...}: {};
|
||||||
|
# having an extra {...}. This is because the first attribute set only contains
|
||||||
|
# flake parts attributes (self', flake.nixosModules, etc), and not nixos attributes.
|
||||||
|
# The usual nixos attributes, like config, are passed into a potential second attribute
|
||||||
|
# set, allowing you to access them there. This set is not implicit, and must be defined.
|
||||||
|
# This means that the code can be read as:
|
||||||
|
# {flake-parts attrs}: {nix attrs}: {actual expression};
|
||||||
|
{config, ...}:
|
||||||
|
# A let in statement allows setting of variables, in this case pointing any reference
|
||||||
|
# of "lib" to "pkgs.lib". These can be stacked, and can be thought of as a way of
|
||||||
|
# scoping variables.
|
||||||
|
let
|
||||||
lib = pkgs.lib;
|
lib = pkgs.lib;
|
||||||
in {
|
in {
|
||||||
|
# When the config or options objects are defined, nothing else can be in the expression.
|
||||||
|
# Options contains a list of defined options, and config becomes the wrapper for everything
|
||||||
|
# else in the expression. Imports works as expected.
|
||||||
imports = [];
|
imports = [];
|
||||||
options = {
|
options = {
|
||||||
|
# Make a new option with lib.mkOption
|
||||||
enableHighlighting = lib.mkOption {
|
enableHighlighting = lib.mkOption {
|
||||||
|
# Set type, eg bool, str, int. Custom types can be created
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
|
# Default value is required
|
||||||
default = false;
|
default = false;
|
||||||
|
# Description is optional but useful
|
||||||
description = "Enable syntax highlighting";
|
description = "Enable syntax highlighting";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
|
# Nixpkgs overlay, replacing the universal "pkgs.zsh" with "self'.packages.zsh".
|
||||||
|
# As stated, self' allows you to shorten the package definition from
|
||||||
|
# self.${pkgs.stdenv.hostPlatform.system}.packages.zsh;
|
||||||
|
# into just self'.packages.zsh, meaning package platform errors are almost impossible.
|
||||||
nixpkgs.overlays = [
|
nixpkgs.overlays = [
|
||||||
(final: prev: {
|
(final: prev: {
|
||||||
zsh = self'.packages.zsh;
|
zsh = self'.packages.zsh;
|
||||||
@@ -26,25 +52,37 @@
|
|||||||
];
|
];
|
||||||
programs.zsh = {
|
programs.zsh = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
# You can use config options through the config attribute, in place of a normal value,
|
||||||
|
# the same way you can in other programming languages.
|
||||||
enableSyntaxHighlighting = config.enableHighlighting;
|
enableSyntaxHighlighting = config.enableHighlighting;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
# PerSystem should be defined in the same scope as flake.nixosModules
|
||||||
perSystem = {
|
perSystem = {
|
||||||
|
# Inherited from inputs.nixpkgs
|
||||||
pkgs,
|
pkgs,
|
||||||
|
# Custom arg, see modules/system/nix-settings.nix
|
||||||
unstablePkgs,
|
unstablePkgs,
|
||||||
|
# Same principle of self', removes need for direct reference to os-string
|
||||||
inputs',
|
inputs',
|
||||||
|
# Helper, points to pkgs.lib
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: {
|
}: {
|
||||||
|
# Defined wrapper for zsh, docs are on nix-wrapper modules site
|
||||||
packages.zsh = inputs.wrappers.wrappers.zsh.wrap {
|
packages.zsh = inputs.wrappers.wrappers.zsh.wrap {
|
||||||
|
# Pkgs MUST be defined, always inherit pkgs in a wrapper
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
zshAliases = {
|
zshAliases = {
|
||||||
|
# By making an alias reference a package, zsh becomes dependant on that package.
|
||||||
|
# This idea allows for fully portable modules with implicit dependancy trees
|
||||||
some = lib.getExe unstablePkgs.vim;
|
some = lib.getExe unstablePkgs.vim;
|
||||||
v = lib.getExe inputs'.nvim.packages.default;
|
v = lib.getExe inputs'.nvim.packages.default;
|
||||||
ff = lib.getExe pkgs.fastfetch;
|
ff = lib.getExe pkgs.fastfetch;
|
||||||
cat = lib.getExe pkgs.bat;
|
cat = lib.getExe pkgs.bat;
|
||||||
};
|
};
|
||||||
|
# Can also be zshrc.path, and path will take precedence over content.
|
||||||
zshrc.content = ''
|
zshrc.content = ''
|
||||||
export SOME=some
|
export SOME=some
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -11,6 +11,11 @@
|
|||||||
newHostConfiguration
|
newHostConfiguration
|
||||||
system
|
system
|
||||||
zsh
|
zsh
|
||||||
|
|
||||||
|
# Change config options in this object
|
||||||
|
# This can be done per-host with different options,
|
||||||
|
# allowing for smaller changes to modules' functionality
|
||||||
|
# Without having to create a whole new module
|
||||||
({...}: {
|
({...}: {
|
||||||
enableHighlighting = true;
|
enableHighlighting = true;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,23 @@
|
|||||||
{inputs, ...}: {
|
{inputs, ...}: {
|
||||||
|
# PerSystem, allows for universal module access
|
||||||
perSystem = {system, ...}: {
|
perSystem = {system, ...}: {
|
||||||
|
# Pre-defined object
|
||||||
_module.args = {
|
_module.args = {
|
||||||
|
# Custom object, creating a new nixpkgs from a different input
|
||||||
unstablePkgs = import inputs.nixpkgs-unstable {
|
unstablePkgs = import inputs.nixpkgs-unstable {
|
||||||
inherit system;
|
inherit system;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Another example not in the video, creating an unfree instance of nixpkgs
|
||||||
|
# Setting nixpkgs.config.free = true isn't possible through a normal nixosModule,
|
||||||
|
# because of how inheritance works with nixos exclusive objects
|
||||||
|
unfreePkgs = import inputs.nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
config.allowUnfree = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
# You can also set universal variables here, if you need to access the same info across files
|
||||||
|
someVariable = "import this as you would import pkgs, in a perSystem block";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user