Compare commits

..

No commits in common. "865bffa641925c559f31ef293efe42ff11be9062" and "7b9d9053bff3daec81e2afebbb4f089341abb368" have entirely different histories.

13 changed files with 121 additions and 160 deletions

View file

@ -17,26 +17,17 @@ let
in in
{ {
config = { config = {
boot = { # UEFI works here, and variables can be touched
# From nixos-generate-config boot.loader = {
initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usbhid" "sd_mod" "rtsx_usb_sdmmc" ]; efi.canTouchEfiVariables = lib.mkDefault true;
kernelModules = [ "kvm-intel" ]; grub = {
enable = true;
# UEFI works here, and variables can be touched efiSupport = true;
loader = { device = "nodev"; # Don't install on MBR
efi.canTouchEfiVariables = lib.mkDefault true; # TODO Maybe we could? In case the HDD doesn't boot anymore?
grub = {
enable = true;
efiSupport = true;
device = "nodev"; # Don't install on MBR
# TODO Maybe we could? In case the HDD doesn't boot anymore?
};
}; };
}; };
# Also from nixos-generate-config hardware.cpu.intel.updateMicrocode = true;
hardware.enableRedistributableFirmware = true;
# TODO Do we really need that? Besides maybe microcode?
frogeye.desktop = { frogeye.desktop = {
x11_screens = [ x11_screens = [
displays.deskLeft.output displays.deskLeft.output
@ -44,23 +35,11 @@ in
]; ];
maxVideoHeight = 1440; maxVideoHeight = 1440;
numlock = true; numlock = true;
phasesCommands = { phasesBrightness = {
jour = '' enable = true;
${pkgs.brightnessctl}/bin/brightnessctl set 40000 & jour = "40000";
${pkgs.ddcutil}/bin/ddcutil setvcp 10 20 -d 1 & crepuscule = "10000";
${pkgs.ddcutil}/bin/ddcutil setvcp 10 20 -d 2 & nuit = "1";
'';
crepuscule = ''
${pkgs.brightnessctl}/bin/brightnessctl set 10000 &
${pkgs.ddcutil}/bin/ddcutil setvcp 10 10 -d 1 &
${pkgs.ddcutil}/bin/ddcutil setvcp 10 10 -d 2 &
'';
nuit = ''
${pkgs.brightnessctl}/bin/brightnessctl set 1 &
${pkgs.ddcutil}/bin/ddcutil setvcp 10 0 -d 1 &
${pkgs.ddcutil}/bin/ddcutil setvcp 10 0 -d 2 &
'';
# TODO Display 2 doesn't work anymore?
}; };
}; };
nixpkgs.overlays = [ nixpkgs.overlays = [

View file

@ -80,6 +80,10 @@
type = "app"; type = "app";
program = "${disko.packages.${system}.default}/bin/disko"; program = "${disko.packages.${system}.default}/bin/disko";
}; };
nixos-generate-config = {
type = "app";
program = "${pkgs.nixos-install-tools}/bin/nixos-generate-config";
};
nixos-install = { nixos-install = {
type = "app"; type = "app";
program = "${pkgs.nixos-install-tools}/bin/nixos-install"; program = "${pkgs.nixos-install-tools}/bin/nixos-install";
@ -94,19 +98,6 @@
${pkgs.lix}/bin/nix repl --expr 'let flake = builtins.getFlake "${self}"; in flake // flake.nixosConfigurations // rec { pkgs = import ${nixpkgs} {}; lib = pkgs.lib; }' ${pkgs.lix}/bin/nix repl --expr 'let flake = builtins.getFlake "${self}"; in flake // flake.nixosConfigurations // rec { pkgs = import ${nixpkgs} {}; lib = pkgs.lib; }'
''}"; ''}";
}; };
updateLocalFlakes = {
type = "app";
program = "${pkgs.writers.writePython3 "update-local-flakes" { }
(builtins.readFile ./common/update-local-flakes.py)}";
};
nixosRebuild = {
type = "app";
program = "${pkgs.writeShellScript "rebuild" ''${pkgs.writeShellApplication {
name = "rebuild";
runtimeInputs = with pkgs; [ nix-output-monitor nixos-rebuild ];
text = builtins.readFile ./os/rebuild.sh;
}}/bin/rebuild ${self} "$@"''}";
};
}; };
} }
); );

View file

