2023-04-13 19:21:12 +02:00
|
|
|
{
|
|
|
|
description = "NixOS system flake";
|
|
|
|
|
2023-04-14 01:56:52 +02:00
|
|
|
inputs = {
|
2024-06-11 07:36:07 +02:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
|
2023-04-13 19:57:56 +02:00
|
|
|
nixos-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
|
2023-04-13 20:34:56 +02:00
|
|
|
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
|
2023-04-13 21:30:17 +02:00
|
|
|
home-manager = {
|
2024-06-11 07:36:07 +02:00
|
|
|
url = "github:nix-community/home-manager/release-24.05";
|
2023-04-13 21:30:17 +02:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-08-17 17:26:57 +02:00
|
|
|
lanzaboote = {
|
|
|
|
url = "github:nix-community/lanzaboote/v0.3.0";
|
|
|
|
# deliberately do _not_ follow the nixpkgs input here, because paranoia and test coverage
|
|
|
|
};
|
2024-01-09 23:48:38 +01:00
|
|
|
utils.url = "github:numtide/flake-utils";
|
2024-03-16 17:14:33 +01:00
|
|
|
treefmt-nix = {
|
|
|
|
url = "github:numtide/treefmt-nix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2024-03-18 11:49:35 +01:00
|
|
|
nix-darwin = {
|
|
|
|
url = "github:LnL7/nix-darwin";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-08-17 17:26:57 +02:00
|
|
|
|
2024-03-16 17:18:20 +01:00
|
|
|
nur.url = "github:nix-community/NUR";
|
2023-04-14 01:56:52 +02:00
|
|
|
# TODO: possible make this a flake as well
|
|
|
|
mysecrets = {
|
|
|
|
flake = false;
|
|
|
|
url = "git+ssh://gitea@git.orlives.de:2342/schmittlauch/home-manager_secrets.git";
|
|
|
|
};
|
2023-04-13 19:21:12 +02:00
|
|
|
};
|
|
|
|
|
2024-03-16 17:18:20 +01:00
|
|
|
outputs =
|
|
|
|
{
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
nur,
|
|
|
|
lanzaboote,
|
|
|
|
utils,
|
|
|
|
home-manager,
|
|
|
|
treefmt-nix,
|
2024-03-18 11:49:35 +01:00
|
|
|
nix-darwin,
|
2024-03-16 17:18:20 +01:00
|
|
|
...
|
|
|
|
}@inputs:
|
|
|
|
let
|
|
|
|
# FIXME: allow different systems
|
|
|
|
systems = utils.lib.system;
|
|
|
|
# necessary to make the top-level inputs available to system configuration
|
|
|
|
# inspired by https://jade.fyi/blog/flakes-arent-real/
|
|
|
|
inputInjection =
|
|
|
|
{ pkgs, lib, ... }:
|
2023-04-14 01:56:52 +02:00
|
|
|
{
|
2024-03-16 17:18:20 +01:00
|
|
|
options.inputInjection = lib.mkOption {
|
|
|
|
type = with lib.types; attrsOf unspecified;
|
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
config.inputInjection = {
|
|
|
|
flake-inputs = inputs;
|
|
|
|
};
|
|
|
|
};
|
2024-08-07 00:32:03 +02:00
|
|
|
defaultModules = system: [
|
|
|
|
inputInjection
|
|
|
|
|
|
|
|
# for some reason, `imports`-ing the home-manager module via inputInjection
|
|
|
|
# from a sub-module causes infinite recursion, so importing it here instead
|
|
|
|
home-manager.nixosModules.home-manager
|
|
|
|
];
|
2024-03-16 17:18:20 +01:00
|
|
|
mkSystem =
|
|
|
|
system: extraModules:
|
|
|
|
nixpkgs.lib.nixosSystem rec {
|
|
|
|
modules = (defaultModules system) ++ extraModules;
|
|
|
|
inherit system;
|
|
|
|
specialArgs = {
|
|
|
|
inherit system;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
mkHomeManager =
|
|
|
|
confName: user: system: # unfortunately, home-manager configs are still system-specific
|
|
|
|
home-manager.lib.homeManagerConfiguration {
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
modules = [
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
nur.hmModules.nur
|
2024-03-17 19:18:53 +01:00
|
|
|
./home/common.nix
|
|
|
|
./home/${confName}.nix
|
2024-03-16 17:18:20 +01:00
|
|
|
];
|
|
|
|
# extends the home config
|
|
|
|
home.username = user;
|
|
|
|
}
|
2023-04-14 01:56:52 +02:00
|
|
|
];
|
2024-03-16 17:18:20 +01:00
|
|
|
# Optionally use extraSpecialArgs
|
|
|
|
# to pass through arguments to home.nix
|
|
|
|
extraSpecialArgs = {
|
|
|
|
inherit inputs system;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
treefmtConf =
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
projectRootFile = "flake.nix";
|
|
|
|
programs.nixfmt-rfc-style.enable = true;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
overlays.default = import ./packages;
|
|
|
|
nixosConfigurations = {
|
|
|
|
thinknix = mkSystem systems.x86_64-linux [
|
|
|
|
./hosts/thinknix
|
|
|
|
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-t440s
|
|
|
|
lanzaboote.nixosModules.lanzaboote
|
|
|
|
];
|
|
|
|
framenix = mkSystem systems.x86_64-linux [
|
|
|
|
./hosts/framenix
|
|
|
|
inputs.nixos-hardware.nixosModules.framework-13-7040-amd
|
|
|
|
lanzaboote.nixosModules.lanzaboote
|
|
|
|
];
|
2024-02-12 19:12:47 +01:00
|
|
|
};
|
2024-03-18 11:49:35 +01:00
|
|
|
darwinConfigurations."OS-MacBook-Pro" = nix-darwin.lib.darwinSystem {
|
2024-04-07 02:09:46 +02:00
|
|
|
modules = [
|
|
|
|
./darwin/configuration.nix
|
|
|
|
inputInjection
|
2024-08-07 00:32:03 +02:00
|
|
|
|
2024-04-07 02:09:46 +02:00
|
|
|
];
|
2024-03-18 11:49:35 +01:00
|
|
|
};
|
2024-03-17 19:18:53 +01:00
|
|
|
homeConfigurations = {
|
|
|
|
spiollinux-desktop = mkHomeManager "desktop" "spiollinux" systems.x86_64-linux;
|
|
|
|
os-workmac = mkHomeManager "workmac" "os" systems.aarch64-darwin;
|
|
|
|
};
|
|
|
|
lib = {
|
|
|
|
inherit mkHomeManager;
|
|
|
|
};
|
2024-03-16 17:18:20 +01:00
|
|
|
}
|
|
|
|
// utils.lib.eachDefaultSystem (
|
|
|
|
system:
|
|
|
|
let
|
|
|
|
nixpkgs = import inputs.nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = nixpkgs.lib.attrValues self.overlays;
|
|
|
|
};
|
|
|
|
nixpkgs_unstable = import inputs.nixos-unstable {
|
|
|
|
inherit system;
|
|
|
|
overlays = nixpkgs.lib.attrValues self.overlays;
|
|
|
|
};
|
|
|
|
pkgs = inputs.nixpkgs.legacyPackages.${system};
|
|
|
|
pkgs_unstable = inputs.nixos-unstable.legacyPackages.${system};
|
|
|
|
treefmtEval = treefmt-nix.lib.evalModule pkgs_unstable treefmtConf;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
devShells.default = pkgs.mkShell { buildInputs = [ ]; };
|
|
|
|
formatter = treefmtEval.config.build.wrapper;
|
|
|
|
checks.formatting = treefmtEval.config.build.check self;
|
|
|
|
# expose nixpkgs with overlay; TODO: figure out role of config
|
|
|
|
#legacyPackages = nixpkgs;
|
2024-03-17 19:54:46 +01:00
|
|
|
|
|
|
|
# inspired by https://github.com/Mic92/dotfiles/blob/main/home-manager/flake-module.nix
|
|
|
|
# run like: `nix run .#hm -- <action>`
|
|
|
|
apps.hm = {
|
|
|
|
type = "app";
|
|
|
|
program = "${pkgs.writeShellScriptBin "hm" ''
|
|
|
|
set -x
|
|
|
|
export PATH=${
|
|
|
|
pkgs.lib.makeBinPath [
|
|
|
|
pkgs.git
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.findutils
|
|
|
|
pkgs.nix
|
|
|
|
pkgs.jq
|
|
|
|
pkgs.unixtools.hostname
|
|
|
|
]
|
|
|
|
}
|
|
|
|
declare -A profiles=(
|
|
|
|
["framenix"]="spiollinux-desktop"
|
|
|
|
["thinknix"]="spiollinux-desktop"
|
2024-03-18 11:52:36 +01:00
|
|
|
["OS MacBook Pro"]="os-workmac"
|
2024-03-17 19:54:46 +01:00
|
|
|
)
|
|
|
|
user=$(id -un)
|
|
|
|
host=$(hostname)
|
|
|
|
if [[ -n ''${profiles["$host-$user"]} ]]; then
|
|
|
|
profile=''${profiles["$host-$user"]};
|
|
|
|
elif [[ -n ''${profiles[$host]:-} ]]; then
|
|
|
|
profile=''${profiles[$host]}
|
|
|
|
else
|
|
|
|
echo "No suitable profile found." >2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
if [[ "''${1:-}" == profile ]]; then
|
|
|
|
echo $profile
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
${
|
|
|
|
inputs.home-manager.packages.${pkgs.system}.home-manager
|
|
|
|
}/bin/home-manager --flake "${self}#$profile" "$@"
|
|
|
|
''}/bin/hm";
|
|
|
|
};
|
2024-03-16 17:18:20 +01:00
|
|
|
}
|
|
|
|
);
|
2023-04-13 19:21:12 +02:00
|
|
|
}
|