GithubHelp home page GithubHelp logo

Comments (7)

roberth avatar roberth commented on June 2, 2024

Would be good if I could just do perSystem = { system, ... }: { foo = ... } and get flake.foo.x86_64-linux.

This would require the definition of flake to scan each config of allSystems, which is too strict.
Also many options in perSystem are not meant to be public, so for these reasons, it can't be quite as simple as that.

With #63 the following should do the trick:

{
  transposition.foo.adHoc = true;
  perSystem = { ... }: {
    foo = ...;
  };
}

I'm not adding that example to the readme though, because I want to encourage users to write proper options; not to copy this kind of bad example.

from flake-parts.

shlevy avatar shlevy commented on June 2, 2024

Makes sense, thanks!

from flake-parts.

shlevy avatar shlevy commented on June 2, 2024

@roberth Do you think it might be possible to at least lower the boilerplate to add a new proper option? Some simple way to say "I want to simultaneously define a perSystem option, and map it to a new flake attribute set option keyed on system and sharing a common description"?

from flake-parts.

roberth avatar roberth commented on June 2, 2024

Something in the style of mkRenamedOptionModule would be possible, but I didn't write it because

  • Transposition is the problem and it should be removed from the next version of flakes
  • We shouldn't be adding many ad hoc attributes
  • The indirection will make the code a bit harder to understand
  • The description isn't actually common, because of the transposition.

I've made it about as easy as possible to make a really ad hoc declaration; just two lines. Apparently your use case is not as ad hoc. What is your actual use case?

from flake-parts.

shlevy avatar shlevy commented on June 2, 2024

Ah, sorry, this was meant to be a question about what to do when it's not ad hoc. E.g. if I look at apps.nix, it seems like I should be able to just write something like

{
  options.perSystemFlakeOptions.apps = mkPerSystemFlakeOption
      ({ config, system, ... }: mkOption {
          type = types.lazyAttrsOf appType;
          default = { };
          description = ''
            Programs runnable with nix run <literal>.#&lt;name></literal>.
          '';
          example = lib.literalExpression or lib.literalExample ''
            {
              default.program = "''${config.packages.hello}/bin/hello";
            }
          '';
        }
      );
}

in place of

{
  options = {
    flake = mkSubmoduleOptions {
      apps = mkOption {
        type = types.lazyAttrsOf (types.lazyAttrsOf appType);
        default = { };
        description = ''
          Programs runnable with nix run <literal>.#&lt;name></literal>.
        '';
        example = lib.literalExpression or lib.literalExample ''
          {
            x86_64-linux.default.program = "''${config.packages.hello}/bin/hello";
          }
        '';
      };
    };

    perSystem = mkPerSystemOption
      ({ config, system, ... }: {
        options = {
          apps = mkOption {
            type = types.lazyAttrsOf appType;
            default = { };
            description = ''
              Programs runnable with nix run <literal>.#&lt;name></literal>.
            '';
            example = lib.literalExpression or lib.literalExample ''
              {
                default.program = "''${config.packages.hello}/bin/hello";
              }
            '';
          };
        };
      });

  };
  config = {
    flake.apps =
      mapAttrs
        (k: v: v.apps or { })
        config.allSystems;

    perInput = system: flake:
      optionalAttrs (flake?apps.${system}) {
        apps = flake.apps.${system};
      };

  };
}

and still get all the same results.

from flake-parts.

roberth avatar roberth commented on June 2, 2024

Ah ok 👍

I'm a bit cautious about making option declarations dynamic, even though adHoc = true shows that it's possible in at least some cases. I think one problem may be the docs generation. Only "static" modules show up in the docs. Once you declare submodule options via a module added in config, they won't be picked up.

So I really think it'd have to be

Something in the style of mkRenamedOptionModule

or, basically, turn the whole apps.nix (or packages.nix or ...) module into a function and parameterize it to abstract all the specifics.

  config = {
    flake.apps =
[...]

Nitpicking, but this part has been replaced by config.transposition.apps = { };

from flake-parts.

shlevy avatar shlevy commented on June 2, 2024

@roberth Created #64 for this

from flake-parts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.