Skip to content

Commit

Permalink
profiles.flakes.disko: init & refactor existing config [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Lehmanator committed Feb 26, 2024
1 parent 62dff72 commit b472642
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 58 deletions.
84 changes: 27 additions & 57 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
...
}: {
packages = {
inherit (inputs.disko.packages.${system}) disko disko-doc;
firefox-gnome-theme = pkgs.callPackage ./pkgs/nixos/themes/firefox-gnome-theme.nix {};
#fajita-images = self.flake.nixosConfigurations.fajita.config.mobile.outputs.android-fastboot-images;
deploy =
nixpkgs.legacyPackages.${system}.writeText "cachix-deploy.json"
Expand All @@ -42,11 +42,6 @@
self.nixosConfigurations);
});
};
#pops.omnibus = inputs.omnibus.pops.self.addLoadExtender {
# load.inputs = {
# inputs = {nixpkgs = inputs.nixpkgs.legacyPackages.${system};};
# };
#};
};
flake = let
mkSystem = {
Expand All @@ -57,7 +52,8 @@
modules ? [],
...
} @ args:
(import ./lib/flake/lehmanatorSystem.nix {inherit inputs self;}) {
#inputs.self.lib.nixos.lehmanatorSystem {
(import ./lib/nixos/lehmanatorSystem.nix {inherit inputs self;}) {
#inputs.nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = {
Expand All @@ -67,31 +63,23 @@
# See:
# - https://nixos-and-flakes.thiscute.world/nixos-with-flakes/downgrade-or-upgrade-packages
# - https://nixos-and-flakes.thiscute.world/nixpkgs/multiple-nixpkgs
pkgs-stable = import inputs.nixpkgs-stable {
inherit system;
config.allowUnfree = true;
};
pkgs-unstable = import inputs.nixpkgs-unstable {
inherit system;
config.allowUnfree = true;
};
# stable, unstable, master, staging, staging-next
pkgs-master = import inputs.nixpkgs-master {
inherit system;
config.allowUnfree = true;
};
pkgs-staging = import inputs.nixpkgs-staging {
inherit system;
config.allowUnfree = true;
};
pkgs-staging-next = import inputs.nixpkgs-staging-next {
inherit system;
config.allowUnfree = true;
};
};
#// specialArgs;
modules = [./hosts/${host}] ++ modules;
};
in {
#lib = inputs.haumea.lib.load {
# src = ./lib;
# inputs = {
# inherit inputs self;
# inherit (inputs.nixpkgs) lib;
# };
#};
overlays = import ./overlays/nixos;
nixosConfigurations = {
fw = mkSystem {host = "fw";};
Expand Down Expand Up @@ -150,33 +138,6 @@
# };
#};

#pops = {
# nixosModules = inputs.omnibus.pops.nixosModules.addLoadExtender {
# load = {src = ./modules/nixos;};
# };
# nixosProfiles = inputs.omnibus.pops.nixosProfiles.addLoadExtender {
# load = {
# src = ./profiles/nixos;
# inputs = {inherit inputs;};
# };
# };
# homeModules = inputs.omnibus.pops.homeProfiles.addLoadExtender {
# load = {
# src = ./modules/nixos;
# inputs = {inherit inputs;};
# };
# };
# homeProfiles = inputs.omnibus.pops.homeProfiles.addLoadExtender {
# load = {
# src = ./profiles/hm;
# inputs = {inherit inputs;};
# };
# };
# #omnibus = forAllSystems (system:
# # inputs.omnibus.pops.self.addLoadExtender {
# # load.inputs = { inputs = {nixpkgs = inputs.nixpkgs.legacyPackages.${system};}; };
# #});
#};
};
};

Expand Down Expand Up @@ -289,6 +250,10 @@
std.url = "github:divnix/std";
hive.url = "github:divnix/hive";
omnibus.url = "github:GTrunSec/omnibus";
haumea = {
url = "github:nix-community/haumea";
inputs.nixpkgs.follows = "nixpkgs";
};

# --- Libs: Packaging ------------------------------------------
nixpak.url = "github:nixpak/nixpak";
Expand Down Expand Up @@ -317,23 +282,28 @@
# --- Modules: Flake-parts -------------------------------------
flake-parts.url = "github:hercules-ci/flake-parts";
agenix-shell.url = "github:aciceri/agenix-shell";
#treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
devenv.url = "github:cachix/devenv";
devshell.url = "github:numtide/devshell";
#devshell.inputs.nixpkgs.follows = "nixpkgs";
dream2nix.url = "github:nix-community/dream2nix";
emanote.url = "github:srid/emanote";
ez-configs.url = "github:ehllie/ez-configs";
flake-parts-website.url = "github:hercules-ci/flake.parts-website";

