Facebook
From dob, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 145
  1. {
  2.     description = "pqq's (aka. dob) nixos flake config with home-manager";
  3.  
  4.     # This is the standard format for flake.nix.
  5.     # `inputs` are the dependencies of the flake,
  6.     # and `outputs` function will return all the build results of the flake.
  7.     # Each item in `inputs` will be passed as a parameter to
  8.     # the `outputs` function after being pulled and built.
  9.  
  10.     inputs = {
  11.         # There are many ways to reference flake inputs.
  12.         # The most widely used is `github:owner/name/reference`,
  13.         # which represents the GitHub repository URL + branch/commit-id/tag.
  14.  
  15.         # example of getting using a specific commit hash:
  16.         # https://discourse.nixos.org/t/cant-update-nvidia-driver-on-stable-branch/39246/17?u=dob
  17.  
  18.         # official nixos package source
  19.         nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
  20.  
  21.         # unstable nixpkgs
  22.         nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
  23.  
  24.         # home manager, used for managing user configuration
  25.         # https://nixos.wiki/wiki/Home_Manager
  26.         # https://nix-community.github.io/home-manager/
  27.         home-manager = {
  28.             url = "github:nix-community/home-manager/release-23.11";
  29.             # The `follows` keyword in inputs is used for inheritance.
  30.             # Here, `inputs.nixpkgs` of home-manager is kept consistent with
  31.             # the `inputs.nixpkgs` of the current flake,
  32.             # to avoid problems caused by different versions of nixpkgs.
  33.             inputs.nixpkgs.follows = "nixpkgs";
  34.         };
  35.  
  36.     };
  37.  
  38.     # `outputs` are all the build result of the flake.
  39.     #
  40.     # A flake can have many use cases and different types of outputs.
  41.     #
  42.     # parameters in function `outputs` are defined in `inputs` and
  43.     # can be referenced by their names. However, `self` is an exception,
  44.     # this special parameter points to the `outputs` itself(self-reference)
  45.     #
  46.     # The `@` syntax here is used to alias the attribute set of the
  47.     # inputs's parameter, making it convenient to use inside the function.
  48.     outputs = {
  49.         self,
  50.         nixpkgs,
  51.         home-manager,
  52.         ...
  53.     } @ inputs: let
  54.         inherit (self) outputs;
  55.  
  56.         # When applied, the unstable nixpkgs set (declared in the flake inputs) will
  57.         # be accessible through 'pkgs.unstable'
  58.         unstable-packages = final: _prev: {
  59.             unstable = import inputs.nixpkgs-unstable {
  60.                 system = final.system;
  61.                 config.allowUnfree = true;
  62.             };
  63.         };
  64.  
  65.     in {
  66.  
  67.         # NixOS configuration entrypoint
  68.         # Available through 'nixos-rebuild --flake .#your-hostname'
  69.         nixosConfigurations = {
  70.  
  71.             # By default, NixOS will try to refer the nixosConfiguration with
  72.             # its hostname, so the system named `t470p` will use this one.
  73.             # However, the configuration name can also be specified using:
  74.             #   sudo nixos-rebuild switch --flake /path/to/flakes/directory#<name>
  75.             #
  76.             # The `nixpkgs.lib.nixosSystem` function is used to build this
  77.             # configuration, the following attribute set is its parameter.
  78.             #
  79.             # Run the following command in the flake's directory to
  80.             # deploy this configuration on any NixOS system:
  81.             #   sudo nixos-rebuild switch --flake .#nixos-test
  82.  
  83.             "t470p" = nixpkgs.lib.nixosSystem {
  84.                 system = "x86_64-linux";
  85.  
  86.                 # The Nix module system can modularize configuration,
  87.                 # improving the maintainability of configuration.
  88.                 #
  89.                 # Each parameter in the `modules` is a Nixpkgs Module, and
  90.                 # there is a partial introduction to it in the nixpkgs manual:
  91.                 #    <https://nixos.org/manual/nixpkgs/unstable/#module-system-introduction>
  92.                 # It is said to be partial because the documentation is not
  93.                 # complete, only some simple introductions.
  94.                 # such is the current state of Nix documentation...
  95.                 #
  96.                 # A Nixpkgs Module can be an attribute set, or a function that
  97.                 # returns an attribute set. By default, if a Nixpkgs Module is a
  98.                 # function, this function has the following default parameters:
  99.                 #
  100.                 #  lib:     the nixpkgs function library, which provides many
  101.                 #             useful functions for operating Nix expressions:
  102.                 #             https://nixos.org/manual/nixpkgs/stable/#id-1.4
  103.                 #  config:  all config options of the current flake, very useful
  104.                 #  options: all options defined in all NixOS Modules
  105.                 #             in the current flake
  106.                 #  pkgs:   a collection of all packages defined in nixpkgs,
  107.                 #            plus a set of functions related to packaging.
  108.                 #            you can assume its default value is
  109.                 #            `nixpkgs.legacyPackages."${system}"` for now.
  110.                 #            can be customed by `nixpkgs.pkgs` option
  111.                 #  modulesPath: the default path of nixpkgs's modules folder,
  112.                 #               used to import some extra modules from nixpkgs.
  113.                 #               this parameter is rarely used,
  114.                 #               you can ignore it for now.
  115.                 #
  116.                 # The default parameters mentioned above are automatically
  117.                 # generated by Nixpkgs.
  118.                 # However, if you need to pass other non-default parameters
  119.                 # to the submodules,
  120.                 # you'll have to manually configure these parameters using
  121.                 # `specialArgs`.
  122.                 # you must use `specialArgs` by uncommenting the following line:
  123.                 #
  124.                 # specialArgs = {...};  # pass custom arguments into all submodules.
  125.  
  126.                 specialArgs = {inherit inputs outputs;};
  127.  
  128.                 modules = [
  129.                     # > Our main nixos configuration file <
  130.                     ./hosts/t470p/configuration.nix
  131.  
  132.                     home-manager.nixosModules.home-manager
  133.                     {
  134.                         # use the global pkgs that is configured via the system level nixpkgs options
  135.                         home-manager.useGlobalPkgs = true;
  136.  
  137.                         # install packages to /etc/profiles
  138.                         home-manager.useUserPackages = true;
  139.  
  140.                         # import home manager settings
  141.                         home-manager.users.poq = import ./home-manager/home.nix;
  142.  
  143.                         # Optionally, use home-manager.extraSpecialArgs to pass
  144.                         # arguments to home.nix
  145.                     }
  146.                 ];
  147.             };
  148.         };
  149.     };
  150. }
  151.