Your one-stop-cake-shop for everything Freshly Baked has to offer

refactor!(*): use attributes that match projects #179

merged opened by a.starrysky.fyi targeting main from private/minion/push-smklqylmuplo

Previously we effectively had some projects smooshed together. This normally worked fine but for any repeated attributes (e.g. default) both copies would break.

Instead, we now have a new naming scheme:

Projects are given a "name" attribute in their config

# foo/project.nix:
{
  config.name = "foo";
}

Any packages, shells, systems or homes defined in that project start with that name followed by a dash

# foo/packages.nix:
{
  config.packages.foo-package = {
    ...
  };
  config.packages.foo-package2 = {
    ...
  };
}

# bar/packages.nix
{
  config.packages.bar-package3 = {
    ...
  };
}

Because of the naming convention, you'll still be able to refer to the package even if another one is named the same

# baz/packages.nix
{
  config.packages.baz-package2 = {
    ...
  };
}

For the default package, the project name alone should be used for the attribute

# foo/packages.nix:
{
  config.packages.foo = {
    ...
  };
}

To refer to a package elsewhere in the project, you must use the fully qualified name

# foo/packageReference.nix:
{ config, ... }: {
  config.something = [
    config.packages.foo-package
    config.packages.baz-package2
    config.packages.foo
    config.packages.package # fails - "package" does not exist
    config.packages.default # fails - "default" does not exist
  ];
}

When using patisserie on the command line or from another project, however, there are aliases for your convenience...

patisserie$ nilla build foo-package # works
patisserie$ nilla build package # also works

...but only if the package is unique

patisserie$ nilla build package2 # fails because there ore two packages called package2 (foo-package2 and baz-package2)
patisserie$ nilla build foo-package2 # still works
pasisserie$ nilla build baz-package2 # also still works

When using Josh to clone down part of the monorepo, only the current project will be aliased, even if other pieces are included as dependencies...

foo$ ls dependencies/
  bar baz
foo$ nilla build foo-package # works
foo$ nilla build package # works
foo$ nilla build package2 # works - referring to foo-package2
foo$ nilla build bar-package2 # works - you can still use the full name of a package
foo$ nilla build package3 # fails - even though bar-package3 doesn't conflict, it isn't aliased in the foo project

...you may also use the default attribute to refer to the package with the name of the cloned project...

foo$ nilla build foo # works
foo$ nilla build default # works
foo$ nilla build # works - since as nilla by default uses "default" if you don't specify an attribute
Labels

None yet.

requested-reviewers

None yet.

tested-working

None yet.

rejected

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:uuyqs6y3pwtbteet4swt5i5y/sh.tangled.repo.pull/3md43bs53df22
+25 -4
Interdiff #0 #1
.tangled/workflows/packetmix-treefmt.yaml

This file has not been changed.

ci.nix

This file has not been changed.

menu/project.nix

This file has not been changed.

nilla.nix

This file has not been changed.

packetmix/homes/coded/games.nix

This file has not been changed.

packetmix/homes/collabora/gtimelog.nix

This file has not been changed.

packetmix/homes/common/helix.nix

This file has not been changed.

packetmix/homes/default.nix

This file has not been changed.

packetmix/homes/minion/misc.nix

This file has not been changed.

packetmix/homes/scriptfs/scriptfs.nix

This file has not been changed.

packetmix/modules/ingredients.nix

This file has not been changed.

packetmix/packages/OpenLinkHub/default.nix

This file has not been changed.

packetmix/packages/beancount-autobean/default.nix

This file has not been changed.

packetmix/packages/beancount-beancount_plugin_utils/default.nix

This file has not been changed.

packetmix/packages/beancount-beancount_share/default.nix

This file has not been changed.

packetmix/packages/beancount-smart_importer/default.nix

This file has not been changed.

packetmix/packages/bluesky-pds/default.nix

This file has not been changed.

packetmix/packages/collabora-gtimelog/default.nix

This file has not been changed.

packetmix/packages/headscale/default.nix

This file has not been changed.

packetmix/packages/josh/default.nix

This file has not been changed.

packetmix/packages/kavita/default.nix

This file has not been changed.

packetmix/packages/lua-multipart/default.nix

This file has not been changed.

packetmix/packages/opensearch/default.nix

This file has not been changed.

packetmix/packages/scriptfs/default.nix

This file has not been changed.

packetmix/packages/treefmt/default.nix

This file has not been changed.

packetmix/packages/vs-launcher/default.nix

This file has not been changed.

packetmix/project.nix

This file has not been changed.

packetmix/systems/corsair/openlinkhub.nix

This file has not been changed.

packetmix/systems/default.nix

This file has not been changed.

packetmix/systems/teal/copyparty.nix

This file has not been changed.

packetmix/systems/teal/fava.nix

This file has not been changed.

packetmix/systems/teal/headscale.nix

This file has not been changed.

packetmix/systems/teal/josh.nix

This file has not been changed.

packetmix/systems/teal/kavita.nix

This file has not been changed.

packetmix/systems/teal/pds.nix

This file has not been changed.

packetmix/systems/wiki/wiki.nix

This file has not been changed.

projects/menu/workspace.josh

This file has not been changed.

+25 -4
projects/nilla.nix
··· 18 nixos-unstable = (settings config).nixpkgs; 19 }; 20 21 - name = (import ./project.nix null null).config.name; 22 23 result = (nilla.create [ ]).extend { 24 modules = [ 25 ./project.nix ··· 79 aliased = 80 config: old: 81 old 82 - // { 83 - default = old.${name}; 84 - } 85 // selectPrefixedAttrs config.lib "${name}-" old; 86 in 87 {
··· 18 nixos-unstable = (settings config).nixpkgs; 19 }; 20 21 + name = 22 + let 23 + lib = result.config.lib; 24 25 + imported = import ./project.nix; 26 + 27 + args = builtins.functionArgs imported; 28 + argNames = builtins.attrNames args; 29 + nonDefaultArgNames = builtins.filter (name: !args.${name}) argNames; 30 + 31 + nullArgs = lib.attrs.generate nonDefaultArgNames (_: null); 32 + 33 + calledProject = imported nullArgs; 34 + 35 + project = if builtins.isFunction imported then calledProject else imported; 36 + in 37 + project.config.name; 38 + 39 result = (nilla.create [ ]).extend { 40 modules = [ 41 ./project.nix ··· 95 aliased = 96 config: old: 97 old 98 + // ( 99 + if (builtins.hasAttr name old) then 100 + { 101 + default = old.${name}; 102 + } 103 + else 104 + { } 105 + ) 106 // selectPrefixedAttrs config.lib "${name}-" old; 107 in 108 {
sprinkles/project.nix

This file has not been changed.

History

4 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
refactor!(*): use attributes that match projects
expand 0 comments
pull request successfully merged
1 commit
expand
refactor!(*): use attributes that match projects
expand 0 comments
1 commit
expand
refactor!(*): use attributes that match projects
expand 0 comments
1 commit
expand
refactor!(*): use attributes that match projects
expand 0 comments