Skip to content

Commit

Permalink
feat: temp
Browse files Browse the repository at this point in the history
  • Loading branch information
r17x committed Feb 15, 2024
1 parent b7180a1 commit 3e81ac8
Show file tree
Hide file tree
Showing 20 changed files with 518 additions and 726 deletions.
491 changes: 145 additions & 346 deletions flake.lock

Large diffs are not rendered by default.

416 changes: 36 additions & 380 deletions flake.nix

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions home/shells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ let
in
{
home = with pkgs;{
sessionVariables = {
OPENAI_API_KEY = "$(cat ${config.sops.secrets.openai_api_key.path})";
};

inherit shellAliases;
sessionPath = [
"$HOME/.yarn/bin"
Expand Down
40 changes: 40 additions & 0 deletions hosts/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ ... }:

let
sharedModules = [
../shared/darwin/gpg.nix
../shared/darwin/homebrew.nix
../shared/darwin/network.nix
../shared/darwin/packages.nix
../shared/darwin/system.nix
];
in

{
# nix-darwin configurations
parts.darwinConfigurations = {
# Apple M1
eR17x = {
system = "aarch64-darwin";
stateVersion = 4;
modules = sharedModules;
};
};

# NixOS configurations
# parts.nixosConfigurations = {
# linuxBased = {
# system = "x86_64-linux";
# stateVersion = "23.05";

# modules = [];
# };
# wsl2 = {
# system = "x86_64-linux";
# stateVersion = "22.05"; # only change this if you know what you are doing.
# wsl = true;

# modules = [ ];
# };
#};
}
63 changes: 63 additions & 0 deletions modules/parts/darwin.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{ config, lib, inputs, withSystem, ... }:

let
inherit lib;
inherit (lib) types;

cfg = config.parts.darwinConfigurations;
configurations = builtins.mapAttrs (_: value: value._darwin) cfg;

darwinOpts = { config, name, ... }: {
options = {
system = lib.mkOption {
type = types.enum [ "aarch64-darwin" "x86_64-darwin" ];
description = "System architecture for the configuration.";
};

stateVersion = lib.mkOption {
type = types.int;
description = "nix-darwin state version, changing this value DOES NOT update your system.";
};

modules = lib.mkOption {
type = types.listOf types.unspecified;
description = "List of nix-darwin modules to include in the configuration.";
};

_darwin = lib.mkOption {
type = types.unspecified;
readOnly = true;
description = "Composed nix-darwin configuration.";
};
};

config._darwin = withSystem config.system (ctx:
inputs.darwin.lib.darwinSystem {
inherit inputs;
inherit (ctx) system;

modules = config.modules ++ [
# Composed home-manager configuration.
inputs.home.darwinModules.home-manager

({ pkgs, ... }: {
inherit (ctx) nix;
nixpkgs = removeAttrs ctx.nixpkgs [ "hostPlatform" ];
_module.args = ctx.extraModuleArgs;
networking.hostName = name;
networking.computerName = name;
system.stateVersion = config.stateVersion;
environment.systemPackages = ctx.basePackagesFor pkgs;
})
];
}
);
};
in
{
options.parts.darwinConfigurations = lib.mkOption {
type = types.attrsOf (types.submodule darwinOpts);
};

config.flake.darwinConfigurations = configurations;
}
76 changes: 76 additions & 0 deletions modules/parts/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{ self, inputs, ... }:

{
imports = [
./home.nix
./darwin.nix
];

perSystem = { lib, pkgs, system, inputs', ... }: {
formatter = inputs.nixpkgs-fmt.defaultPackage.${system};

_module.args = rec {
# the nix package manager configurations and settings.
nix = import ./nix.nix {
inherit lib inputs inputs';
inherit (pkgs) stdenv;
};

# nixpkgs (channel) configuration (not the flake input)
nixpkgs = {
config = lib.mkForce {
allowBroken = true;
allowUnfree = true;
tarball-ttl = 0;

# Experimental options, disable if you don't know what you are doing!
contentAddressedByDefault = false;
};

hostPlatform = system;

overlays = lib.mkForce [
self.overlays.default
];
};

# Extra arguments passed to the module system for nix-darwin, NixOS, and home-manager
extraModuleArgs = {
inherit inputs' system;
inputs = lib.mkForce inputs;

/*
One can access these nixpkgs branches like so:
`branches.stable.mpd'
`branches.master.linuxPackages_xanmod'
*/
branches =
let
pkgsFrom = branch: system: import branch {
inherit system;
inherit (nixpkgs) config overlays;
};
in
{
master = pkgsFrom inputs.master system;
unstable = pkgsFrom inputs.unstable system;
stable = pkgsFrom inputs.stable system;
};
};

# NixOS and nix-darwin base environment.systemPackages
basePackagesFor = pkgs: builtins.attrValues {
inherit (pkgs)
vim
curl
fd
man-pages-posix
wget
git;

home-manager = inputs'.home.packages.home-manager.override { path = "${inputs.home}"; };
};
};
};
}
78 changes: 78 additions & 0 deletions modules/parts/home.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{ config, lib, inputs, withSystem, ... }:

let
inherit lib;
inherit (lib) types;

cfg = config.parts.homeConfigurations;
configurations = builtins.mapAttrs (_: value: value._home) cfg;

homeOpts = opts@{ config, lib, name, ... }: {
options = {
system = lib.mkOption {
type = types.enum [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];

description = "System architecture for the configuration.";
};

stateVersion = lib.mkOption {
type = types.str;
description = "home-manager state version, changing this value DOES NOT update your config.";
};

modules = lib.mkOption {
type = types.listOf types.unspecified;
description = "List of home-manager modules to include in the configuration.";
};

_home = lib.mkOption {
type = types.unspecified;
readOnly = true;
description = "Composed home-manager configuration.";
};
};

config._home = withSystem config.system (ctx:
inputs.home.lib.homeManagerConfiguration {
# Default nixpkgs for home.nix
pkgs = inputs.nixpkgs.legacyPackages.${ctx.system};

modules = config.modules ++ [
inputs.nix-index-database.hmModules.nix-index

({ config, lib, pkgs, ... }: {
_module.args = ctx.extraModuleArgs;
nixpkgs = removeAttrs ctx.nixpkgs [ "hostPlatform" ];

home = {
username = builtins.elemAt (lib.strings.split "@" name) 0;
inherit (opts.config) stateVersion;

packages = builtins.attrValues {
inherit (pkgs)
hello;
};

homeDirectory = lib.mkMerge [
(lib.mkIf pkgs.stdenv.isDarwin "/Users/${config.home.username}")
(lib.mkIf pkgs.stdenv.isLinux "/home/${config.home.username}")
];
};
})
];
}
);
};
in
{
options.parts.homeConfigurations = lib.mkOption {
type = types.attrsOf (types.submodule homeOpts);
};

config.flake.homeConfigurations = configurations;
}
61 changes: 61 additions & 0 deletions modules/parts/nix.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{ lib, stdenv, inputs, inputs' }:

{
configureBuildUsers = true;

nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];

registry = {
system.flake = inputs.self;
default.flake = inputs.nixpkgs;
home-manager.flake = inputs.home;
};

settings = {
max-jobs = "auto";
auto-optimise-store = true;
accept-flake-config = true;

experimental-features = [
"auto-allocate-uids"
"ca-derivations"
"flakes"
"nix-command"
];

trusted-users = [ "r17" "nixos" "root" ];

trusted-substituters = [
"https://cache.komunix.org"
"https://nix-community.cachix.org"
"https://r17.cachix.org/"
"https://efishery.cachix.org"
];

trusted-public-keys = [
"efishery.cachix.org-1:ix7pi358GsGkH7oBTmKGkVj42yBcjxRPi6IQ9AbRc0o="
"r17.cachix.org-1:vz0nG6BCbdgTPn7SEiOwe/3QwvjH1sb/VV9WLcBtkAY="
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
} // (lib.optionalAttrs (stdenv.isDarwin && stdenv.isAarch64) {
extra-platforms = "x86_64-darwin aarch64-darwin";
});


# enable garbage-collection on weekly and delete-older-than 30 day
gc = {
automatic = true;
options = "--delete-older-than 30d";
};

# this is configuration for /etc/nix/nix.conf
# so it will generated /etc/nix/nix.conf
extraOptions = ''
keep-outputs = true
keep-derivations = true
auto-allocate-uids = false
builders-use-substitutes = true
http-connections = 0
'';
}
5 changes: 5 additions & 0 deletions overlays/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_:

{
flake.overlays.default = final: prev: { };
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions users/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_:

{
parts.homeConfigurations = {
"r17@eR17x" = {
system = "aarch64-darwin";
stateVersion = "23.05";
};
};
}

0 comments on commit 3e81ac8

Please sign in to comment.