@ -2,23 +2,31 @@
{ pkgs, lib, config, ... }: { pkgs, lib, config, ... }:
let let
phases = [ phases = [
{ command = "jour"; specialisation = null; } { command = "jour"; polarity = "light"; }
{ command = "crepuscule"; specialisation = "dark"; } { command = "crepuscule"; polarity = "dark"; }
{ command = "nuit"; specialisation = "dark"; } { command = "nuit"; polarity = "dark"; }
]; ];
phasesBrightness = config.frogeye.desktop.phasesBrightness;
in in
{ {
config = { config = {
home.packages = map home.packages = map
(phase: (pkgs.writeShellScriptBin phase.command '' (phase: (pkgs.writeShellApplication {
switch="/nix/var/nix/profiles/system${lib.strings.optionalString (phase.specialisation != null) "/specialisation/${phase.specialisation}"}/bin/switch-to-configuration" name = "${phase.command}";
if [ -x "$switch" ] runtimeInputs = [ pkgs.brightnessctl ];
then text = (lib.optionalString phasesBrightness.enable ''
sudo "$switch" test & brightnessctl set ${builtins.getAttr phase.command phasesBrightness}
sudo "$switch" boot & '') + ''
fi switch="/nix/var/nix/profiles/system/specialisation/${phase.polarity}/bin/switch-to-configuration"
${builtins.getAttr phase.command config.frogeye.desktop.phasesCommands} if [ -x "$switch" ]
'')) then
# In two steps to get the visual changes slightly earlier
sudo "$switch" test
sudo "$switch" boot
fi
'';
})
)
phases; phases;
xsession.windowManager.i3.config.keybindings = { xsession.windowManager.i3.config.keybindings = {
"XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set +5%"; "XF86MonBrightnessUp" = "exec ${pkgs.brightnessctl}/bin/brightnessctl set +5%";

View file

@ -1,4 +1,8 @@
{ pkgs, config, ... }: { pkgs, config, ... }:
let
ulf = pkgs.writers.writePython3 "update-local-flakes" {
} (builtins.readFile ./update-local-flakes.py);
in
{ {
home.packages = [ home.packages = [
(pkgs.writeShellApplication { (pkgs.writeShellApplication {
@ -10,26 +14,32 @@
verb="$1" verb="$1"
shift shift
fi fi
nixos_flake="$(readlink -f /etc/nixos)" nixos_flake="/etc/nixos/flake.nix"
if [ -f "$nixos_flake/flake.nix" ] if [ -f "$nixos_flake" ]
then then
nix run "$nixos_flake#updateLocalFlakes" -- "$nixos_flake" sudo ${ulf} "$nixos_flake"
nix run "$nixos_flake#nixosRebuild" -- "$verb" "$@" # ${pkgs.nix-output-monitor}/bin/nom build "$(dirname "$nixos_flake")#nixosConfigurations.$HOSTNAME.config.system.build.toplevel"
if [ "$verb" = "switch" ] || [ "$verb" = "test" ]
then
sudo nixos-rebuild "$verb" --specialisation ${config.frogeye.polarity} "$@"
else
sudo nixos-rebuild "$verb" "$@"
fi
fi
hm_flake="${config.xdg.configHome}/home-manager/flake.nix"
if [ -f "$hm_flake" ]
then
${ulf} "$hm_flake"
home-manager "$verb" "$@"
fi
nod_flake="${config.xdg.configHome}/nix-on-droid/flake.nix"
if [ -f "$nod_flake" ]
then
${ulf} "$nod_flake"
nix-on-droid "$verb" --flake "$(dirname "$nod_flake")" "$@"
fi fi
# TODO Fix nix-on-droid and home-manager
# hm_flake="${config.xdg.configHome}/home-manager/flake.nix"
# if [ -f "$hm_flake" ]
# then
# {ulf} "$hm_flake"
# home-manager "$verb" "$@"
# fi
# nod_flake="${config.xdg.configHome}/nix-on-droid/flake.nix"
# if [ -f "$nod_flake" ]
# then
# {ulf} "$nod_flake"
# nix-on-droid "$verb" --flake "$(dirname "$nod_flake")" "$@"
# fi
''; '';
}) })
]; ];
} }
# TODO make it a flake application, optional nom (is slow), test then boot, flags to confirm each, nvd diff here

View file

@ -12,14 +12,13 @@ GET_INPUTS_CMD = [
] ]
def process_flake(flakeUri: str) -> None: def process_flake(flake: str) -> None:
# get full path # get full path
flakeUri = os.path.normpath(flakeUri) if not os.path.isfile(flake):
flakeFile = os.path.join(flakeUri, "flake.nix") raise FileNotFoundError(f"Flake not found: {flake}")
if not os.path.isfile(flakeFile): dir = os.path.dirname(flake)
raise FileNotFoundError(f"Flake not found: {flakeUri}")
# import dependencies # import dependencies
p = subprocess.run(GET_INPUTS_CMD, cwd=flakeUri, stdout=subprocess.PIPE) p = subprocess.run(GET_INPUTS_CMD, cwd=dir, stdout=subprocess.PIPE)
deps = json.loads(p.stdout) deps = json.loads(p.stdout)
p.check_returncode() p.check_returncode()
# for each dependency # for each dependency
@ -35,8 +34,11 @@ def process_flake(flakeUri: str) -> None:
# get flake file corresponding # get flake file corresponding
dep_path = dep_url.split(":")[1] dep_path = dep_url.split(":")[1]
if not dep_path.startswith("/"): if not dep_path.startswith("/"):
dep_path = os.path.join(flakeUri, dep_path) dep_path = os.path.join(dir, dep_path)
process_flake(dep_path) dep_path = os.path.normpath(dep_path)
dep_flake = os.path.join(dep_path, "flake.nix")
# call this function with the flake file
process_flake(dep_flake)
# update lockfile # update lockfile
cmd = [ cmd = [
"nix", "nix",
@ -48,7 +50,7 @@ def process_flake(flakeUri: str) -> None:
"update", "update",
dep_name, dep_name,
] ]
p = subprocess.run(cmd, cwd=flakeUri) p = subprocess.run(cmd, cwd=dir)
p.check_returncode() p.check_returncode()
@ -57,6 +59,6 @@ if __name__ == "__main__":
description="Recursively update lockfiles " description="Recursively update lockfiles "
"of flakes located on the system" "of flakes located on the system"
) )
parser.add_argument("flake", help="Starting flake", default="/") parser.add_argument("flake", help="Starting flake", default="flake.nix")
args = parser.parse_args() args = parser.parse_args()
process_flake(args.flake) process_flake(args.flake)

View file

@ -82,9 +82,24 @@ sudo nix --extra-experimental-features "nix-command flakes" run "${SCRIPT_DIR}#d
trap - ERR trap - ERR
rm "$luks_pass_file" rm "$luks_pass_file"
# Save that system configuration uses this repo # Generate hardware-config.nix
sudo mkdir -p "${mountpoint}/etc" sudo nix --extra-experimental-features "nix-command flakes" run "${SCRIPT_DIR}#nixos-generate-config" -- --no-filesystems --root "$mountpoint"
sudo ln -sfn "${flake_uri}" "${mountpoint}/nixos" # --no-filesystems because they are imported via disko
sudo rm "$mountpoint/etc/nixos/configuration.nix"
# Plug system configuration into this git repo
sudo mkdir -p "${mountpoint}/etc/nixos"
echo "{
description = \"$name system config\";
inputs.entrypoint.url = \"git+file:$flake_uri\";
outputs = { self, entrypoint, ... }:
{
nixosConfigurations.$name = entrypoint.nixosConfigurations.$name.extendModules {
modules = [ ./hardware-configuration.nix ];
};
};
}" | sudo tee "${mountpoint}/etc/nixos/flake.nix" > /dev/null
# Everything there should be covered by (and conflicts with) the repo anyways.
# Install NixOS! Or create a new generation. # Install NixOS! Or create a new generation.
sudo nix --extra-experimental-features "nix-command flakes" run "${SCRIPT_DIR}#nixos-install" -- --no-root-password --root "$mountpoint" --flake "${mountpoint}/etc/nixos#${name}" sudo nix --extra-experimental-features "nix-command flakes" run "${SCRIPT_DIR}#nixos-install" -- --no-root-password --root "$mountpoint" --flake "${mountpoint}/etc/nixos#${name}"

View file

@ -22,10 +22,11 @@
description = "Maximum video height in pixel the machine can reasonably watch"; description = "Maximum video height in pixel the machine can reasonably watch";
default = 1080; default = 1080;
}; };
phasesCommands = { phasesBrightness = {
jour = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: jour"; }; enable = lib.mkEnableOption "Set a specific brightness for the screen when running phases commands";
crepuscule = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: crepuscule"; }; jour = lib.mkOption { type = lib.types.str; default = "100%"; description = "brightnessctl value for phase: jour"; };
nuit = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: nuit"; }; crepuscule = lib.mkOption { type = lib.types.str; default = "50%"; description = "brightnessctl value for phase: crepuscule"; };
nuit = lib.mkOption { type = lib.types.str; default = "1%"; description = "brightnessctl value for phase: nuit"; };
}; };
}; };
dev = { dev = {

View file

@ -9,6 +9,7 @@
./common.nix ./common.nix
./desktop ./desktop
./dev ./dev
./diff
disko.nixosModules.disko disko.nixosModules.disko
./gaming ./gaming
./geoffrey.nix ./geoffrey.nix

View file

@ -1,11 +1,9 @@
{ pkgs, lib, config, ... }: { pkgs, lib, config, ... }:
{ {
config = lib.mkIf config.frogeye.desktop.xorg { config = lib.mkIf config.frogeye.desktop.xorg {
boot.kernelModules = [ "i2c-dev" ]; # Allows using ddcutil
services = { services = {
blueman.enable = true; blueman.enable = true;
displayManager.defaultSession = "none+i3"; displayManager.defaultSession = "none+i3";
udev.packages = with pkgs; [ ddcutil ]; # TODO Doesn't seem to help
xserver = { xserver = {
enable = true; enable = true;
windowManager.i3.enable = true; windowManager.i3.enable = true;

14
os/diff/default.nix Normal file
View file

@ -0,0 +1,14 @@
{ pkgs, lib, config, ... }:
{
config = {
system.activationScripts.diff = {
supportsDryActivation = true;
text = ''
if [ -h /run/current-system ]
then
${pkgs.nvd}/bin/nvd --nix-bin-dir=${pkgs.nix}/bin diff /run/current-system "$systemConfig"
fi
'';
};
};
}

View file

@ -34,6 +34,7 @@
specialisation = { specialisation = {
dark.configuration.frogeye.polarity = "dark"; dark.configuration.frogeye.polarity = "dark";
light.configuration.frogeye.polarity = "light";
}; };
# Fix https://nix-community.github.io/home-manager/index.html#_why_do_i_get_an_error_message_about_literal_ca_desrt_dconf_literal_or_literal_dconf_service_literal # Fix https://nix-community.github.io/home-manager/index.html#_why_do_i_get_an_error_message_about_literal_ca_desrt_dconf_literal_or_literal_dconf_service_literal

View file

@ -1,54 +0,0 @@
# Handle arguments
self="$1"
verb="$2"
shift
shift
if [ "$verb" != "build" ] && [ "$verb" != "test" ] && [ "$verb" != "boot" ] && [ "$verb" != "switch" ] && [ "$verb" != "confirm" ]
then
echo "Action should be one of: build, test, boot, switch, confirm"
exit 2
fi
# Build, looking nice
tmpdir="$(mktemp -d)"
# sudo so the eval cache is shared with nixos-rebuild
sudo nom build "$self#nixosConfigurations.$HOSTNAME.config.system.build.toplevel" -o "$tmpdir/toplevel" "$@"
toplevel="$(readlink "$tmpdir/toplevel")"
rm -rf "$tmpdir"
# Show diff
nvd diff /nix/var/nix/profiles/system "$toplevel"
# Figure out specialisation
specialisationArgs=""
currentSystem="$(readlink /run/current-system)"
while read -r specialisation
do
if [ "$(readlink "/nix/var/nix/profiles/system/specialisation/$specialisation")" = "$currentSystem" ]
then
specialisationArgs=("--specialisation" "$specialisation")
fi
done <<< "$(ls /nix/var/nix/profiles/system/specialisation)"
# Apply
if [ "$verb" = "confirm" ]
then
echo "Apply configuration? [y/N]"
read -r confirm
fi
if [ "$verb" = "test" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
then
sudo nixos-rebuild --flake "$self#$HOSTNAME" test "${specialisationArgs[@]}" "$@"
fi
# Set as boot
if [ "$verb" = "confirm" ]
then
echo "Set configuration as boot? [y/N]"
read -r confirm
fi
if [ "$verb" = "boot" ] || [ "$verb" = "switch" ] || [ "$confirm" = "y" ]
then
sudo nixos-rebuild --flake "$self#$HOSTNAME" boot "$@"
fi

View file

@ -16,16 +16,11 @@
frogeye.desktop = { frogeye.desktop = {
x11_screens = [ "DP-1" "eDP-1" ]; x11_screens = [ "DP-1" "eDP-1" ];
maxVideoHeight = 1080; maxVideoHeight = 1080;
phasesCommands = { phasesBrightness = {
jour = '' enable = true;
${pkgs.brightnessctl}/bin/brightnessctl set 3500 jour = "3500";
''; crepuscule = "3000";
crepuscule = '' nuit = "700";
${pkgs.brightnessctl}/bin/brightnessctl set 3000
'';
nuit = ''
${pkgs.brightnessctl}/bin/brightnessctl set 700
'';
}; };
}; };