# https://github.com/srid/nixos-flake
flake-root.url = "github:srid/flake-root";
nixid.url = "github:srid/nixid";
treefmt-nix.url = "github:numtide/treefmt-nix";
#treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
devshell.url = "github:numtide/devshell";
#devshell.inputs.nixpkgs.follows = "nixpkgs";
devenv.url = "github:cachix/devenv";
haskell-flake.url = "github:srid/haskell-flake";
hercules-ci-effects.url = "github:hercules-ci/hercules-ci-effects";
mission-control.url = "github:Platonic-Systems/mission-control";
nixid.url = "github:srid/nixid";
nix-cargo-integration.url = "github:yusdacra/nix-cargo-integration";
ocaml-flake.url = "github:9glenda/ocaml-flake";
pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix";
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
proc-flake.url = "github:srid/proc-flake";
pydev.url = "github:oceansprint/pydev";
treefmt-nix.url = "github:numtide/treefmt-nix";


# --- Modules: System ------------------------------------------
nixos-hardware.url = "github:NixOS/nixos-hardware";
Expand Down
File renamed without changes.
17 changes: 16 additions & 1 deletion profiles/flakes/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
inputs,
...
}: {
}:
{
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.hercules-ci-effects.flakeModule
Expand All @@ -13,6 +14,7 @@
./agenix-shell.nix
#./devenv.nix
./devshell.nix
./disko
#./easyOverlay.nix
#./ez-configs.nix
./emanote.nix
Expand All @@ -27,4 +29,17 @@
#./std.nix
./treefmt.nix
];

