Comments (7)
Would be good if I could just do
perSystem = { system, ... }: { foo = ... }
and getflake.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.
Makes sense, thanks!
from flake-parts.
@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.
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.
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>.#<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>.#<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>.#<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.
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.
from flake-parts.
Related Issues (20)
- Provide a way to easily run doc tests HOT 1
- Explicitly pass default nixpkgs to mkFlake
- Document, how to declare packages only for concrete system
- perSystem.packages cannot be used with recursive packages HOT 1
- NixOS options not 1:1 available HOT 2
- nixosConfigurations example does not invoke nixosConfigurations HOT 2
- infinite recursion when `self` assigned to option HOT 6
- Add `templates` to `flake` HOT 2
- Infinite recursion error when unknown option is set HOT 3
- nix flake show broken HOT 2
- Set `_file` and `_class` for modules defined under `flake.modules.${className}.${moduleName}` HOT 1
- How to define a custom flake attribute for a reusable module HOT 2
- Attribute set is expected to be unique HOT 2
- Generate nixosConfigurations HOT 1
- Per system option with a different name? HOT 4
- Flakestry releases HOT 2
- Q: How to correctly implement a home-manager? HOT 1
- Do we really need nixpkgs in inputs instead of the lightweight nix-community/nixpkgs.lib? HOT 2
- `flake-parts` doesn't evaluate. HOT 3
- Declaring per-system functions as flake outputs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flake-parts.