From c233d0654ebc4d0dd0e7a2e81a6d49264ec312d3 Mon Sep 17 00:00:00 2001 From: guangtao Date: Sun, 12 May 2024 16:35:08 -0700 Subject: [PATCH] refactor(tests): use submodule instead --- src/mkHome.nix | 11 +++- src/pops/nixosProfiles.nix | 16 +++++ tests/nixos/__fixture/__lock/flake.lock | 27 -------- tests/nixos/__fixture/__lock/flake.nix | 14 ----- .../__fixture/__nixosProfiles/bootstrap.nix | 10 --- tests/nixos/__fixture/layouts.nix | 62 ------------------- tests/nixos/__fixture/pops/flake.nix | 20 ------ tests/nixos/__fixture/pops/homeModules.nix | 34 ---------- tests/nixos/__fixture/pops/homeProfiles.nix | 44 ------------- tests/nixos/__fixture/pops/nixosModules.nix | 46 -------------- tests/nixos/__fixture/pops/nixosProfiles.nix | 54 ---------------- tests/nixos/__fixture/pops/omnibus.nix | 15 ----- .../__fixture/pops/selfNixOSProfiles.nix | 19 ------ tests/nixos/__fixture/pops/srvos.nix | 10 --- tests/nixos/_pops.nix | 20 ------ tests/nixos/expr.nix | 61 ------------------ tests/nixos/format.nix | 6 -- units/nixos/homeProfiles/shell.nix | 5 +- 18 files changed, 28 insertions(+), 446 deletions(-) delete mode 100644 tests/nixos/__fixture/__lock/flake.lock delete mode 100644 tests/nixos/__fixture/__lock/flake.nix delete mode 100644 tests/nixos/__fixture/__nixosProfiles/bootstrap.nix delete mode 100644 tests/nixos/__fixture/layouts.nix delete mode 100644 tests/nixos/__fixture/pops/flake.nix delete mode 100644 tests/nixos/__fixture/pops/homeModules.nix delete mode 100644 tests/nixos/__fixture/pops/homeProfiles.nix delete mode 100644 tests/nixos/__fixture/pops/nixosModules.nix delete mode 100644 tests/nixos/__fixture/pops/nixosProfiles.nix delete mode 100644 tests/nixos/__fixture/pops/omnibus.nix delete mode 100644 tests/nixos/__fixture/pops/selfNixOSProfiles.nix delete mode 100644 tests/nixos/__fixture/pops/srvos.nix delete mode 100644 tests/nixos/_pops.nix delete mode 100644 tests/nixos/expr.nix delete mode 100644 tests/nixos/format.nix diff --git a/src/mkHome.nix b/src/mkHome.nix index 229f22c..42f7efb 100644 --- a/src/mkHome.nix +++ b/src/mkHome.nix @@ -4,7 +4,13 @@ # SPDX-License-Identifier: MIT { lib }: -userSet: shell: suites: +homeModule: userSet: shell: suites: +{ + homeModule ? [ ], + userSet, + shell, + suites ? [ ], +}: let user = lib.head (lib.attrNames userSet); pathsToLinkShell = lib.elem shell [ @@ -17,7 +23,8 @@ let in { imports = - [ + lib.flatten [ + homeModule { users.users = userSet; } ( { pkgs, lib, ... }: diff --git a/src/pops/nixosProfiles.nix b/src/pops/nixosProfiles.nix index e41f112..6ef232e 100644 --- a/src/pops/nixosProfiles.nix +++ b/src/pops/nixosProfiles.nix @@ -8,12 +8,28 @@ projectRoot, POP, flops, + lib, }: (super.nixosModules.addLoadExtender { load = { src = projectRoot + "/units/nixos/nixosProfiles"; type = "nixosProfilesOmnibus"; transformer = [ (_: _: _) ]; + inputsTransformer = [ + ( + self: + self + // ( + let + system = if self ? system then self.system else throw "system is required"; + in + { + isDarwin = lib.elem system lib.systems.doubles.darwin; + isLinux = lib.elem system lib.systems.doubles.linux; + } + ) + ) + ]; }; }).addExporters [ diff --git a/tests/nixos/__fixture/__lock/flake.lock b/tests/nixos/__fixture/__lock/flake.lock deleted file mode 100644 index 38da713..0000000 --- a/tests/nixos/__fixture/__lock/flake.lock +++ /dev/null @@ -1,27 +0,0 @@ -{ - "nodes": { - "catppuccin-bat": { - "flake": false, - "locked": { - "lastModified": 1668065083, - "narHash": "sha256-6WVKQErGdaqb++oaXnY3i6/GuH2FhTgK0v4TN4Y0Wbw=", - "owner": "catppuccin", - "repo": "bat", - "rev": "ba4d16880d63e656acced2b7d4e034e4a93f74b1", - "type": "github" - }, - "original": { - "owner": "catppuccin", - "repo": "bat", - "type": "github" - } - }, - "root": { - "inputs": { - "catppuccin-bat": "catppuccin-bat" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/tests/nixos/__fixture/__lock/flake.nix b/tests/nixos/__fixture/__lock/flake.nix deleted file mode 100644 index 96d5c11..0000000 --- a/tests/nixos/__fixture/__lock/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -{ - inputs = { - catppuccin-bat = { - url = "github:catppuccin/bat"; - flake = false; - }; - }; - outputs = _: { }; -} diff --git a/tests/nixos/__fixture/__nixosProfiles/bootstrap.nix b/tests/nixos/__fixture/__nixosProfiles/bootstrap.nix deleted file mode 100644 index 14cef65..0000000 --- a/tests/nixos/__fixture/__nixosProfiles/bootstrap.nix +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -{ - fileSystems."/" = { - device = "/dev/disk/by-label/nixos"; - }; -} diff --git a/tests/nixos/__fixture/layouts.nix b/tests/nixos/__fixture/layouts.nix deleted file mode 100644 index fdc8f43..0000000 --- a/tests/nixos/__fixture/layouts.nix +++ /dev/null @@ -1,62 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -let - inherit (inputs) nixpkgs darwin; - # exports.default to be default - outputs = omnibus.lib.omnibus.mapPopsExports' super.pops; - # with multi-layout - outputs' = omnibus.lib.omnibus.mapPopsExports super.pops; -in -{ - system = "x86_64-linux"; - - inherit data outputs outputs'; - - nixosSuites = lib.flatten [ - # outputs.selfNixOSProfiles.default.bootstrap - { users.users.root.initialPassword = "nixos"; } - # self.nixosProfiles.default.presets.boot - # load a suite profile from audio - # (outputs.nixosProfiles.default.audio {}).default - - # # --custom profiles - # # exporter.nixosProfiles.customProfiles.presets.boot - # outputs.srvos.default.common.nix - - (outputs'.omnibus.mkHome inputs.home-manager.nixosModule { - admin = { - uid = 1000; - description = "default manager"; - isNormalUser = true; - extraGroups = [ "wheel" ]; - }; - } "zsh" self.homeSuites) - ]; - - homeSuites = [ - # exporter.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.exports.default.wayland.windowManager.hyprland - ]; - - nixosConfiguration = - module: - nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = lib.flatten [ - self.nixosSuites - module - ]; - }; - - darwinConfiguration = - module: - darwin.lib.darwinSystem { - system = "aarch64-darwin"; - modules = lib.flatten [ module ]; - }; -} diff --git a/tests/nixos/__fixture/pops/flake.nix b/tests/nixos/__fixture/pops/flake.nix deleted file mode 100644 index 1c6a9d2..0000000 --- a/tests/nixos/__fixture/pops/flake.nix +++ /dev/null @@ -1,20 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -(omnibus.pops.flake.addInputsExtender ( - POP.extendPop flops.flake.pops.inputsExtender ( - _self: _super: - let - selfInputs = omnibus.pops.flake.setInitInputs ../__lock; - local = omnibus.pops.flake.setInitInputs (projectRoot + "/local"); - in - { - inputs = { - std = local.outputs.std; - } // selfInputs.inputs; - } - ) -)).setSystem - root.layouts.system diff --git a/tests/nixos/__fixture/pops/homeModules.nix b/tests/nixos/__fixture/pops/homeModules.nix deleted file mode 100644 index 4359c2d..0000000 --- a/tests/nixos/__fixture/pops/homeModules.nix +++ /dev/null @@ -1,34 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -let - inherit (inputs) dmerge; -in -(omnibus.src.pops.homeModules.addLoadExtender { - load.inputs = { - inputs = { - inherit (super.flake.inputs) catppuccin-bat; - }; - }; -}).addExporters - [ - (POP.extendPop flops.haumea.pops.exporter ( - self: _super: { - exports.customModules = self.outputs [ - { - value = { - enable = false; - customList = with dmerge; append [ "1" ]; - imports = with dmerge; append [ ]; - }; - path = [ - "services" - "openssh" - ]; - } - ]; - } - )) - ] diff --git a/tests/nixos/__fixture/pops/homeProfiles.nix b/tests/nixos/__fixture/pops/homeProfiles.nix deleted file mode 100644 index 7d17576..0000000 --- a/tests/nixos/__fixture/pops/homeProfiles.nix +++ /dev/null @@ -1,44 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -let - inherit (inputs) dmerge; -in -(omnibus.src.pops.homeProfiles.addLoadExtender { - load.inputs = { - omnibus = { - homeModules = super.homeModules.exports.default; - }; - inputs = { - inherit (omnibus.flake.inputs) nur nix-filter navi-tldr-pages; - }; - }; -}).addExporters - [ - (POP.extendPop flops.haumea.pops.exporter ( - self: _super: { - exports.customProfiles = self.outputs [ - { - value = - { selfModule' }: - with dmerge; - selfModule' ( - m: - dmerge m { - config.wayland.windowManager.hyprland.__profiles__ = { - nvidia.content = true; - }; - } - ); - path = [ - "presets" - "hyprland" - "default" - ]; - } - ]; - } - )) - ] diff --git a/tests/nixos/__fixture/pops/nixosModules.nix b/tests/nixos/__fixture/pops/nixosModules.nix deleted file mode 100644 index 1287109..0000000 --- a/tests/nixos/__fixture/pops/nixosModules.nix +++ /dev/null @@ -1,46 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -let - inherit (inputs) dmerge; -in -(omnibus.src.pops.nixosModules.addLoadExtender { - load.inputs = { - inputs = super.flake.inputs; - }; -}).addExporters - [ - (POP.extendPop flops.haumea.pops.exporter ( - self: _super: { - exports.customModules = - with dmerge; - self.outputs [ - ({ - value = - { selfModule' }: - selfModule' ( - m: - dmerge - (lib.removeAttrs m [ - # popup the imports, so that we can use own nixosModule - # "imports" - ]) - { - config.contents = update [ 0 ] [ - { - content = { - boot.loader.timeout.content = 10; - # loader.efi.canTouchEfiVariables = false; - }; - } - ]; - } - ); - path = [ "boot" ]; - }) - ]; - } - )) - ] diff --git a/tests/nixos/__fixture/pops/nixosProfiles.nix b/tests/nixos/__fixture/pops/nixosProfiles.nix deleted file mode 100644 index 51b58aa..0000000 --- a/tests/nixos/__fixture/pops/nixosProfiles.nix +++ /dev/null @@ -1,54 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -let - inherit (inputs) dmerge; -in -(omnibus.src.pops.nixosProfiles.addLoadExtender { - load = { - inputs = { - inputs = super.flake.inputs; - omnibus = { - nixosModules = super.nixosModules.exports.default; - }; - }; - }; -}).addExporters - [ - (POP.extendPop flops.haumea.pops.exporter ( - self: _super: { - exports.customProfiles = self.outputs [ - { - value = - { selfModule' }: - selfModule' ( - m: - dmerge m { - config.nix.extraOptions = '' - allowed-uris = https://github.com/ - ''; - } - ); - path = [ - "presets" - "nix" - ]; - } - { - # boot.__profiles__.systemd-initrd.enable = true; - value = - { selfModule' }: - selfModule' ( - m: dmerge m { config.boot.__profiles__.systemd-boot.enable = true; } - ); - path = [ - "presets" - "boot" - ]; - } - ]; - } - )) - ] diff --git a/tests/nixos/__fixture/pops/omnibus.nix b/tests/nixos/__fixture/pops/omnibus.nix deleted file mode 100644 index 2971e0d..0000000 --- a/tests/nixos/__fixture/pops/omnibus.nix +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -(omnibus.pops.self.addLoadExtender { - load.inputs = { - inputs = inputs; - }; -}).addExporters - [ - (POP.extendPop flops.haumea.pops.exporter ( - _self: _super: { exports.customProfiles = { }; } - )) - ] diff --git a/tests/nixos/__fixture/pops/selfNixOSProfiles.nix b/tests/nixos/__fixture/pops/selfNixOSProfiles.nix deleted file mode 100644 index 8a93348..0000000 --- a/tests/nixos/__fixture/pops/selfNixOSProfiles.nix +++ /dev/null @@ -1,19 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -(super.nixosProfiles.addLoadExtender { - load = { - src = ../__nixosProfiles; - loader = haumea.loaders.scoped; - type = "nixosProfiles"; - inputs = { - omnibus = { - nixosProfiles = super.nixosProfiles.outputs.nixosProfiles; - data = super.data.exports.default; - }; - }; - }; -}).addExporters - [ (POP.extendPop flops.haumea.pops.exporter (_self: _super: { })) ] diff --git a/tests/nixos/__fixture/pops/srvos.nix b/tests/nixos/__fixture/pops/srvos.nix deleted file mode 100644 index 37e6952..0000000 --- a/tests/nixos/__fixture/pops/srvos.nix +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -(omnibus.pops.srvos.addLoadExtender { load.inputs = { }; }).addExporters [ - (POP.extendPop flops.haumea.pops.exporter ( - _self: _super: { exports.customProfiles = { }; } - )) -] diff --git a/tests/nixos/_pops.nix b/tests/nixos/_pops.nix deleted file mode 100644 index c2d99ad..0000000 --- a/tests/nixos/_pops.nix +++ /dev/null @@ -1,20 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -{ - omnibus, - root, - haumea, -}: -(omnibus.pops.load { - src = ./__fixture; - loader = with haumea; [ (matchers.nix loaders.scoped) ]; - inputs = { - data = root.data; - inputs = { - inherit (omnibus.flake.inputs) darwin nixpkgs home-manager; - }; - }; -}) diff --git a/tests/nixos/expr.nix b/tests/nixos/expr.nix deleted file mode 100644 index b9c468c..0000000 --- a/tests/nixos/expr.nix +++ /dev/null @@ -1,61 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -{ - super, - debug, - lib, -}: -let - out = super.pops.exports.default.layouts; - extraHomeModule = m: { - home-manager.users.admin = { - imports = lib.flatten m; - }; - }; -in -{ - # inherit out; - bootProfile = - (out.nixosConfiguration [ - out.outputs.nixosProfiles.customProfiles.presets.boot - ]).config.boot.__profiles__; - - customModuleBootTimeOut = - (out.nixosConfiguration [ - out.outputs.nixosModules.customModules.boot - { - config.boot.__profiles__.speedup = true; - config.boot.__profiles__.systemd-boot.enable = true; - } - ]).config.boot.loader.timeout; - - hyprland = - (out.nixosConfiguration [ - out.outputs.nixosModules.customModules.boot - (extraHomeModule [ - out.outputs.homeProfiles.customProfiles.presets.hyprland.default - out.outputs.homeProfiles.default.presets.firefox - ]) - ]).config.home-manager.users.admin.wayland.windowManager.hyprland.__profiles__; -} -// lib.optionalAttrs debug { - nixosConfiguration = out.nixosConfiguration [ - # out.outputs.nixosProfiles.default.presets.boot - out.outputs.nixosProfiles.default.cloud.contabo - out.outputs.nixosProfiles.default.dev.coding - ]; - pop = super.pops; - - homeConfiguration = - (out.nixosConfiguration [ - out.outputs.nixosProfiles.default.presets.boot - (extraHomeModule [ - out.outputs.homeProfiles.customProfiles.presets.hyprland.default - out.outputs.homeProfiles.default.presets.firefox - out.outputs.homeProfiles.default.presets.foliate - ]) - ]).config.home-manager.users.admin; -} diff --git a/tests/nixos/format.nix b/tests/nixos/format.nix deleted file mode 100644 index 85889da..0000000 --- a/tests/nixos/format.nix +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The omnibus Authors -# SPDX-FileCopyrightText: 2024 The omnibus Authors -# -# SPDX-License-Identifier: MIT - -"pretty" diff --git a/units/nixos/homeProfiles/shell.nix b/units/nixos/homeProfiles/shell.nix index 38c4b7b..a21dd52 100644 --- a/units/nixos/homeProfiles/shell.nix +++ b/units/nixos/homeProfiles/shell.nix @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: 2024 The omnibus Authors # # SPDX-License-Identifier: MIT - # [[id:cbe34da3-ffbb-423c-aee4-d0cd71af51e4][shell:1]] { root, @@ -10,6 +9,8 @@ lib, super, inputs, + isLinux, + isDarwin, }: let presets = root.presets; @@ -47,7 +48,7 @@ with presets; # ------------------------------ spell-check self.fileManager - #(lib.optionals inputs.nixpkgs.stdenv.isLinux presets.alacritty) + (lib.optionals isLinux presets.alacritty) ]; modernTools = [