Skip to content

Commit

Permalink
docs(loaders): add pacakges
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Nov 20, 2023
1 parent 9d305bb commit 1a4101a
Show file tree
Hide file tree
Showing 14 changed files with 264 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docs/org/homeProfiles.org
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:PROPERTIES:
:header-args: :noweb tangle :comments noweb :exports both
:PRJ-DIR: ../../nixos/homeProfiles
:PRJ-DIR: ../../units/nixos/homeProfiles
:ID: 6bb7d46d-7358-4110-a848-f68fffda5b4d
:END:
#+TITLE: homeProfiles
Expand Down
108 changes: 108 additions & 0 deletions docs/org/loaders.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
:PROPERTIES:
:ID: da553274-7bc3-4ce0-a314-89a0bfb87a4a
:header-args: :noweb tangle :comments noweb :exports both
:PRJ-DIR: ../..
:EXP-DIR: ../../examples
:END:
#+TITLE: loaders
#+AUTHOR: GuangTao Zhang
#+EMAIL: gtrunsec@hardenedlinux.org
#+DATE: 2023-11-19 Sun 15:16


#+begin_quote
Please note that in Pops, the outputs/results should not be directly printed, but instead, they wll be exported through the exports property under the pop object.
#+end_quote


* packages
:PROPERTIES:
:CODE-DIR: ../../src/pops
:END:

- function: ~omnibus.pops.pacakges~

that function is responsible for loading packages in a tree structure and nixpkgs.callPackage <>automatically.

#+begin_src nix :tangle (concat (org-entry-get (point) "CODE-DIR" t) "/packages.nix")
{ super, root }:
load:
let
inherit
(root.errors.requiredInputs load.inputs "omnibus.pops.packages" [ "nixpkgs" ])
nixpkgs
;
inherit (nixpkgs) newScope;
inherit (nixpkgs.lib) makeScope;
in
makeScope newScope (
selfScope:
((super.load load).addLoadExtender {
load = {
loader =
__inputs__: path:
(selfScope.overrideScope (_: _: { inherit __inputs__; })).callPackage path { };
transformer = [ (_cursor: dir: if dir ? default then dir.default else dir) ];
};
}).addExporters
[
(POP.extendPop flops.haumea.pops.exporter (
self: _super: {
exports = {
overlay =
final: prev:
(self.layouts.self.addLoadExtender {
load = {
inputs.inputs.nixpkgs = final;
loader =
__inputs__: path:
(__inputs__.inputs.nixpkgs.extend (_: _: { inherit __inputs__; })).callPackage
path
{ };
};
}).exports.default;
};
}
))
]
)
#+end_src

- *pops.packages* have an arg named by anti-namespace of *__inputs__* in the scopePackages, that *__inptus__* can pass all args same as haumea.inputs, such as {super,self, ...} => {__inputs__.self, __inputs__.super, inputs.{...} }


** Example

#+begin_src nix :tangle (concat (org-entry-get nil "EXP-DIR" t) "/packages/default.nix")
{
omnibus,
inputs,
self,
}:
omnibus.pops.packages {
src = ./__fixture;
inputs = {
nixpkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
};
}
# => out.exports { default = {...}, packages = {...}; }
#+end_src


+ exports

#+begin_src nix
nix-repl> :p Flake.examples.packages.exports.default
{ hello1 = «derivation /nix/store/kc6j6vssi60h1yn3kafc7v8ywn1j35lp-example-unfree-package-2.0.drv»; hello2 = «derivation /
nix/store/v0qa0lw6jhzcwj68zz939kn8ixmiabnb-example-unfree-package-3.0.drv»; }
#+end_src

- default (packageSet)
- overlay
#+begin_src nix :tangle (concat (org-entry-get nil "EXP-DIR" t) "/packagesOverlay.nix")
{ super, omnibus }:
let
nixos-23_05 = omnibus.flake.inputs.nixos-23_05;
in
nixos-23_05.legacyPackages.x86_64-linux.extend super.packages.exports.overlay
#+end_src
108 changes: 108 additions & 0 deletions docs/org/pops-packages.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
:PROPERTIES:
:ID: f7adb0ad-2cc1-4723-a796-bf608682456a
:header-args: :noweb tangle :comments noweb :exports both
:PRJ-DIR: ../..
:EXP-DIR: ../../examples
:CODE-DIR: ../../src/pops
:END:
#+TITLE: pops-packages
#+AUTHOR: GuangTao Zhang
#+EMAIL: gtrunsec@hardenedlinux.org
#+DATE: 2023-11-19 Sun 16:25


