Skip to content

Commit

Permalink
feat: WIP add nixos example
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Oct 4, 2023
1 parent de3129c commit f35be63
Show file tree
Hide file tree
Showing 17 changed files with 257 additions and 72 deletions.
2 changes: 1 addition & 1 deletion examples/nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ in

outputs.srvos.default.common.nix

(omnibus.lib.outputs.default.mkHome
(omnibus.lib.mkHome
{
admin = {
uid = 1000;
Expand Down
7 changes: 6 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
...
}@inputs:
let
omnibus = self.lib // {
lib = self.lib.lib;
};
lib = flops.lib.haumea.pops.default.setInit {
src = ./lib;
loader = haumea.lib.loaders.scoped;
inputs = {
lib = flops.inputs.nixlib.lib // builtins;
home-manager = self.lib.loadInputs.outputs.home-manager;
haumea = haumea.lib;
inherit omnibus;
};
};

Expand Down Expand Up @@ -116,7 +121,7 @@
haumea = flops.inputs.haumea.lib;
dmerge = flops.inputs.dmerge;
POP = POP.lib;
omnibus = self.lib;
inherit omnibus;
};
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
loader = with haumea; [
(matchers.regex "^(.+)\\.(yaml|yml)$" (
_: _: path:
super.inputs.outputs.std.lib.ops.readYAML path
super.readYAML path
))
];
})
20 changes: 20 additions & 0 deletions lib/readYAML.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ nixpkgs }: # source from std
let
inherit (builtins) fromJSON;
inherit (nixpkgs) runCommand yq-go;
inherit (nixpkgs.lib) readFile;
in
# Read a YAML file into a Nix datatype using IFD.
# Similar to:
# > builtins.fromJSON (builtins.readFile ./somefile)
# but takes an input file in YAML instead of JSON.
#
# Type:
# Path -> a :: Nix
path:
let
jsonOutputDrv =
runCommand "from-yaml" { nativeBuildInputs = [ yq-go ]; }
''yq -o=json "${path}" > "$out"'';
in
fromJSON (readFile jsonOutputDrv)
21 changes: 12 additions & 9 deletions templates/nixos/flake.lock

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

32 changes: 25 additions & 7 deletions templates/nixos/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
srvos.url = "github:numtide/srvos";
srvos.inputs.nixpkgs.follows = "nixpkgs";

omnibus.url = "github:gtrunsec/omnibus";
# omnibus.url = "github:gtrunsec/omnibus";
omnibus.url = "/home/guangtao/ghq/github.com/GTrunSec/omnibus";
haumea.follows = "omnibus/flops/haumea";
flops.follows = "omnibus/flops";
};

# nixpkgs & home-manager
Expand All @@ -36,12 +38,28 @@

outputs =
{ self, ... }@inputs:
let
eachSystem = inputs.nixpkgs.lib.genAttrs [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
in
{
lib = inputs.omnibus.exporters.addLoadExtender {
src = ./lib;
inputs = {
inherit inputs;
};
};
lib =
(inputs.omnibus.exporters.addLoadExtender {
src = ./lib;
inputs = {
inherit inputs eachSystem;
};
}).outputs.default;

inherit (self.lib.exporters)
darwinConfigurations
nixosConfigurations
packages
local
;
};
}
File renamed without changes.
File renamed without changes.
55 changes: 55 additions & 0 deletions templates/nixos/lib/exporters.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
let
filterConfigs =
config:
lib.pipe self.hosts [
(lib.filterAttrs (_: v: v ? "${config}"))
(lib.mapAttrs (_: v: v.${config}))
];
in
{
hosts =
(inputs.omnibus.exporters.addLoadExtender {
src = ../nixos/hosts;
inputs = inputs // {
self' = {
inherit (super) inputs;
};
omnibus = inputs.omnibus.lib // {
lib = super.omnibus.lib.outputs.default;
};
};
}).outputs.default;

nixosConfigurations = filterConfigs "nixosConfiguration";

darwinConfigurations = filterConfigs "darwinConfiguration";

local = eachSystem (
system:
let
inputs = (super.inputs.setSystem system).outputs;
loadDataAll =
(omnibus.lib.addLoadExtender {
inputs = {
nixpkgs = inputs.nixpkgs.legacyPackages.${system};
};
}).outputs.default.loadDataAll;
in
{
data = (loadDataAll.addLoadExtender { src = ../local/data; }).outputs.default;
}
);

packages = eachSystem (
system:
let
inputs = (super.inputs.setSystem system).outputs;
in
(
(flops.haumea.pops.default.setInit {
src = ../packages;
loader = _: path: inputs.nixpkgs.callPackage path { };
})
).outputs.default
);
}
13 changes: 13 additions & 0 deletions templates/nixos/lib/inputs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(omnibus.loadInputs.addInputsExtender (
POP.extendPop flops.flake.pops.inputsExtender (
self: super:
let
selfInputs = omnibus.loadInputs.setInitInputs ./__lock;
in
{
inputs = {
nixpkgs = inputs.nixpkgs.legacyPackages;
} // selfInputs.outputs;
}
)
))
14 changes: 7 additions & 7 deletions templates/nixos/lib/nixos.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
loadHomeModules =
(omnibus.loadHomeModules.addLoadExtender { src = ../nixos/homeModules; });

loadHomeProfiles =
(omnibus.loadHomeProfiles.addLoadExtender { src = ../nixos/homeProfiles; });

loadNixOSProfiles =
(omnibus.loadNixOSProfiles.addLoadExtender { src = ../nixos/nixosProfiles; });

loadNixOSModules =
(omnibus.loadNixOSModules.addLoadExtender { src = ../nixos/nixosModules; });

omnibus = {
lib = omnibus.lib.addLoadExtender {
inputs = {
home-manager = inputs.home;
};
};
};
loadDarwinProfiles =
(omnibus.loadNixOSProfiles.addLoadExtender { src = ../nixos/darwinProfiles; });

loadDarwinModules =
(omnibus.loadNixOSModules.addLoadExtender { src = ../nixos/darwinModules; });
}
15 changes: 15 additions & 0 deletions templates/nixos/lib/omnibus.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
loadHomeModules = (omnibus.loadHomeModules.addLoadExtender { });

loadHomeProfiles = (omnibus.loadHomeProfiles.addLoadExtender { });

loadNixOSProfiles = (omnibus.loadNixOSProfiles.addLoadExtender { });

loadNixOSModules = (omnibus.loadNixOSModules.addLoadExtender { });

lib = omnibus.lib.addLoadExtender {
inputs = {
home-manager = inputs.home;
};
};
}
43 changes: 0 additions & 43 deletions templates/nixos/nixos/hosts/nixos/default.nix

This file was deleted.

45 changes: 45 additions & 0 deletions templates/nixos/nixos/hosts/nixos/layouts.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let
outputs = lib.mapAttrs (_: v: v.outputs) (
lib.removeAttrs super.pops [ "inputs" ]
);
in
{
system = "x86_64-linux";

data = outputs.data.default;

nixosSuites = lib.flatten [
# outputs.selfNixOSProfiles.default.bootstrap

# # self.nixosProfiles.default.presets.boot
# outputs.nixosModules.default.programs.git

# # # --custom profiles
# outputs.nixosProfiles.customProfiles.presets.nix
# outputs.nixosProfiles.customProfiles.presets.boot
# outputs.nixosModules.customModules.boot

# outputs.srvos.default.common.nix
(omnibus.lib.mkHome
{
admin = {
uid = 1000;
description = "default manager";
isNormalUser = true;
extraGroups = [ "wheel" ];
};
}
"zsh"
self.homeSuites
)
];

homeSuites =
[
# outputs.homeProfiles.customProfiles.presets.hyprland
# outputs.homeProfiles.default.presets.bat
# # # The parent directory of "presets" is categorized as a list type of "suites"
# (outputs.homeProfiles.default.shell { }).default
# super.pops.homeModules.outputs.default.wayland.windowManager.hyprland
];
}
5 changes: 5 additions & 0 deletions templates/nixos/nixos/hosts/nixos/nixosConfiguration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nixpkgs.lib.nixosSystem rec {
system = super.layouts.system;
pkgs = import nixpkgs { inherit system; };
modules = lib.flatten [ super.layouts.nixosSuites ];
}
5 changes: 2 additions & 3 deletions templates/nixos/nixos/hosts/nixos/pops/inputs.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
(omnibus.loadInputs.addInputsExtender (
(self'.inputs.loadInputs.addInputsExtender (
POP.extendPop flops.flake.pops.inputsExtender (
self: super:
let
selfInputs = omnibus.loadInputs.setInitInputs ../__lock;
local = omnibus.loadInputs.setInitInputs ../../../local;
in
{
inputs = {
Expand All @@ -13,4 +12,4 @@
}
)
)).setSystem
"x86_64-linux"
root.nixos.layouts.system
Loading

0 comments on commit f35be63

Please sign in to comment.