Skip to content

[WIP] Separate NixOS lib and nixpkgs lib #19153

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

Closed
wants to merge 1 commit into from

Conversation

ericsagnes
Copy link
Contributor

@ericsagnes ericsagnes commented Oct 2, 2016

Motivation for this change

This was motivated by this comment.

The ultimate goal of this PR is to be able to include NixOS lib functions in an easy manner for custom projects, eg with import <nixpkgs/nixos>; lib.....
An other objective is to have a clearer separation between nixos and nixpkgs functions.

Until now, only nixpkgs had a lib, and NixOS related functions were part of this lib, directly called via imports (eval-config) or directly defined in files (test related functions).

For a better separation and cleaner namespaces, this PR create a new lib to nixos, that can be called with with import <nixpkgs/nixos/lib>; ... or with import <nixpkgs/nixos>; lib.... and move the functions that has nothing to do with nixpkgs in the nixos library.

This is a work in progress, and this aims to be as much backward compatible as possible.

nixpkgs lib side

options, types, modules have moved to nixos lib, but each file (lib/options.nix, ...) is still present to not break any direct imports (eg, import <nixpkgs/lib/options.nix>) that users might have in their setups.

The nixos lib, can be accessed via the lib.nixos namespace. So if options functions must be used in nixpkgs context, they can be accessed with lib.nixos.options.
Note that there is no trace of usage of options, types and modules in the nixpkgs only source, so the new namespace should not break things.

nixos lib side

A lib top level attribute was added to ./nixos that can be used with "with import <nixpkgs/nixos>; lib..." or "with import <nixpkgs/nixos/lib>;".
This lib includes previous nixpkgs lib options, types and modules.
The nixpkgs lib is in the namespace lib.nixpkgs AND at top-level.

This is the lib that is used in the module system, so having nixpkgs lib at top level is required to not break modules code that expect nixpkgs lib functions to be accessible from lib.


This is in early state and will require more extensive testing to be sure nothing break it is much backward compatible as possible before being mergeable.

In current state, this can build the manual and a simple config via VM.

Feedback is welcomed.


cc @edolstra

@mention-bot
Copy link

@ericsagnes, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @nbp and @shlevy to be potential reviewers.

@ericsagnes ericsagnes changed the title [WIP] Seperate NixOS lib and nixpkgs lib [WIP] Separate NixOS lib and nixpkgs lib Oct 2, 2016
@vcunat vcunat added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Oct 2, 2016
@ericsagnes
Copy link
Contributor Author

Any opinions on this?

@NeQuissimus NeQuissimus added 0.kind: enhancement Add something new 9.needs: reporter feedback This issue needs the person who filed it to respond 2.status: work-in-progress This PR isn't done labels Oct 10, 2016
@vcunat
Copy link
Member

vcunat commented Oct 16, 2016

The idea at least seems good to me, but I haven't done much nixos/* stuff, so better if someone else looks at it as well.

@nbp
Copy link
Member

nbp commented Nov 6, 2016

I think this change would have made sense when nixpkgs and NixOS were in separated repository.
I honestly do not recall why I chose nixpkgs lib over adding a new one to NixOS back then, probably because we were already heavily using nixpkgs/lib.

@ericsagnes
Copy link
Contributor Author

I think this change would have made sense when nixpkgs and NixOS were in separated repository.

As it was only linked in the description and easy to miss, bellow is the quote from @edolstra comment that motivated this PR:

I don't think we should move the NixOS testing stuff to the non-NixOS part of Nixpkgs. They're NixOS-specific after all.

I do agree with that, but I think that it could be useful to have some NixOS specific functions easily available from external projects, like testing related functions.

Making a NixOS specific library that could be imported with import <nixpkgs/nixos> {}; lib.callTest felt like a good solution for this.
In this process, it made sense to also move NixOS specific parts of the nixpkgs lib to that library.

I hope this can help to clarify the motivation.

@aneeshusa
Copy link
Contributor

I've found the module system nice to be able to use outside of NixOS, for example in defining a user environment (see https://github.com/rycee/home-manager for instance), so I'd like to see it continue to be available from the main Nixpkgs lib. I don't see it as being NixOS specific.

@ericsagnes
Copy link
Contributor Author

I have totally forgot about this one.

I agree that it is easy to use nix lib from outside of nixpkgs, and I do that in a few of my personal projects.
The main goal of this PR was to have a cleaner organization of libs with a new lib.nixos namespace.
And also to have a cleaner lib available in nixos modules to avoid #19899 like problems.

Anyway, closing as this has been open for too long.
Will reopen if someone is interested by this.

@ericsagnes ericsagnes closed this May 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: enhancement Add something new 2.status: work-in-progress This PR isn't done 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 9.needs: community feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants