diff --git a/configure.sh b/configure.sh index fb45a54..0997189 100755 --- a/configure.sh +++ b/configure.sh @@ -39,20 +39,33 @@ chooseOpts() { # A looping function to choose Y or N. chooseYN() { + # Determine the default based on upper case Y or N in prompt. local default="" if [[ "$1" =~ \[.*([YN]).*\] ]]; then default=${BASH_REMATCH[1]} fi - echo -n "$1: " - read -r CHOICE - [[ -z $CHOICE ]] && CHOICE=$default - if [[ "$CHOICE" =~ ^[yY]$ ]]; then - CHOICE="y" - elif [[ "$CHOICE" =~ ^[nN]$ ]]; then - CHOICE="n" - else - chooseYN "$1" - fi + + # Loop for the choice. + while true; do + # Prompt for choice. + echo -n "$1: " + read -r CHOICE + + # If choice is empty, set choice to the default. + [[ -z $CHOICE ]] && CHOICE=$default + + # If choice does not equal Y or N, continue. + # Otherwise set the global CHOICE variable to lowercase y or n. + # Lowercase allows for easy logic in code that calls this function. + if [[ "$CHOICE" =~ ^[yY]$ ]]; then + CHOICE="y" + elif [[ "$CHOICE" =~ ^[nN]$ ]]; then + CHOICE="n" + else + continue + fi + break + done } # Determine video drivers based on PCI devices. diff --git a/flake.lock b/flake.lock index 1e54a3e..8dfb8b8 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1715822638, - "narHash": "sha256-Z4ZoyK8jYRmBZwMaEZLEmAilrfdpekwwwohliqC14/E=", + "lastModified": 1718242063, + "narHash": "sha256-n3AWItJ4a94GT0cray/eUV7tt3mulQ52L+lWJN9d1E8=", "owner": "nix-community", "repo": "disko", - "rev": "476eef8d85aa09389ae7baf6e6b60357f6a01432", + "rev": "832a9f2c81ff3485404bd63952eadc17bf7ccef2", "type": "github" }, "original": { @@ -20,6 +20,26 @@ "type": "github" } }, + "flatpaks": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + }, + "locked": { + "lastModified": 1707326266, + "narHash": "sha256-vRVih6iltuyLdj305Pj236BfhzFaOkAbHg3r5VsFdxs=", + "owner": "GermanBread", + "repo": "declarative-flatpak", + "rev": "efe7897ddcfbca085fba0690b3094e7f8e8911dd", + "type": "github" + }, + "original": { + "owner": "GermanBread", + "ref": "stable", + "repo": "declarative-flatpak", + "type": "github" + } + }, "home-manager": { "inputs": { "nixpkgs": [ @@ -27,16 +47,16 @@ ] }, "locked": { - "lastModified": 1715381426, - "narHash": "sha256-wPuqrAQGdv3ISs74nJfGb+Yprm23U/rFpcHFFNWgM94=", + "lastModified": 1717527182, + "narHash": "sha256-vWSkg6AMok1UUQiSYVdGMOXKD2cDFnajITiSi0Zjd1A=", "owner": "nix-community", "repo": "home-manager", - "rev": "ab5542e9dbd13d0100f8baae2bc2d68af901f4b4", + "rev": "845a5c4c073f74105022533907703441e0464bc3", "type": "github" }, "original": { "owner": "nix-community", - "ref": "release-23.11", + "ref": "release-24.05", "repo": "home-manager", "type": "github" } @@ -48,11 +68,11 @@ ] }, "locked": { - "lastModified": 1715486357, - "narHash": "sha256-4pRuzsHZOW5W4CsXI9uhKtiJeQSUoe1d2M9mWU98HC4=", + "lastModified": 1718243258, + "narHash": "sha256-abBpj2VU8p6qlRzTU8o22q68MmOaZ4v8zZ4UlYl5YRU=", "owner": "nix-community", "repo": "home-manager", - "rev": "44677a1c96810a8e8c4ffaeaad10c842402647c1", + "rev": "8d5e27b4807d25308dfe369d5a923d87e7dbfda3", "type": "github" }, "original": { @@ -63,15 +83,15 @@ }, "nixpkgs": { "locked": { - "lastModified": 1715668745, - "narHash": "sha256-xp62OkRkbUDNUc6VSqH02jB0FbOS+MsfMb7wL1RJOfA=", - "owner": "nixos", + "lastModified": 1706098335, + "narHash": "sha256-r3dWjT8P9/Ah5m5ul4WqIWD8muj5F+/gbCdjiNVBKmU=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "9ddcaffecdf098822d944d4147dd8da30b4e6843", + "rev": "a77ab169a83a4175169d78684ddd2e54486ac651", "type": "github" }, "original": { - "owner": "nixos", + "owner": "NixOS", "ref": "nixos-23.11", "repo": "nixpkgs", "type": "github" @@ -79,11 +99,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1715534503, - "narHash": "sha256-5ZSVkFadZbFP1THataCaSf0JH2cAH3S29hU9rrxTEqk=", + "lastModified": 1718160348, + "narHash": "sha256-9YrUjdztqi4Gz8n3mBuqvCkMo4ojrA6nASwyIKWMpus=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2057814051972fa1453ddfb0d98badbea9b83c06", + "rev": "57d6973abba7ea108bac64ae7629e7431e0199b6", "type": "github" }, "original": { @@ -93,14 +113,64 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1718208800, + "narHash": "sha256-US1tAChvPxT52RV8GksWZS415tTS7PV42KTc2PNDBmc=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "cc54fb41d13736e92229c21627ea4f22199fee6b", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { "disko": "disko", + "flatpaks": "flatpaks", "home-manager": "home-manager", "home-manager-unstable": "home-manager-unstable", - "nixpkgs": "nixpkgs", + "nixpkgs": "nixpkgs_2", "nixpkgs-unstable": "nixpkgs-unstable" } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index c6be9b9..289f4e1 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,7 @@ # Package sources. inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; disko = { @@ -12,7 +12,7 @@ }; home-manager = { - url = "github:nix-community/home-manager/release-23.11"; + url = "github:nix-community/home-manager/release-24.05"; inputs.nixpkgs.follows = "nixpkgs"; }; @@ -20,10 +20,11 @@ url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; + flatpaks.url = "github:GermanBread/declarative-flatpak/stable"; }; # Flake outputs, NixOS and Home Configurations. - outputs = inputs@{ self, ... }: + outputs = inputs@{ self, flatpaks, ... }: let # Load settings.nix or the default if not exists. settings = (if (builtins.pathExists ./settings.nix) @@ -76,9 +77,10 @@ inherit settings; }; modules = [ - config inputs.disko.nixosModules.disko home-manager.nixosModules.default + flatpaks.nixosModules.default + config ]; }; @@ -89,7 +91,10 @@ inherit inputs; inherit settings; }; - modules = [ config ]; + modules = [ + flatpaks.homeManagerModules.default + config + ]; }; in { # NixOS configurations, in most cases we use default with a profile. diff --git a/home_update.sh b/home_update.sh new file mode 100644 index 0000000..cbefdc5 --- /dev/null +++ b/home_update.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +# Change into script dir. +cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null || exit +nixosDir=$(pwd) + +# Rebuild and switch. +# shellcheck disable=SC2068 +home-manager switch --flake "path:$nixosDir" $@ diff --git a/modules/home/flatpaks.nix b/modules/home/flatpaks.nix new file mode 100644 index 0000000..4d7718b --- /dev/null +++ b/modules/home/flatpaks.nix @@ -0,0 +1,21 @@ +{pkgs, settings, ...}: + +{ + # Setup flatpaks. + services.flatpak.enableModule = true; + services.flatpak.remotes = { + "flathub" = "https://dl.flathub.org/repo/flathub.flatpakrepo"; + }; + services.flatpak.packages = [ + "flathub:app/org.kde.kdenlive/x86_64/stable" + "flathub:app/org.libreoffice.LibreOffice/x86_64/stable" + "flathub:app/org.onlyoffice.desktopeditors/x86_64/stable" + "flathub:app/md.obsidian.Obsidian/x86_64/stable" + "flathub:app/org.mozilla.Thunderbird/x86_64/stable" + "flathub:app/com.calibre_ebook.calibre/x86_64/stable" + "flathub:app/org.gimp.GIMP/x86_64/stable" + "flathub:app/org.kde.krita/x86_64/stable" + "flathub:app/org.inkscape.Inkscape/x86_64/stable" + "flathub:app/org.blender.Blender/x86_64/stable" + ]; +} \ No newline at end of file diff --git a/modules/nixos/users.nix b/modules/nixos/users.nix index c06e330..cf86f35 100644 --- a/modules/nixos/users.nix +++ b/modules/nixos/users.nix @@ -45,7 +45,12 @@ inherit settings; }; users = { - ${settings.user.name} = import ../../users/main-user.nix; + ${settings.user.name} = { + imports = [ + inputs.flatpaks.homeManagerModules.default + ../../users/main-user.nix + ]; + }; "root" = import ../../users/root.nix; }; }; diff --git a/rebuild.sh b/rebuild.sh index 188795c..ee6a097 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -17,4 +17,4 @@ fi # Rebuild and switch. # shellcheck disable=SC2068 -nixos-rebuild switch --impure --flake "path:$nixosDir/#$host" $@ +sudo nixos-rebuild switch --impure --flake "path:$nixosDir/#$host" $@ diff --git a/update.sh b/update.sh index ae8cf2b..ff25877 100755 --- a/update.sh +++ b/update.sh @@ -10,23 +10,27 @@ if [[ -n $nixHostOverride ]]; then host=$nixHostOverride fi +if (( EUID==0 )); then + sudoCmd="sudo -u grmrgecko" +fi + # Confirm host configuration is available; If not, we should not continue. if ! grep -q "nixosConfigurations.$host " flake.nix; then host="default" fi # Update nixpkgs. -if ! sudo -u grmrgecko nix flake update "$nixosDir"; then +if ! $sudoCmd nix flake update "$nixosDir"; then echo "Update failed" exit 1 fi # Add updated lock file to git staging for rebuild below. -sudo -u grmrgecko git add flake.lock +$sudoCmd git add flake.lock # Commit update. -sudo -u grmrgecko git commit -m "Flake update $(date)" +$sudoCmd git commit -m "Flake update $(date)" # Rebuild and switch. # shellcheck disable=SC2068 -nixos-rebuild switch --impure --flake "path:$nixosDir/#$host" $@ +sudo nixos-rebuild switch --impure --flake "path:$nixosDir/#$host" $@ diff --git a/users/main-user.nix b/users/main-user.nix index fdbd3ee..40fb23d 100644 --- a/users/main-user.nix +++ b/users/main-user.nix @@ -4,6 +4,7 @@ imports = [ ../modules/home/git.nix ../modules/home/zsh.nix + ../modules/home/flatpaks.nix ] ++ (if (builtins.pathExists ../modules/home/profiles/${settings.profile}.nix) then [ ../modules/home/profiles/${settings.profile}.nix ]