Compare commits

...

3 commits

Author SHA1 Message Date
Geoffrey Frogeye 865bffa641
phases: Allow loosen brightness setting again
Didn't manage to do what I wanted to do for some reason, but hey,
at least ddcutils is there.
2024-06-10 03:00:52 +02:00
Geoffrey Frogeye d5917b1264
Remove duplicate specialisation
Saves 16s on eval time
2024-06-10 02:21:32 +02:00
Geoffrey Frogeye 17f0ba3370
New rebuild mechanism
Put most of it as a flake app, so we can mess with it without relying on
`rb` being rebuilt. Also nom nom!
2024-06-10 02:12:59 +02:00
13 changed files with 160 additions and 121 deletions

View file

@ -12,13 +12,14 @@ GET_INPUTS_CMD = [
] ]
def process_flake(flake: str) -> None: def process_flake(flakeUri: str) -> None:
# get full path # get full path
if not os.path.isfile(flake): flakeUri = os.path.normpath(flakeUri)
raise FileNotFoundError(f"Flake not found: {flake}") flakeFile = os.path.join(flakeUri, "flake.nix")
dir = os.path.dirname(flake) if not os.path.isfile(flakeFile):
raise FileNotFoundError(f"Flake not found: {flakeUri}")
# import dependencies # import dependencies
p = subprocess.run(GET_INPUTS_CMD, cwd=dir, stdout=subprocess.PIPE) p = subprocess.run(GET_INPUTS_CMD, cwd=flakeUri, 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
@ -34,11 +35,8 @@ def process_flake(flake: 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(dir, dep_path) dep_path = os.path.join(flakeUri, dep_path)
dep_path = os.path.normpath(dep_path) process_flake(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",
@ -50,7 +48,7 @@ def process_flake(flake: str) -> None:
"update", "update",
dep_name, dep_name,
] ]
p = subprocess.run(cmd, cwd=dir) p = subprocess.run(cmd, cwd=flakeUri)
p.check_returncode() p.check_returncode()
@ -59,6 +57,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="flake.nix") parser.add_argument("flake", help="Starting flake", default="/")
args = parser.parse_args() args = parser.parse_args()
process_flake(args.flake) process_flake(args.flake)

View file

