Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass 'self' to lib #169

Closed
Pacman99 opened this issue Mar 15, 2021 · 7 comments · Fixed by #164
Closed

Pass 'self' to lib #169

Pacman99 opened this issue Mar 15, 2021 · 7 comments · Fixed by #164
Labels
enhancement New feature or request

Comments

@Pacman99
Copy link
Member

For os.mkPkgs and os.mkPackages, self is passed to them as a function argument. But why not just pass self to lib/default.nix and make it available for all lib functions?
So you can just call os.mkPkgs without any arguments. And os.mkPackages can just be passed pkgs.

@Pacman99 Pacman99 added the enhancement New feature or request label Mar 15, 2021
@blaggacao
Copy link
Contributor

blaggacao commented Mar 15, 2021

I would be somehow in favor of this. (resolve there, so we can discuss here)

@Pacman99
Copy link
Member Author

Yup your PR was what gave me the idea, and I think it would simplify some other lib functions as well.

@Pacman99
Copy link
Member Author

Tested it with this patch

diff --git a/flake.nix b/flake.nix index ad39936..b1720b5 100644 --- a/flake.nix +++ b/flake.nix @@ -36,7 +36,7 @@
   extern = import ./extern { inherit inputs; };
  •  pkgs' = os.mkPkgs { inherit self; };
    
  •  pkgs' = os.mkPkgs;
    
     outputs =
       let
    

@@ -57,7 +57,7 @@
overlay = import ./pkgs;
overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays);

  •      lib = import ./lib { inherit nixos pkgs; };
    
  •      lib = import ./lib { inherit nixos self pkgs; };
    
         templates.flk.path = ./.;
         templates.flk.description = "flk template";
    

diff --git a/lib/default.nix b/lib/default.nix
index cda082e..7f422f9 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -1,4 +1,4 @@
-args@{ nixos, pkgs, ... }:
+args@{ nixos, pkgs, self, ... }:
let inherit (nixos) lib; in
lib.makeExtensible (self:
let callLibs = file: import file
diff --git a/lib/devos/mkPkgs.nix b/lib/devos/mkPkgs.nix
index f9e53e7..9b76e6d 100644
--- a/lib/devos/mkPkgs.nix
+++ b/lib/devos/mkPkgs.nix
@@ -1,6 +1,5 @@
-{ lib, dev, nixos, ... }:
+{ lib, dev, nixos, self, ... }:

-{ self }:
let inherit (self) inputs;
in
(inputs.utils.lib.eachDefaultSystem

And the configurations evaluated okay.

@nrdxp
Copy link
Collaborator

nrdxp commented Mar 15, 2021

I've thought about this as well. Was also wondering if passing self as a specialArg would be useful in general. If we do this, we should probably do that as well. Although, for clarity we should probably rename it on passing, something like:
{ devos = self; }

@Pacman99
Copy link
Member Author

Thats a good idea. If you do that I'll drop the multiPkgs module argument. Since you could just use self.packages.system instead.

And actually it could obsolete the hosts module arg since other configs could be accessed with self.nixosConfigurations. But I'm not sure since hosts is still easier to access and could prevent possible infinite recursion errors.

@nrdxp
Copy link
Collaborator

nrdxp commented Mar 15, 2021

We'll probably want to levarage the new test infrastructure to ensure there is no infinite recursion.

blaggacao pushed a commit to blaggacao/devos that referenced this issue Mar 16, 2021
It is generally useful to acess the top level flake from
library functions or hosts. This not only simplifies
the mental model and code but also provides additional
context and not least a handle to the repo source code
in the nix store.

closes divnix#169
blaggacao pushed a commit to blaggacao/devos that referenced this issue Mar 16, 2021
It is generally useful to acess the top level flake from
library functions or hosts. This not only simplifies
the mental model and code but also provides additional
context and not least a handle to the repo source code
in the nix store.

closes divnix#169
blaggacao pushed a commit to blaggacao/devos that referenced this issue Mar 16, 2021
It is generally useful to acess the top level flake from
library functions or hosts. This not only simplifies
the mental model and code but also provides additional
context and not least a handle to the repo source code
in the nix store.

closes divnix#169
blaggacao pushed a commit to blaggacao/devos that referenced this issue Mar 16, 2021
It is generally useful to acess the top level flake from
library functions or hosts. This not only simplifies
the mental model and code but also provides additional
context and not least a handle to the repo source code
in the nix store.

closes divnix#169
@Pacman99
Copy link
Member Author

closed by #168

bors bot added a commit that referenced this issue Mar 16, 2021
164: add hosts module arg r=nrdxp a=Pacman99

should help with #163. Fixes #169
But either way this could be generally useful. I have one use case of setting up a minecraft bungeecord proxy with servers on different hosts. 

Co-authored-by: Pacman99 <pachum99@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants