← ../

configuration files

unlike typical a static config file in /etc/myservice, the configuration files often (always?) end up in the /nix/store. Sometimes, the config will be directly added in the ExecStart directive of the systemd unit file, and sometimes, the traditional /etc/myservice/myservice.conf will be a symlink to the real configuration file in the nix store.

each time you change a configuration file, it will create a new version. Since all files in the nix store have the same date+time it can be hard to figure out which file is the last one.

to find the configuration file, either issue the command systemctl cat myservice or ls -la /etc/myservice/myservice.conf

to get rid of the old versions of the config files, you can run nix-collect-garbage -d manual here


modules

modules are useful when you want to sepatate a configuration from your main /etc/nixos/configuration.nix

a good use case is a daemon with a lot of options, you would not want to clutter your main configuration file…

modules can be a function or not. if it is a function (denoted by :), it can accept an attribute set {} as follows :

{ config, pkgs, ... }:

common attributes that you can pass to the function :

config : The configuration of the entire system.

options : All option declarations refined with all definition and declaration references. (the options passed to this function/module ?)

pkgs : The attribute set extracted from the Nix package collection and enhanced with the nixpkgs.config option.

modulesPath : the location of the module directory of NixOS.

lib : The module system is defined in the lib, which include all the functions used to change the definitions such as mkForce and mkIf, as well as all function used to declare options such mkOption or types.

... : extra arguments to pass to this function, without it, the function will only accept exactly the number of parameters passed

so while a module that is not a function will look like :

{
  imports = [
    # Paths to other modules.
    # Compose this module out of smaller ones.
  ];

  options = {
    # Option declarations.
    # Declare what settings a user of this module module can set.
    # Usually this includes a global "enable" option which defaults to false.
  };

  config = {
    # Option definitions.
    # Define what other settings, services and resources should be active.
    # Usually these depend on whether a user of this module chose to "enable" it
    # using the "option" above. 
    # Options for modules imported in "imports" can be set here.
  };
}

a module that is a function and that accept parameters will look like

{ config, pkgs, ... }:

{
  #imports = [
  #  # Paths to other modules.
  #  # Compose this module out of smaller ones.
  #];

  #options = {
  #  # Option declarations.
  #  # Declare what settings a user of this module module can set.
  #  # Usually this includes a global "enable" option which defaults to false.
  #};

  #config = {
  #  # Option definitions.
  #  # Define what other settings, services and resources should be active.
  #  # Usually these depend on whether a user of this module chose to "enable" it
  #  # using the "option" above.
  #  # Options for modules imported in "imports" can be set here.
  #};
  environment.systemPackages = [
    pkgs.postfix
   ];
  services.postfix.enable = true; }

flakes

This an experimental feature that allows you to pin the version of the dependencies. This allows to improve the reproductibility of nix installations by making sure dependencies are not linked to the nix channel

flakes have an input attribute where you can specify the dependencies.

once the inputs are resolved, they will be passed to an output function based on a pre-defined schema (outputs is a function of one argument that takes an attribute set of all the realized inputs, and outputs another attribute set )

see the Flake schema and the Output Schema


other/to classify

disons que tu veux créer un fichier, tu utiliserais quoi? - writeText qu’y est un trivial builder qu’y retourne une dérivation (un shortcut au lieu faire faire mkDerivation à la main)