82 Matching Annotations
  1. Last 7 days
    1. type Option type, providing type-checking and value merging.

      This is vague to the point of being useless, given the Nix expression language is untyped.

      A snippet from freeswitch.nix:

            configTemplate = mkOption {
              type = types.path;
              # omitted
            };
            configDir = mkOption {
              type = with types; attrsOf path;
              # omitted
            };
      
      • Where does types come from?

        See NixOS manual at "Option types".

      • What is the difference between the path types? (I guess, the second one is attribute set consisting only of paths.)

    2. TODO: document lib.mkIf

      Found a description in the NixOS manual:

      The special function mkIf causes the evaluation of the conditional to be “pushed down” into the individual definitions, as if you had written:

      config = {
        environment.systemPackages = if
      config.services.httpd.enable then [ ... ] else [];
        ...
      };
      
    3. TODO: document lib.mkDefault

      Not mentioned in any of the manuals (i.e., nix, nixpkgs, NixOS), only the NixOS options page has 1 mention:

      Some promising search result (in the order of relevance):


      From source:

        mkOverride = priority: content:
          { _type = "override";
            inherit priority content;
          };
      
        mkDefault = mkOverride 1000; # used in config sections of non-user modules to set a default
      

      It seems that all the mkOverride calls set up a priority for certain actions.

    4. 5.1.7. NixOS / nixpkgs option handling

      What is an option?

      From the link below to the source, it's just an attribute set with all the function parameters (see below) plus a _type attribute name to allow for type level operations (because Nix is untyped).

        mkOption =
          {
          # Default value used when no definition is given in the configuration.
          default ? null,
          # Textual representation of the default, for the manual.
          defaultText ? null,
          # Example value used in the manual.
          example ? null,
          # String describing the option.
          description ? null,
          # Related packages used in the manual (see `genRelatedPackages` in ../nixos/lib/make-options-doc/default.nix).
          relatedPackages ? null,
          # Option type, providing type-checking and value merging.
          type ? null,
          # Function that converts the option value to something else.
          apply ? null,
          # Whether the option is for NixOS developers only.
          internal ? null,
          # Whether the option shows up in the manual.
          visible ? null,
          # Whether the option can be set only once
          readOnly ? null,
          # Deprecated, used by types.optionSet.
          options ? null
          } @ attrs:
          attrs // { _type = "option"; };
      

      How does it fit in a big scheme of things?

      ?

    5. 5.1.2.25. lib.attrsets.recursiveUpdateUntil

      If there is recursiveUpdateUntil (i.e., mergeUntil) then mergeWith would also be welcome.

    6. 5.1.2.26. lib.attrsets.recursiveUpdaterecursiveUpdate :: AttrSet -> AttrSet -> AttrSet

      Would be nice to have an alias called merge.

    7. String -> Any -> { name = String; value = Any }

      Fix: add semicolon after last Any. (same above in the main type signature)

    8. mapAttrsToList :: (String -> Any -> Any) -> AttrSet -> Any Located at lib/attrsets.nix:233 in <nixpkgs>. Call fn for each attribute in the given set and return the result in a list.

      So the type signature

      (String -> Any -> Any) -> AttrSet -> Any
                                           ^^^
      

      should be

      
      (String -> Any -> Any) -> AttrSet -> List
                                           ^^^^
      

      instead, right?

    9. 5.1.2.11. lib.attrsets.collectcollect :: (Any -> Bool) -> AttrSet -> [Any]
    10. 5.1.2.7. lib.attrsets.catAttrscatAttrs :: String -> [AttrSet] -> [Any] Located at lib/attrsets.nix:113 in <nixpkgs>. Collect each attribute named `attr' from the list of attribute sets, sets.

      Then why not call it collectVals?... (Following the distinctive naming convention between lib.attrsets.attrVals and lib.attrsets.attrValues.)

      Especially because there is lib.attrsets.collect:

      catAttrs :: String -> [AttrSet] -> [Any]
      collect :: (Any -> Bool) -> AttrSet -> [Any]
      

      (Call it filterVals? There are filterAttrs* functions but those return an attribute set, so no collision.)

    11. Attribute-Set

      This should read "Attribute Set Functions". Nowhere else is attribute sets spelled as "attribute-set".

      edit: Alright, "attribute-set" is used in total of 4 times, whereas "attribute set" is used 112 times.

    1. baseNameOf sReturn the base name of the string s, that is, everything following the final slash in the string. This is similar to the GNU basename command.

      works both on strings and paths

    2. String Concatenation string1 + string2 leftString concatenation.
  2. Aug 2020
    1. > (square: (x: y: square x + square y) 3 7) (x: x*x)58

      This can be written up in many other forms, plus the possibility of currying deserves to be pointed out:

      $ nix repl
      nix-repl> (sq: (x: y: sq y + sq x) 2 7) (x: x*x)
      53
      
      nix-repl> (sq: (x: y: sq y + sq x)) (x: x*x)     
      «lambda @ (string):1:11»
      
      nix-repl> (sq: (x: y: sq y + sq x)) (x: x*x) 2
      «lambda @ (string):1:14»
      
      nix-repl> (sq: (x: y: sq y + sq x)) (x: x*x) 2 7
      53
      
      nix-repl> (sq: x: y: sq y + sq x) (x: x*x) 2 7   
      53
      
  3. Jul 2020
    1. The most commonly supported tool for this is kerl. Kerl is a wrapper around downloading, compiling, and loading various Erlang/OTP versions on a single system, and will abstract away most annoying operations.
  4. Jun 2020
    1. Why is Nix written in C++ rather than a functional language like Haskell?[ ] Mainly because Nix is intended to be lightweight, easy to learn and portable (zero dependencies). Since 24. April 2017 thanks to Shea Levy and the crowdfunding of 54 community members, nix does not have Perl as dependency anymore.

      There is hnix that is still actively developed (as of 2020/06/21).

    1. Basic Install environment.systemPackages = with pkgs; [ vim ]; or environment.systemPackages = with pkgs; [ vim_configurable ];

      What is the difference between the vim and vim_configurable packages?

      I believe the source for the latter is here.

    1. boot.initrd.luks.devices = [ { name = "root"; device = "/dev/nvme0n1p2"; preLVM = true; } ];

      This will still work on 20.03 but will show a warning as name = "root"; is deprecated, and luksroot should be used instead (see boot.initrd.luks.devices NixOS option) .

      boot.initd.luks.devices = {
        luksroot = {
          device = "/nev/sda2";
          preLVM = true;
        };
      };
      
  5. Apr 2020
    1. nix path-info shows information about store paths, replacing nix-store -q. A useful feature is the option --closure-size (-S). For example, the following command show the closure sizes of every path in the current NixOS system closure, sorted by size: nix path-info -rS /run/current-system | sort -nk2

      The Nixpkgs pull request template has a checkbox "Determined the impact on package closure size (by running nix path-info -S before and after)" but there is only 4 instances of path-info in the Nix manual (and none in the Nixpkgs manual).

      nix --help says

      path-info        query information about store paths
      

      so the command works at the bottom but what switches are available for example? From the examples, -r and -S is valid but where are they documented?

      nix path-info -rS $(readlink -f $(which vim))

  6. Mar 2020
  7. Feb 2020
    1. Nix is a purely functional package manager. This means that it treats packages like values in purely functional programming languages such as Haskell — they are built by functions that don’t have side-effects, and they never change after they have been built.
    2. Nix helps you make sure that package dependency specifications are complete. In general, when you’re making a package for a package management system like RPM, you have to specify for each package what its dependencies are, but there are no guarantees that this specification is complete. If you forget a dependency, then the component will build and work correctly on your machine if you have the dependency installed, but not on the end user's machine if it's not there.
    1. Never compile the same project twice Nix allows to easily share build results across machines. If the CI has built the project, developers or servers can download the build results instead of re-building the same thing.
  8. Nov 2019
    1. { packageOverrides = pkgs: rec { foo = pkgs.foo.override { ... }; }; }

      Why is rec needed here, and not in the example under 2.6.1?

      Based on what I saw with other examples, rec is usually included when a_package.override is used inside packageOverrides. But why?

    1. 3. Deployment as Memory Management

      The entire chapter 3 is worth reading. Great resource on what a package (or more broadly, a component) is in regards to Nix.

      Specifically "3.1 What is a component?"

    1. packages

      There is no officially prescribed reading order of the Nix manuals, but it's safe to say that one should start this, the Nix manual. Then it would be prudent to briefly describe what a package is in the context of Nix and/or (at east) link to the definition.

      I like how Dolstra's thesis has an entire section on the topic (that is, on the more general concept of components).

    2. You can have multiple versions or variants of a package installed at the same time.

      It is clear now that there can be multiple versions of the same package in the store, but how does one call them (e.g., if is an executable application)? Simply by using the full Nix store path (and create and manage one's own symlinks, with stow or manually)??

    1. haskell-overridez is a tool and library of nix functions that simplify the use of overrides while developing haskell projects with nixpkgs.

  9. Oct 2019
    1. fixed-point

      "fixed-point", "fix point" seems to be most important concept in Nix, because overrides, overridePackages, overlays are built using it.

    2. Overlays
    3. buildEnv
    4. stdenv.lib.licenses

      Find out where stdenv.lib functions are documented.

    5. builtins.elem

      builtins.elem x xs

      Return true if a value equal to x occurs in the list xs, and false otherwise.

    6. builtins.parseDrvName

      builtins.parseDrvName s

      Split the string s into a package name and version. The package name is everything up to but not including the first dash followed by a digit, and the version is everything following that dash. The result is returned in a set { name, version }. Thus, builtins.parseDrvName "nix-0.12pre12876" returns { name = "nix"; version = "0.12pre12876"; }.

    7. This option is a function which accepts a package as a parameter, and returns a boolean. The following example configuration accepts a package and always returns false: { allowUnfreePredicate = (pkg: false); }

      What is a package in this context? That is, the callback's pkg parameter. Is it a derivation?

      If I understood it correctly, whenever referencing other packages as inputs, those are actually derivations, that are just attribute sets.

  10. Jul 2019
  11. Jun 2019
  12. Dec 2018
  13. Nov 2018
  14. Oct 2018
  15. Sep 2018
  16. Jul 2018
  17. Jun 2018
  18. Dec 2017