function: ~omnibus.pops.pacakges~ is responsible for loading packages in a tree structure then nixpkgs.callPackage with *path* automatically.

- code

#+begin_src nix :tangle (concat (org-entry-get nil "CODE-DIR" t) "/packages.nix")
{ super, root }:
load:
let
inherit
(root.errors.requiredInputs load.inputs "omnibus.pops.packages" [ "nixpkgs" ])
nixpkgs
;
inherit (nixpkgs) newScope;
inherit (nixpkgs.lib) makeScope;
in
makeScope newScope (
selfScope:
((super.load load).addLoadExtender {
load = {
loader =
__inputs__: path:
(selfScope.overrideScope (_: _: { inherit __inputs__; })).callPackage path { };
transformer = [ (_cursor: dir: if dir ? default then dir.default else dir) ];
};
}).addExporters
[
(POP.extendPop flops.haumea.pops.exporter (
self: _super: {
exports = {
overlay =
final: prev:
(self.layouts.self.addLoadExtender {
load = {
inputs.inputs.nixpkgs = final;
loader =
__inputs__: path:
(__inputs__.inputs.nixpkgs.extend (_: _: { inherit __inputs__; })).callPackage
path
{ };
};
}).exports.default;
};
}
))
]
)
#+end_src

- *pops.packages* have an arg named by anti-namespace of *__inputs__* in the scopePackages, that *__inptus__* can pass all args same as haumea.inputs, such as {super,self, ...} => {__inputs__.self, __inputs__.super, inputs.{...} }


** Example

#+begin_src nix :tangle (concat (org-entry-get nil "EXP-DIR" t) "/packages/default.nix")
{
omnibus,
inputs,
self,
}:
omnibus.pops.packages {
src = ./__fixture;
inputs = {
nixpkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
};
}
# => out.exports { default = {...}, packages = {...}; }
#+end_src


#+begin_quote
Please note that in Pops, the outputs/results should not be directly printed, but instead, they wll be exported through the exports property under the pop object.
#+end_quote


+ exports

#+begin_src nix

# => default (packageSet)
nix-repl> :p Flake.examples.packages.exports.default
{ hello1 = «derivation /nix/store/kc6j6vssi60h1yn3kafc7v8ywn1j35lp-example-unfree-package-2.0.drv»; hello2 = «derivation /
nix/store/v0qa0lw6jhzcwj68zz939kn8ixmiabnb-example-unfree-package-3.0.drv»; }
# => overlay
nix-repl> :p Flake.examples.packages.exports.overlay
«lambda @ /home/guangtao/Dropbox/omnibus/src/pops/packages.nix:27:15»
#+end_src

- aplly the overlay with nixpkgs
#+begin_src nix :tangle (concat (org-entry-get nil "EXP-DIR" t) "/packagesOverlay.nix")
{ super, omnibus }:
let
nixos-23_05 = omnibus.flake.inputs.nixos-23_05;
in
nixos-23_05.legacyPackages.x86_64-linux.extend super.packages.exports.overlay
#+end_src
18 changes: 18 additions & 0 deletions docs/org/pops.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
:PROPERTIES:
:ID: da553274-7bc3-4ce0-a314-89a0bfb87a4a
:header-args: :noweb tangle :comments noweb :exports both
:PRJ-DIR: ../..
:EXP-DIR: ../../examples
:END:
#+TITLE: pops
#+AUTHOR: GuangTao Zhang
#+EMAIL: gtrunsec@hardenedlinux.org
#+DATE: 2023-11-19 Sun 15:16

#+begin_quote
Please note that in Pops, the outputs/results should not be directly printed, but instead, they wll be exported through the exports property under the pop object.
#+end_quote

* Loaders