@ -17,8 +17,13 @@ let
in in
{ {
config = { config = {
boot = {
# From nixos-generate-config
initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usbhid" "sd_mod" "rtsx_usb_sdmmc" ];
kernelModules = [ "kvm-intel" ];
# UEFI works here, and variables can be touched # UEFI works here, and variables can be touched
boot.loader = { loader = {
efi.canTouchEfiVariables = lib.mkDefault true; efi.canTouchEfiVariables = lib.mkDefault true;
grub = { grub = {
enable = true; enable = true;
@ -27,7 +32,11 @@ in
# TODO Maybe we could? In case the HDD doesn't boot anymore? # TODO Maybe we could? In case the HDD doesn't boot anymore?
}; };
}; };
hardware.cpu.intel.updateMicrocode = true; };
# Also from nixos-generate-config
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
@ -35,11 +44,23 @@ in
]; ];
maxVideoHeight = 1440; maxVideoHeight = 1440;
numlock = true; numlock = true;
phasesBrightness = { phasesCommands = {
enable = true; jour = ''
jour = "40000"; ${pkgs.brightnessctl}/bin/brightnessctl set 40000 &
crepuscule = "10000"; ${pkgs.ddcutil}/bin/ddcutil setvcp 10 20 -d 1 &
nuit = "1"; ${pkgs.ddcutil}/bin/ddcutil setvcp 10 20 -d 2 &
'';
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,10 +80,6 @@
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";
@ -98,6 +94,19 @@
${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,31 +2,23 @@
{ pkgs, lib, config, ... }: { pkgs, lib, config, ... }:
let let
phases = [ phases = [
{ command = "jour"; polarity = "light"; } { command = "jour"; specialisation = null; }
{ command = "crepuscule"; polarity = "dark"; } { command = "crepuscule"; specialisation = "dark"; }
{ command = "nuit"; polarity = "dark"; } { command = "nuit"; specialisation = "dark"; }
]; ];
phasesBrightness = config.frogeye.desktop.phasesBrightness;
in in
{ {
config = { config = {
home.packages = map home.packages = map
(phase: (pkgs.writeShellApplication { (phase: (pkgs.writeShellScriptBin phase.command ''
name = "${phase.command}"; switch="/nix/var/nix/profiles/system${lib.strings.optionalString (phase.specialisation != null) "/specialisation/${phase.specialisation}"}/bin/switch-to-configuration"
runtimeInputs = [ pkgs.brightnessctl ];
text = (lib.optionalString phasesBrightness.enable ''
brightnessctl set ${builtins.getAttr phase.command phasesBrightness}
'') + ''
switch="/nix/var/nix/profiles/system/specialisation/${phase.polarity}/bin/switch-to-configuration"
if [ -x "$switch" ] if [ -x "$switch" ]
then then
# In two steps to get the visual changes slightly earlier sudo "$switch" test &
sudo "$switch" test sudo "$switch" boot &
sudo "$switch" boot
fi fi
''; ${builtins.getAttr phase.command config.frogeye.desktop.phasesCommands}
}) ''))
)
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,8 +1,4 @@
{ 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 {
@ -14,32 +10,26 @@ in
verb="$1" verb="$1"
shift shift
fi fi
nixos_flake="/etc/nixos/flake.nix" nixos_flake="$(readlink -f /etc/nixos)"
if [ -f "$nixos_flake" ] if [ -f "$nixos_flake/flake.nix" ]
then then
sudo ${ulf} "$nixos_flake" nix run "$nixos_flake#updateLocalFlakes" -- "$nixos_flake"
# ${pkgs.nix-output-monitor}/bin/nom build "$(dirname "$nixos_flake")#nixosConfigurations.$HOSTNAME.config.system.build.toplevel" nix run "$nixos_flake#nixosRebuild" -- "$verb" "$@"
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

@ -82,24 +82,9 @@ sudo nix --extra-experimental-features "nix-command flakes" run "${SCRIPT_DIR}#d
trap - ERR trap - ERR
rm "$luks_pass_file" rm "$luks_pass_file"
# Generate hardware-config.nix # Save that system configuration uses this repo
sudo nix --extra-experimental-features "nix-command flakes" run "${SCRIPT_DIR}#nixos-generate-config" -- --no-filesystems --root "$mountpoint" sudo mkdir -p "${mountpoint}/etc"
# --no-filesystems because they are imported via disko sudo ln -sfn "${flake_uri}" "${mountpoint}/nixos"
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,11 +22,10 @@
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;
}; };
phasesBrightness = { phasesCommands = {
enable = lib.mkEnableOption "Set a specific brightness for the screen when running phases commands"; jour = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: jour"; };
jour = lib.mkOption { type = lib.types.str; default = "100%"; description = "brightnessctl value for phase: jour"; }; crepuscule = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: crepuscule"; };
crepuscule = lib.mkOption { type = lib.types.str; default = "50%"; description = "brightnessctl value for phase: crepuscule"; }; nuit = lib.mkOption { type = lib.types.lines; default = ""; description = "Command to execute for phase: nuit"; };
nuit = lib.mkOption { type = lib.types.str; default = "1%"; description = "brightnessctl value for phase: nuit"; };
}; };
}; };
dev = { dev = {

View file

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

View file

@ -1,9 +1,11 @@
{ 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;

View file

@ -1,14 +0,0 @@
{ 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,7 +34,6 @@
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

54
os/rebuild.sh Normal file
View file

@ -0,0 +1,54 @@
# 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,11 +16,16 @@
frogeye.desktop = { frogeye.desktop = {
x11_screens = [ "DP-1" "eDP-1" ]; x11_screens = [ "DP-1" "eDP-1" ];
maxVideoHeight = 1080; maxVideoHeight = 1080;
phasesBrightness = { phasesCommands = {
enable = true; jour = ''
jour = "3500"; ${pkgs.brightnessctl}/bin/brightnessctl set 3500
crepuscule = "3000"; '';
nuit = "700"; crepuscule = ''
${pkgs.brightnessctl}/bin/brightnessctl set 3000
'';
nuit = ''
${pkgs.brightnessctl}/bin/brightnessctl set 700
'';
}; };
}; };