Initial commit

This commit is contained in:
Nikodem Rabuliński 2023-08-03 14:54:05 +02:00
commit 9661927410
No known key found for this signature in database
GPG key ID: FF629AA9E08138DB
27 changed files with 1091 additions and 0 deletions

6
modules/default.nix Normal file
View file

@ -0,0 +1,6 @@
{...}: {
imports = [
./nixos
./flake
];
}

View file

@ -0,0 +1,102 @@
{
nixpkgs,
darwin,
home-manager,
}: {
config,
lib,
flake-parts-lib,
...
}: let
inherit (lib) mkOption mapAttrs;
inherit (flake-parts-lib) mkSubmoduleOptions;
possibleConfigurations = {
nixos = {};
darwin = {};
home = {};
};
in {
_file = ./configurations.nix;
options = {
# Those functions take the final arguments and emit a valid configuration.
# Probably should hardly ever be overriden
builders = {
nixos = mkOption {
type = lib.types.functionTo lib.types.unspecified;
default = nixpkgs.lib.nixosSystem;
};
darwin = mkOption {
type = lib.types.functionTo lib.types.unspecified;
default = darwin.lib.darwinSystem;
};
home = mkOption {
type = lib.types.functionTo lib.types.unspecified;
default = home-manager.lib.homeManagerConfiguration;
};
};
# Those functions map the value of the configuration attribute
# and emit a list of arguments to be passed to respected evalModules
mappers =
mapAttrs
(_: _:
mkOption {
type = lib.types.functionTo lib.types.attrs;
default = lib.id;
})
possibleConfigurations;
configurations = {
nixos = mkOption {
type = lib.types.unspecified;
default = {};
};
darwin = mkOption {
type = lib.types.unspecified;
default = {};
};
home = mkOption {
type = lib.types.unspecified;
default = {};
};
};
# This is exposed so that it's possible to modify the arguments that get passed to a builder
# after they have been mapped. Probably shouldn't do it. Probably should remove it or make it read-only
configurationOptions =
mapAttrs
(_: _:
mkOption {
type = lib.types.attrsOf lib.types.attrs;
})
possibleConfigurations;
};
config = {
configurationOptions =
mapAttrs
(
name: _:
mapAttrs
(configurationName: val: let
mapped = config.mappers.${name} val;
# TODO: specialArgs is actually extraSpecialArgs in home-manager.
# At which level should that be handled?
defaultArgs = {
specialArgs = {inherit configurationName;};
};
in
lib.recursiveUpdate defaultArgs mapped)
config.configurations.${name}
)
possibleConfigurations;
flake = {
nixosConfigurations =
mapAttrs
(_: args: config.builders.nixos args)
config.configurationOptions.nixos;
};
};
}

15
modules/flake/default.nix Normal file
View file

@ -0,0 +1,15 @@
{
flake-parts-lib,
lib,
inputs,
...
}: let
inherit (flake-parts-lib) importApply;
flakeModules = {
configurations = importApply ./configurations.nix {inherit (inputs) nixpkgs darwin home-manager;};
};
in {
imports = lib.attrValues flakeModules;
flake = {inherit flakeModules;};
}

View file

@ -0,0 +1,3 @@
{config, ...}: {
flake.nixosModules.settei = import ./settei {inherit (config) perInput;};
}

View file

@ -0,0 +1,16 @@
{perInput}: {
lib,
config,
...
}: {
imports = [
./sane-defaults.nix
(import ./flake-qol.nix {inherit perInput;})
];
options.settei = with lib; {
username = mkOption {
type = types.str;
};
};
}

View file

@ -0,0 +1,45 @@
{perInput}: {
config,
lib,
pkgs,
...
}: let
cfg = config.settei.flake-qol;
in {
_file = ./flake-qol.nix;
options.settei.flake-qol = with lib; {
enable = lib.mkEnableOption "QoL defaults when using flakes";
reexportAsArgs = mkOption {
type = types.bool;
default = true;
};
inputs = mkOption {
type = types.unspecified;
};
inputs-flakes = mkOption {
type = types.attrs;
readOnly = true;
};
inputs' = mkOption {
type = types.attrs;
readOnly = true;
};
};
config = lib.mkIf cfg.enable {
settei.flake-qol = {
inputs-flakes = lib.filterAttrs (_: input: input ? flake -> input.flake) cfg.inputs;
inputs' = lib.mapAttrs (_: perInput pkgs.stdenv.system) cfg.inputs-flakes;
};
_module.args = lib.mkIf cfg.reexportAsArgs {
inherit (cfg) inputs inputs-flakes inputs';
};
nix = {
registry = lib.mapAttrs (_: flake: {inherit flake;}) cfg.inputs-flakes;
nixPath = map (name: "${name}=flake:${name}") (lib.attrNames cfg.inputs-flakes);
};
};
}

View file

@ -0,0 +1,57 @@
{
lib,
config,
...
} @ args: {
_file = ./sane-defaults.nix;
options.settei.sane-defaults = {
enable = lib.mkEnableOption "Personal sane defaults";
};
config = lib.mkIf config.settei.sane-defaults.enable (let
cfg = config.settei;
inherit (cfg) username;
in {
_module.args = {
username = lib.mkDefault username;
};
hardware.enableRedistributableFirmware = true;
services.openssh.enable = true;
services.tailscale.enable = true;
programs.mosh.enable = lib.mkDefault true;
users = {
mutableUsers = false;
users.${username} = {
isNormalUser = true;
home = "/home/${username}";
group = username;
extraGroups = ["wheel"];
};
groups.${username} = {};
};
networking.hostName = lib.mkDefault (
args.configurationName
or (throw "pass configurationName to module arguments or set networking.hostName yourself")
);
time.timeZone = lib.mkDefault "Europe/Warsaw";
nix = {
settings = {
experimental-features = ["nix-command" "flakes" "repl-flake" "auto-allocate-uids"];
trusted-users = [username];
auto-allocate-uids = true;
};
};
# TODO: Actually this should be extraRules which makes wheel users without any password set
# be able to use sudo with no password
security.sudo.wheelNeedsPassword = false;
system.stateVersion = "22.05";
});
}