- [[id:f7adb0ad-2cc1-4723-a796-bf608682456a][pops-packages]] (loading the packages into nixpkgs from a directory)
3 changes: 3 additions & 0 deletions examples/packages/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# [[file:../../docs/org/pops-packages.org::*Example][Example:1]]
{
omnibus,
inputs,
Expand All @@ -9,3 +10,5 @@ omnibus.pops.packages {
nixpkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
};
}
# => out.exports { default = {...}, packages = {...}; }
# Example:1 ends here
2 changes: 2 additions & 0 deletions examples/packagesOverlay.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# [[file:../docs/org/pops-packages.org::*Example][Example:3]]
{ super, omnibus }:
let
nixos-23_05 = omnibus.flake.inputs.nixos-23_05;
in
nixos-23_05.legacyPackages.x86_64-linux.extend super.packages.exports.overlay
# Example:3 ends here
6 changes: 3 additions & 3 deletions local/lock/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions src/pops/packages.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# [[id:f7adb0ad-2cc1-4723-a796-bf608682456a][No heading:1]]
{ super, root }:
load:
let
Expand All @@ -9,15 +10,15 @@ let
inherit (nixpkgs.lib) makeScope;
in
makeScope newScope (
selfScope
((super.load load).addLoadExtender {
load = {
loader =
__inputs__: path:
(selfScope.overrideScope (_: _: { inherit __inputs__; })).callPackage path { };
transformer = [ (_cursor: dir: if dir ? default then dir.default else dir) ];
};
}).addExporters
selfScope:
((super.load load).addLoadExtender {
load = {
loader =
__inputs__: path:
(selfScope.overrideScope (_: _: { inherit __inputs__; })).callPackage path { };
transformer = [ (_cursor: dir: if dir ? default then dir.default else dir) ];
};
}).addExporters
[
(POP.extendPop flops.haumea.pops.exporter (
self: _super: {
Expand All @@ -39,3 +40,4 @@ makeScope newScope (
))
]
)
# No heading:1 ends here
1 change: 1 addition & 0 deletions units/configs/treefmt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ in
nix = {
includes = [ "*.nix" ];
command = "nixfmt";
options = [ "--width=80" ];
excludes = [ ];
};
prettier = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ in
# Create .sqlite database from chinook database.
sqlite-init.command = ''
echo "$(date): Importing Chinook database (${dataFile}) ..."
${
lib.getExe pkgs.sqlite
} "${dataFile}" < ${chinookDb}/ChinookDatabase/DataSources/Chinook_Sqlite.sql
${lib.getExe pkgs.sqlite} "${dataFile}" < ${chinookDb}/ChinookDatabase/DataSources/Chinook_Sqlite.sql
echo "$(date): Done."
'';

Expand Down
10 changes: 4 additions & 6 deletions units/nixos/homeProfiles/presets/spell-check.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ let
);
in
{
home.file.".config/enchant/enenchant.ordering".source =
pkgs.writeText "enenchant.ordering"
''
*:${ordering}
en_US:${ordering}
'';
home.file.".config/enchant/enenchant.ordering".source = pkgs.writeText "enenchant.ordering" ''
*:${ordering}
en_US:${ordering}
'';
home.packages = with pkgs; [
(hunspellWithDicts [ hunspellDicts.en-us ])
(aspellWithDicts (
Expand Down
2 changes: 1 addition & 1 deletion units/nixos/homeProfiles/shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [[file:../../../docs/org/homeProfiles.org::*shell][shell:1]]
# [[id:cbe34da3-ffbb-423c-aee4-d0cd71af51e4][shell:1]]
{
root,
self,
Expand Down
4 changes: 1 addition & 3 deletions units/nixos/nixosModules/omnibus/bootstrap/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ in
if [ -z "$1" ]; then
nix repl --argstr host "$HOST" --argstr flakePath "$PRJ_ROOT" ${./nrepl.nix}
else
nix repl --argstr host "$HOST" --argstr flakePath $(readlink -f $1 | sed 's|/flake.nix||') ${
./nrepl.nix
}
nix repl --argstr host "$HOST" --argstr flakePath $(readlink -f $1 | sed 's|/flake.nix||') ${./nrepl.nix}
fi
'')
ripgrep
Expand Down
8 changes: 2 additions & 6 deletions units/nixos/nixosModules/omnibus/coding/python.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
options = with lib; {
enableLspBridge =
mkEnableOption
"Enable the language server protocol bridge support";
enableEmacsEaf =
mkEnableOption
"Enable the Emacs Application Framework support";
enableLspBridge = mkEnableOption "Enable the language server protocol bridge support";
enableEmacsEaf = mkEnableOption "Enable the Emacs Application Framework support";
python = mkOption {
type = types.package;
default = pkgs.python3;
Expand Down

0 comments on commit 1a4101a

Please sign in to comment.