NixOS 与 Flakes 阅读笔记 - Nixpkgs Module 系统

Tuesday, April 30, 2024

Nixpkgs Module 结构的简单介绍

e.g. for a simple Nixpkgs Module:

{lib, config, options, pkgs, ...}:
{
  imports = [
    # ......
    # ./xxx.nix
  ];

  for.bar.enable = true;
  # other options declarations
  # ...
}

args

lib: nixpkgs fuctions lib config: the set of current env options options: the set of current env defined options pkgs: the set of entire nixpkgs default: nixpkgs.legacyPackages."${system}" can be defined by nixpkgs.pkgs modulesPath: Path nixpkgs/nixos/modules

other args

flakes.nix

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
    another-input.url = "github:username/repo-name/branch-name";
    helix.url = "github:helix-editor/helix/master";
  };

  outputs = inputs@{ self, nixpkgs, another-input, ... }: {
    nixosConfigurations.my-nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        {
          _module.args = { inherit inputs; };
        }
      ];
    };
  };
}

configuration.nix

{ config, pkgs, inputs, ... }:
{
  environment.systemPackages = with pkgs; [
    git vim wget curl
    inputs.helix.packages."${pkgs.system}".helix
  ];
}

ref: https://nixos-and-flakes.thiscute.world/zh/nixos-with-flakes/nixos-flake-and-module-system

NixOSLinuxNixOSFlakes

NixOS 与 Flakes 阅读笔记 - 安装使用 Home Manager