diff options
author | Jasper Ras <jras@hostnet.nl> | 2025-03-20 11:07:49 +0100 |
---|---|---|
committer | Jasper Ras <jras@hostnet.nl> | 2025-03-20 11:07:49 +0100 |
commit | 80ccf68f55dbb70d7e5ed52ee95b3c9d1b6ce264 (patch) | |
tree | 93e28e85ab70052aa6f577998ec7dc1f413b40c0 /3 Resources/Nix/NixOS Modules.md | |
parent | 9642cd7ae24f0ba79ce5647c709b35ae8f06a285 (diff) |
vault backup: 2025-03-20 11:07:48
Diffstat (limited to '3 Resources/Nix/NixOS Modules.md')
-rw-r--r-- | 3 Resources/Nix/NixOS Modules.md | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/3 Resources/Nix/NixOS Modules.md b/3 Resources/Nix/NixOS Modules.md new file mode 100644 index 0000000..1ab4c25 --- /dev/null +++ b/3 Resources/Nix/NixOS Modules.md @@ -0,0 +1,56 @@ +--- +tags: + - nix + - nixos +references: + - https://nixos.org/manual/nixos/unstable/#sec-writing-modules + - https://nixos.org/manual/nixpkgs/stable/#module-system-lib-evalModules + - https://nix.dev/tutorials/module-system/ + - llk +--- +Extra care must be taken when writing systemd services using Exec* due to interpolation and such. `utils.escapeSystemdExecArg` and `utils.escapeSystemdExecArg` exist. + +```nix +{ + options = { + name = mkOption { + type = type specification; + default = default value; + example = example value; + description = "Description for use in the NixOS manual."; + }; + }; +} +``` + +**A list of submodules** +```nix +{ + options.mod = mkOption { + description = "submodule example"; + type = with types; listOf (submodule { + options = { + foo = mkOption { + type = int; + }; + bar = mkOption { + type = str; + }; + }; + }); + }; +} +``` + + +**Testing** +```nix eval.nix +let + pkgs = import <nixpkgs> {}; + res = pkgs.lib.evalModules { + modules = [./git-repos.nix]; + }; +in +res.config +``` +`nix-instantiate --eval eval.nix`
\ No newline at end of file |