• 8 Posts
  • 14 Comments
Joined 1 year ago
cake
Cake day: June 23rd, 2023

help-circle








  • Not sure what the issue is, but I hope this helps:

    • Stuff added to home.sessionPath ends up in $HOME/.nix-profile/etc/profile.d/hm-session-vars.sh, which (in my system, at least) is referenced from ~/.profile.
    • ~/.profile is only executed by login shells (ie. you have to logout and back in for it to be re-evaluated, or of course you can just source it)
    • bash ignores ~/.profile if there is a ~/.bash_profile or ~/.bash_login (IIRC)



  • Submodules are for defining the type, so the only thing you get is interface (options), not implementation.

    You do get a functional config in submodules… try this (it doesn’t do anything so you can just import into any configuration.nix):

    { config, lib, pkgs, modulesPath, specialArgs, options, ... }: {
    
      options.mynamespace = lib.mkOption {
        type = lib.types.attrsOf (lib.types.submodule ({name, config, ...}:{
          options = {
            option1 = lib.mkOption { type = lib.types.str; default = ""; };
            option2 = lib.mkOption { type = lib.types.str; default = ""; };
          };
          config = {
            option2 = "derived from value of option1: '${config.option1}'";
          };
        }));
      };
    
      config = {
    
        mynamespace.submodule1.option1 = "value of option1";
    
        fileSystems = builtins.trace (builtins.toJSON config.mynamespace) {};
    
      };
    
    }
    

  • Your module only defines the option inside types.submodule - I’d (ideally, to better organize the code) want to also put the config section in the submodule.

    Ie. your code is structured similar to:

    options = {
        fileSystems = mkOption {
        type = types.attrsOf (types.submodule {
            options = {
              # bla bla
            };           
        };
        };
    };
    
    config = {
      # set options here
    };
    

    while what I would like to do is more like

    options = {
      fileSystems = mkOption {
        type = types.attrsOf (types.submodule {
          options = {
            # bla bla
          };
          config = {
            # set options here
          };
      };
    };
    

    The reason why I’m trying to do so is purely to restructure my code (which right now does has the config logic at the module, rather than submodule, level) in order to make it more readable/manageable, since it currently has jems like:

    config.services.restic.backups = builtins.listToAttrs (
      builtins.concatLists (lib.attrsets.mapAttrsToList (v-name: v-cfg: (
        builtins.concatLists (lib.attrsets.mapAttrsToList (s-name: s-cfg: (
          builtins.concatLists (lib.attrsets.mapAttrsToList (r-name: r-cfg: (
    

    I know I can restructure the code in other ways (eg. let .. in) - I just wanted to put the options definitions together with the code that uses them.





  • That was my first idea (well, I say “my”… but it was really suggested by yourself in the question I posted the other day), but it results in nixos complaining that error: A definition for option 'environment.systemPackages."[definition 1-entry 1]"' is not of type 'package'.

    It might very well be that I’m doing some stupid mistake here (or maybe it’s something that used to work and doesn’t anymore?)… here’s what I used to test it out:

      environment.systemPackages = [
        pkgs.writeShellApplication {
          name = "some-script";
          text = "echo hello wolrd";
        }
      ];
    

    Edit:

    And indeed I was the one doing stupid things: it must be

      environment.systemPackages = [
        (pkgs.writeShellApplication {
          name = "some-script";
          text = "echo hello wolrd";
        })
      ];
    

    with the parentheses, or it’s a list with two elements (a function and an attrset)…