perSystem = {config, lib, pkgs, system, ...}:
let
inherit (inputs.haumea.lib) load;
in
{
#lib = load {
# src = ../../lib;
# loader =
#};
};
flake = {
};
}
40 changes: 40 additions & 0 deletions profiles/flakes/disko/configurations/wyse.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ inputs, ... }: {
disko.devices = {
nodev."/" = { fsType = "tmpfs"; mountOptions = [ "defaults" "size=8G" "mode=755" ]; };
disk.main = {
type = "disk";
device = "/dev/nvme0n1";
content = {
type = "gpt";
partitions = {
ESP = {
size = "1024M";
type = "EF00";
content = { mountpoint = "/boot"; mountOptions = [ "defaults" ]; format = "vfat"; type = "filesystem"; };
};
luks = {
size = "100%";
content = {
type = "luks";
name = "crypted";
askPassword = true;
settings.allowDiscards = true;
content = {
type = "btrfs";
extraArgs = [ "-f" ];
subvolumes = {
"/nix" = { mountpoint = "/nix"; mountOptions = [ "compress=zstd" "noatime" ]; };
"/persist" = { mountpoint = "/nix/persist"; mountOptions = [ "compress=zstd" "noatime" "noexec" ]; };
"/home" = { mountpoint = "/home"; mountOptions = [ "compress=zstd" "noatime" ]; };
# https://git.dblsaiko.net/systems/tree/configurations/invader/swap.nix
"/swap" = { mountpoint = "/nix/swap"; swap.swapfile.size = "32G"; };
"/var" = { mountpoint = "/var"; mountOptions = [ "default" ]; };
};
};
};
};
};
};
};
};
}
141 changes: 141 additions & 0 deletions profiles/flakes/disko/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{inputs, self, ...}:
let
inherit (inputs.haumea.lib) load loaders matchers transformers;
in
{
# Disko: systems=["aarch64-linux" "i686-linux" "riscv64-linux" "x86_64-linux"];
perSystem = {config, lib, pkgs, system, ...}:
let
inherit (inputs.disko.lib) makeDiskImages makeDiskImagesScript create mount;
inherit (inputs.disko.packages.${system}) disko disko-doc;
in
{
packages = {
# Make disko CLI & documentation available in flake outputs.
inherit disko disko-doc;

# Script to create new diskoConfiguration from existing / profiles.

# Packages to build disk images for nixosConfigurations
# TODO: Map diskoConfigurations.* to makeDiskImages

# Packages to write scripts to build disk images for nixosConfigurations
# TODO: Map diskoConfigurations.* to makeDiskImagesScript
};

# Extend NixOS devshell with config from disko devshell.
#devshells.nixos = lib.recursiveMerge config.devshells.nixos config.devshells.disko;

devshells.disko = {
packages = [disko-doc];
env = [ {name="BROWSER"; value = "firefox"; } ]; # TODO: Remove
commands = [
{name="disko-docs"; category="disko-info"; help="Display disko documentation"; command = "$BROWSER ${disko-doc}/index.html";}
{name="disko-help"; category="disko-info"; help="Show helptext for disko command"; command="${disko}/bin/disko --help";}
{name="disko"; category="disko"; help="Unmount & destroy all filesystems on the disks we want to format, then run the create & mount mode"; command="${disko}/bin/disko --mode disko --flake";}
{name="disko-format"; category="disko"; help="Create partition tables, zpools, LVMs, RAIDs, & filesystems."; command="${disko}/bin/disko --mode format --flake";}
{name="disko-mount"; category="disko"; help="Mount the partition at the specified root-mountpoint"; command="${disko}/bin/disko --mode mount --flake";}

# { # Build disk image for current system.
# name = "makeDiskImage";
# category = "disko";
# help = "Build your NixOS disk image";
# command = "${config.lib.makeDiskImages} ${config.diskoConfigurations.$(hostname)}";
# }
# TODO: Open nix-community/disko
# TODO: List diskoConfigurations
# TODO: List diskoProfiles
# TODO: List /dev/{nvme0n,sd,vd}*
# TODO: List /dev/disks/by-*/*
# TODO: Init template from examples
# TODO: Init template from existing config/profile
];
};
};

flake = {
lib.disko = { inherit (inputs.disko) lib; };

# Flake output for partial disk configurations.
# NOTE: Requires data from nixosConfigurations.<host> to fully evaluate.
# TODO: Custom transformer using lib.evalModules
diskoProfiles = load {
src = ./profiles;
inputs = {
inherit inputs;
lib = inputs.nixpkgs.lib; #pkgs;
};
};

# Flake output for complete disk configurations
# NOTE: Should be finalized disk configs that fully evaluate.
diskoConfigurations = load {
src = ./configurations;
#transformer = ; # TODO: Use lib.evalModules to
inputs = {
inherit inputs;
lib = inputs.nixpkgs.lib; #pkgs;
};
};

# NixOS module to specify data related to disk configuration.
# - Disk Paths:
# - /dev/disk/by-{diskseq, id, partuuid, path, uuid}
# - /dev/nvme0n<num>
# - /dev/{sd,vd}<letter>
# - Tmpfs Options: isTmpfsRoot, isTmpfsHome,
# - Swap Options: hasSwap, hasSwapPartition, hasSwapFile
# TODO: Override/extend original disko nixosModule?
#nixosModules = {
# disks = ({config, lib, pkgs, ...}: let cfg = config.disks; in {
# imports = [../../modules/disko];
# options.disks = {};
# config = lib.mkIf config.disko.enable {
# disks = { system = { }; home = { }; };
# tmpfs = lib.mkOption {
# type = lib.types.bool;
# default = false;
# description = "Whether disk should use a tmpfs root";
# example = true;
# };
# };
# };
#};

# NixOS profiles that configure NixOS to use disko
# NixOS profiles to optionally use some disko layout
nixosProfiles = with inputs.self.packages; {
disko-base = ({config, lib, pkgs, ... }: with config.networking; let
inherit (inputs.self.packages.${pkgs.system}) disko disko-doc;
in {
# TODO: Import diskoConfigurations.${hostName} only if it exists
imports = [inputs.disko.nixosModules.disko];
disko = (inputs.self.diskoConfigurations.${hostName} {inherit inputs config lib pkgs;}) // { enableConfig = lib.mkDefault true; };
environment.systemPackages = [disko disko-doc];
services.nginx.virtualHosts = let
locations = { "/disko".root = "${disko}/index.html"; };
in { # Add disko-doc to webserver
localhost = {inherit locations;};
"nixos-docs.${fqdn}" = lib.mkIf (domain!="" && domain!=null) {inherit locations;};
};
});

# Profile to run only in installer
disko-installer = ({config, lib, pkgs, ...}: {
imports = [config.nixosProfiles.disko-base];
disko.enableConfig = lib.mkImageMediaOverride false;
});

disko-tmpfs-root = ({config, lib, pkgs, ...}: {
imports = [
config.nixosProfiles.disko-base
config.diskoProfiles.tmpfs-root
inputs.impermanence.nixosModules.impermanence
];
});

};

};

}
19 changes: 19 additions & 0 deletions profiles/flakes/disko/profiles/btrfs-luks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ inputs, ... }: {
#imports = [];
disko.devices.disk.main.content.partitions.luks.content.content = {
type = "btrfs";
extraArgs = ["-f"];
subvolumes = {
"/nix" = { mountpoint = "/nix"; mountOptions = [ "compress=zstd" "noatime" ]; };
"/persist" = { mountpoint = "/nix/persist"; mountOptions = [ "compress=zstd" "noatime" "noexec" ]; };
"/var" = { mountpoint = "/var"; mountOptions = [ "default" ]; };

# https://git.dblsaiko.net/systems/tree/configurations/invader/swap.nix
# TODO: Conditional if swap enabled on system.
"/swap" = { mountpoint = "/nix/swap"; swap.swapfile.size = "32G"; };

# TODO: Conditional if home in system or separate partition.
"/home" = { mountpoint = "/home"; mountOptions = [ "compress=zstd" "noatime" ]; };
};
};
}
Loading

0 comments on commit b472642

Please sign in to comment.