2023-05-25 04:39:57 +07:00
|
|
|
{
|
|
|
|
description = "NixOS + Home Manager configuration of chayleaf";
|
|
|
|
|
|
|
|
inputs = {
|
2023-11-21 04:46:52 +07:00
|
|
|
#nixpkgs.url = "github:NixOS/nixpkgs/3dc2b4f8166f744c3b3e9ff8224e7c5d74a5424f";
|
|
|
|
# nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
2024-01-30 23:01:09 +07:00
|
|
|
nixpkgs.url = "github:chayleaf/nixpkgs";
|
2023-05-25 04:39:57 +07:00
|
|
|
nixos-hardware.url = "github:NixOS/nixos-hardware";
|
2023-12-25 03:40:33 +07:00
|
|
|
nix-index-database = {
|
|
|
|
url = "github:nix-community/nix-index-database";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-10-17 20:25:03 +07:00
|
|
|
mobile-nixos = {
|
|
|
|
# url = "github:NixOS/mobile-nixos";
|
2023-12-19 11:12:34 +07:00
|
|
|
url = "github:chayleaf/mobile-nixos/fix-op6-modem";
|
2023-10-17 20:25:03 +07:00
|
|
|
flake = false;
|
|
|
|
};
|
2023-05-25 04:39:57 +07:00
|
|
|
impermanence.url = "github:nix-community/impermanence";
|
|
|
|
nur.url = "github:nix-community/NUR";
|
|
|
|
rust-overlay = {
|
|
|
|
url = "github:oxalica/rust-overlay";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-11-27 00:20:43 +07:00
|
|
|
coop-ofd = {
|
|
|
|
url = "github:chayleaf/coop-ofd";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-05-25 04:39:57 +07:00
|
|
|
home-manager = {
|
2024-02-06 14:59:06 +07:00
|
|
|
url = "github:chayleaf/home-manager/librewolf";
|
2023-05-25 04:39:57 +07:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
nix-gaming = {
|
|
|
|
url = "github:fufexan/nix-gaming";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
notlua = {
|
2023-06-11 21:48:35 +07:00
|
|
|
url = "github:chayleaf/notlua";
|
2023-05-25 04:39:57 +07:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-06-24 07:12:11 +07:00
|
|
|
notnft = {
|
2023-06-24 14:52:13 +07:00
|
|
|
url = "github:chayleaf/notnft";
|
2023-06-24 07:12:11 +07:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
nixos-router = {
|
2023-06-24 14:52:13 +07:00
|
|
|
url = "github:chayleaf/nixos-router";
|
2023-06-24 07:12:11 +07:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-05-25 04:39:57 +07:00
|
|
|
nixos-mailserver = {
|
|
|
|
url = "gitlab:simple-nixos-mailserver/nixos-mailserver";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-06-11 18:02:38 +07:00
|
|
|
flake-compat = {
|
|
|
|
url = "github:edolstra/flake-compat";
|
|
|
|
flake = false;
|
|
|
|
};
|
2023-05-25 04:39:57 +07:00
|
|
|
};
|
|
|
|
|
2023-12-18 08:48:49 +07:00
|
|
|
outputs = base-inputs@{ self, nixpkgs, ... }:
|
2023-05-25 05:09:17 +07:00
|
|
|
let
|
2023-06-24 09:49:57 +07:00
|
|
|
# --impure required for developing
|
2023-06-27 15:25:19 +07:00
|
|
|
# it takes the paths for modules from filesystem as opposed to flake inputs
|
2023-12-18 08:48:49 +07:00
|
|
|
dev = {
|
|
|
|
# coop-ofd = true;
|
2024-02-06 14:59:06 +07:00
|
|
|
# home-manager = true;
|
2023-12-19 11:12:34 +07:00
|
|
|
# mobile-nixos = true;
|
|
|
|
# nixos-router = true;
|
|
|
|
# notnft = true;
|
2023-12-18 08:48:49 +07:00
|
|
|
};
|
2023-05-25 05:09:17 +07:00
|
|
|
# IRL-related stuff I'd rather not put into git
|
2023-05-26 01:38:17 +07:00
|
|
|
priv =
|
2023-12-18 08:48:49 +07:00
|
|
|
if builtins.pathExists ./private.nix then import ./private.nix { }
|
|
|
|
else if builtins.pathExists ./private/default.nix then import ./private { }
|
2023-05-26 00:40:31 +07:00
|
|
|
# workaround for git flakes not having access to non-checked out files
|
2023-05-26 01:38:17 +07:00
|
|
|
else if builtins?extraBuiltins.secrets then builtins.extraBuiltins.secrets
|
2023-05-26 00:40:31 +07:00
|
|
|
# yes, this is impure, this is a last ditch effort at getting access to secrets
|
2023-12-25 04:13:25 +07:00
|
|
|
else import /secrets/nixos { };
|
2023-06-24 07:12:11 +07:00
|
|
|
devPath = priv.devPath or ../.;
|
2023-12-18 08:48:49 +07:00
|
|
|
inputs = builtins.mapAttrs
|
|
|
|
(name: input:
|
|
|
|
if dev.${name} or false then
|
2023-12-19 11:12:34 +07:00
|
|
|
(if input._type or null == "flake"
|
2024-02-06 14:59:06 +07:00
|
|
|
then let inputs = input.inputs // { self = (import /${devPath}/${name}/flake.nix).outputs inputs; };
|
|
|
|
in inputs.self
|
2023-12-18 08:48:49 +07:00
|
|
|
else /${devPath}/${name})
|
|
|
|
else input)
|
|
|
|
base-inputs;
|
2023-05-25 06:24:57 +07:00
|
|
|
# if x has key s, get it. Otherwise return def
|
|
|
|
# All private config for hostname
|
2023-05-30 10:02:36 +07:00
|
|
|
getPriv = hostname: priv.${hostname} or { };
|
2023-05-25 06:24:57 +07:00
|
|
|
# Private NixOS config for hostname
|
2023-05-30 10:02:36 +07:00
|
|
|
getPrivSys = hostname: (getPriv hostname).system or { };
|
2023-05-25 06:24:57 +07:00
|
|
|
# Private home-manager config for hostname and username
|
2023-05-30 10:02:36 +07:00
|
|
|
getPrivUser = hostname: user: (getPriv hostname).${user} or { };
|
2023-05-25 06:24:57 +07:00
|
|
|
# extended lib
|
2023-12-18 08:48:49 +07:00
|
|
|
lib = nixpkgs.lib // import ./lib.nix { inherit (nixpkgs) lib; };
|
2023-05-30 10:02:36 +07:00
|
|
|
# can't use callPackage ./pkgs here, idk why; use import instead
|
2023-10-26 22:22:39 +07:00
|
|
|
overlay' = args: self: super: import ./pkgs ({
|
2023-05-25 06:24:57 +07:00
|
|
|
pkgs = super;
|
2023-06-11 21:48:35 +07:00
|
|
|
pkgs' = self;
|
2023-05-25 06:24:57 +07:00
|
|
|
lib = super.lib;
|
2023-12-18 08:48:49 +07:00
|
|
|
inherit inputs;
|
2023-10-26 22:22:39 +07:00
|
|
|
} // args);
|
|
|
|
overlay = overlay' { };
|
2023-05-25 06:24:57 +07:00
|
|
|
# I override some settings down the line, but overlays always stay the same
|
|
|
|
mkPkgs = config: import nixpkgs (config // {
|
2023-10-26 22:22:39 +07:00
|
|
|
overlays = config.overlays or [ ] ++ [ overlay ];
|
2023-05-25 06:24:57 +07:00
|
|
|
});
|
2023-06-24 09:49:57 +07:00
|
|
|
# this is actual config, it gets processed below
|
2023-07-28 12:02:37 +07:00
|
|
|
config = let
|
2023-07-28 14:20:39 +07:00
|
|
|
mkBpiR3 = args: config: config // {
|
2023-07-28 12:02:37 +07:00
|
|
|
system = "aarch64-linux";
|
2023-10-26 22:22:39 +07:00
|
|
|
modules = config.modules or [ ] ++ [ (import ./system/devices/bpi-r3-router.nix args) ];
|
2023-05-25 05:09:17 +07:00
|
|
|
};
|
2023-07-28 12:02:37 +07:00
|
|
|
routerConfig = rec {
|
2023-05-25 05:09:17 +07:00
|
|
|
system = "aarch64-linux";
|
|
|
|
modules = [
|
2023-07-12 04:05:05 +07:00
|
|
|
{
|
2023-12-18 08:48:49 +07:00
|
|
|
_module.args.server-config = self.nixosConfigurations.server.config;
|
|
|
|
_module.args.notnft = inputs.notnft.lib.${system};
|
2023-07-28 14:20:39 +07:00
|
|
|
}
|
2023-12-18 08:48:49 +07:00
|
|
|
inputs.nixos-router.nixosModules.default
|
2023-07-28 14:20:39 +07:00
|
|
|
];
|
|
|
|
};
|
2023-12-18 08:48:49 +07:00
|
|
|
in {
|
2023-07-28 12:02:37 +07:00
|
|
|
router-emmc = mkBpiR3 "emmc" routerConfig;
|
|
|
|
router-sd = mkBpiR3 "sd" routerConfig;
|
2023-10-17 20:25:03 +07:00
|
|
|
server = {
|
2023-09-13 17:20:18 +07:00
|
|
|
system = "aarch64-linux";
|
2023-06-12 17:07:38 +07:00
|
|
|
modules = [
|
2023-12-18 08:48:49 +07:00
|
|
|
{ _module.args.router-config = self.nixosConfigurations.router-emmc.config; }
|
2023-09-13 17:20:18 +07:00
|
|
|
./system/devices/radxa-rock5a-server.nix
|
2023-05-25 05:09:17 +07:00
|
|
|
];
|
|
|
|
};
|
2023-05-25 06:24:57 +07:00
|
|
|
nixmsi = rec {
|
|
|
|
system = "x86_64-linux";
|
2023-12-18 08:48:49 +07:00
|
|
|
modules = [ ./system/devices/msi-delta-15-workstation.nix ];
|
2023-05-25 06:24:57 +07:00
|
|
|
home.common.extraSpecialArgs = {
|
2023-12-18 08:48:49 +07:00
|
|
|
notlua = inputs.notlua.lib.${system};
|
2023-05-25 06:24:57 +07:00
|
|
|
};
|
2023-12-18 08:48:49 +07:00
|
|
|
home.user = [ ./home/hosts/nixmsi.nix ];
|
2023-05-25 06:24:57 +07:00
|
|
|
};
|
2023-12-24 14:27:43 +07:00
|
|
|
phone = rec {
|
2023-10-17 20:25:03 +07:00
|
|
|
system = "aarch64-linux";
|
2023-12-19 11:12:34 +07:00
|
|
|
modules = [ ./system/devices/oneplus-6-phone.nix ];
|
2023-12-24 14:27:43 +07:00
|
|
|
home.common.extraSpecialArgs = {
|
|
|
|
notlua = inputs.notlua.lib.${system};
|
|
|
|
};
|
|
|
|
home.user = [ ./home/hosts/phone.nix ];
|
2023-10-17 20:25:03 +07:00
|
|
|
};
|
2023-12-18 08:48:49 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
overlays.default = overlay;
|
|
|
|
packages = lib.genAttrs [
|
|
|
|
"x86_64-linux"
|
|
|
|
"aarch64-linux"
|
|
|
|
] (system: let self = overlay' { isOverlay = false; } (mkPkgs { inherit system; } // self) (import nixpkgs { inherit system; }); in self);
|
|
|
|
nixosImages.router = let pkgs = mkPkgs { inherit (config.router-emmc) system; }; in {
|
|
|
|
emmcImage = pkgs.callPackage ./system/hardware/bpi-r3/image.nix {
|
|
|
|
inherit (self.nixosConfigurations.router-emmc) config;
|
|
|
|
rootfsImage = self.nixosConfigurations.router-emmc.config.system.build.rootfsImage;
|
|
|
|
bpiR3Stuff = pkgs.bpiR3StuffEmmc;
|
|
|
|
};
|
|
|
|
sdImage = pkgs.callPackage ./system/hardware/bpi-r3/image.nix {
|
|
|
|
inherit (self.nixosConfigurations.router-sd) config;
|
|
|
|
rootfsImage = self.nixosConfigurations.router-sd.config.system.build.rootfsImage;
|
|
|
|
bpiR3Stuff = pkgs.bpiR3StuffSd;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
hydraJobs = {
|
|
|
|
server.${config.server.system} = self.nixosConfigurations.server.config.system.build.toplevel;
|
|
|
|
router.${config.router-emmc.system} = self.nixosConfigurations.router-emmc.config.system.build.toplevel;
|
2023-12-24 14:27:43 +07:00
|
|
|
phone.${config.phone.system} = self.nixosConfigurations.phone.config.system.build.toplevel;
|
|
|
|
phone-home.${config.phone.system} = self.homeConfigurations."user@phone".activation-script;
|
|
|
|
workstation.${config.nixmsi.system} = self.nixosConfigurations.nixmsi.config.system.build.toplevel;
|
2023-12-18 08:48:49 +07:00
|
|
|
workstation-home.${config.nixmsi.system} = self.homeConfigurations."user@nixmsi".activation-script;
|
2023-05-25 05:09:17 +07:00
|
|
|
};
|
2023-06-24 09:49:57 +07:00
|
|
|
|
|
|
|
# this is the system config processing part
|
2023-12-18 08:48:49 +07:00
|
|
|
nixosConfigurations = lib.flip builtins.mapAttrs config (hostname: args @ { modules, nixpkgs ? {}, home ? {}, ... }:
|
|
|
|
lib.nixosSystem {
|
|
|
|
inherit (args) system;
|
2023-05-30 10:02:36 +07:00
|
|
|
# allow modules to access nixpkgs directly, use customized lib,
|
|
|
|
# and pass nixos-harware to let hardware modules import parts of nixos-hardware
|
|
|
|
specialArgs = {
|
2023-12-18 08:48:49 +07:00
|
|
|
inherit inputs lib;
|
|
|
|
hardware = inputs.nixos-hardware.nixosModules;
|
|
|
|
} // args.specialArgs or { };
|
|
|
|
modules = args.modules or [ ]
|
|
|
|
++ [
|
2023-05-26 01:38:17 +07:00
|
|
|
(getPrivSys hostname)
|
2023-12-18 08:48:49 +07:00
|
|
|
{ networking.hostName = lib.mkDefault hostname;
|
|
|
|
nixpkgs.overlays = [ overlay ]; }
|
|
|
|
inputs.impermanence.nixosModule
|
2023-05-30 10:02:36 +07:00
|
|
|
]
|
2023-12-18 08:48:49 +07:00
|
|
|
++ map (x: ./system/modules/${x}) (builtins.attrNames (builtins.readDir ./system/modules))
|
2023-05-30 10:02:36 +07:00
|
|
|
# the following is NixOS home-manager module configuration. Currently unused, but I might start using it for some hosts later.
|
2023-12-18 08:48:49 +07:00
|
|
|
++ lib.optionals (home != { } && home.common.enableNixosModule or false) [
|
|
|
|
inputs.home-manager.nixosModules.home-manager
|
|
|
|
{ home-manager = builtins.removeAttrs (home.common or { }) [ "nixpkgs" "nix" "enableNixosModule" ]; }
|
|
|
|
{ # set both to false to match behavior with standalone home-manager
|
2023-05-25 11:34:27 +07:00
|
|
|
home-manager.useGlobalPkgs = false;
|
|
|
|
home-manager.useUserPackages = false;
|
|
|
|
home-manager.users = builtins.mapAttrs (username: modules: {
|
|
|
|
imports = modules ++ [
|
2023-12-18 08:48:49 +07:00
|
|
|
{ nixpkgs = home.common.nixpkgs or { };
|
|
|
|
nix = home.common.nix or { }; }
|
2023-05-26 00:40:31 +07:00
|
|
|
({ config, pkgs, lib, ...}: {
|
2023-05-25 11:34:27 +07:00
|
|
|
nixpkgs.overlays = [ overlay ];
|
2023-12-18 08:48:49 +07:00
|
|
|
nix.package = lib.mkDefault pkgs.nixForNixPlugins; })
|
2023-05-26 01:38:17 +07:00
|
|
|
(getPrivUser hostname username)
|
2023-05-25 11:34:27 +07:00
|
|
|
];
|
2023-12-18 08:48:49 +07:00
|
|
|
}) (builtins.removeAttrs home [ "common" ]); }
|
|
|
|
];
|
|
|
|
});
|
2023-05-30 10:02:36 +07:00
|
|
|
|
2023-05-25 06:24:57 +07:00
|
|
|
# for each hostname, for each user, generate an attribute "${user}@${hostname}"
|
2023-05-25 05:09:17 +07:00
|
|
|
homeConfigurations =
|
2023-12-18 08:48:49 +07:00
|
|
|
builtins.listToAttrs (builtins.concatLists
|
|
|
|
(lib.flip lib.mapAttrsToList config
|
|
|
|
(hostname: { system, home ? {}, ... }:
|
|
|
|
let
|
|
|
|
common' = builtins.removeAttrs (home.common or { }) [ "nix" "nixpkgs" "enableNixosModule" ];
|
|
|
|
pkgs = mkPkgs ({ inherit system; } // home.common.nixpkgs or { });
|
|
|
|
common = common' // { inherit pkgs; };
|
|
|
|
in
|
|
|
|
lib.flip lib.mapAttrsToList (builtins.removeAttrs home [ "common" ])
|
|
|
|
# this is where actual config takes place
|
|
|
|
(user: homeConfig: lib.nameValuePair "${user}@${hostname}"
|
|
|
|
(inputs.home-manager.lib.homeManagerConfiguration (common // {
|
|
|
|
extraSpecialArgs = (common.extraSpecialArgs or { }) // { inherit inputs; };
|
|
|
|
modules =
|
|
|
|
homeConfig
|
|
|
|
++ common.modules or [ ]
|
|
|
|
++ [
|
|
|
|
(getPrivUser hostname user)
|
|
|
|
({ pkgs, lib, ... }: {
|
|
|
|
nixpkgs.overlays = [ overlay ];
|
|
|
|
nix.package = lib.mkDefault pkgs.nixForNixPlugins;
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}))))));
|
2023-05-25 05:09:17 +07:00
|
|
|
};
|
2023-05-25 04:39:57 +07:00
|
|
|
}
|