From a593b8d7fcfdfd82933f75d98ffdf72c32a835c4 Mon Sep 17 00:00:00 2001 From: Remy Moll Date: Wed, 28 Aug 2024 00:18:47 +0200 Subject: [PATCH] adding modularity --- README.md | 19 +++++- flake.lock | 66 +++++++++++++++++++ flake.nix | 39 +++++++++-- .../spectre-x360-2018/configuration.nix | 10 ++- .../hardware-configuration.nix | 0 modules/home-manager/browser.nix | 11 ++++ modules/home-manager/code.nix | 6 ++ modules/nixos/gdm.nix | 26 ++++++++ modules/nixos/networks.nix | 26 ++++++++ users/remy.nix | 31 +++++++++ utils/binary-cache.nix | 22 +++++++ utils/garbage-collection.nix | 23 +++++++ 12 files changed, 269 insertions(+), 10 deletions(-) create mode 100644 flake.lock rename {machines => hosts}/spectre-x360-2018/configuration.nix (92%) rename {machines => hosts}/spectre-x360-2018/hardware-configuration.nix (100%) create mode 100644 modules/home-manager/browser.nix create mode 100644 modules/home-manager/code.nix create mode 100644 modules/nixos/gdm.nix create mode 100644 modules/nixos/networks.nix create mode 100644 users/remy.nix create mode 100644 utils/binary-cache.nix create mode 100644 utils/garbage-collection.nix diff --git a/README.md b/README.md index d633a68..4f5c8bf 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,19 @@ # NixOS configuration - managing my devices - \ No newline at end of file + + +## Using this flake +Clone this repository and use the current directory as the flake target ``. + +or + +Use this repository as a a remote input using the following format for ``: +``` +git+https://git.kluster.moll.re/remoll/nixos-config +``` +Don't forget to add the `#` to the end of the target to specify the host configuration to use. + + +## Hosts + +### Spectre +Run `nixos-rebuild switch --flake #spectre` to apply the configuration. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d6c5872 --- /dev/null +++ b/flake.lock @@ -0,0 +1,66 @@ +{ + "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720042825, + "narHash": "sha256-A0vrUB6x82/jvf17qPCpxaM+ulJnD8YZwH9Ci0BsAzE=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "e1391fb22e18a36f57e6999c7a9f966dc80ac073", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-24.05", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1724531977, + "narHash": "sha256-XROVLf9ti4rrNCFLr+DmXRZtPjCQTW4cYy59owTEmxk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2527da1ef492c495d5391f3bcf9c1dd9f4514e32", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-unstable": { + "locked": { + "lastModified": 1724479785, + "narHash": "sha256-pP3Azj5d6M5nmG68Fu4JqZmdGt4S4vqI5f8te+E/FTw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d0e1602ddde669d5beb01aec49d71a51937ed7be", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nixpkgs": "nixpkgs", + "nixpkgs-unstable": "nixpkgs-unstable" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 71d9f44..31fd8eb 100644 --- a/flake.nix +++ b/flake.nix @@ -4,16 +4,41 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; - # probably home manager at some point + # Home manager + home-manager.url = "github:nix-community/home-manager/release-24.05"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, ... }@inputs: { + outputs = { + self, + nixpkgs, + home-manager, + ... + } @ inputs: { - nixosConfigurations.spectre-x360-2018 = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ./machines/spectre-x360-2018/configuration.nix - ]; + nixosConfigurations = { + # HP Spectre x360 2018 + spectre = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./hosts/spectre-x360-2018/configuration.nix + ./modules/nixos/gdm.nix + home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + + # home-manager.extraSpecialArgs = inputs // specialArgs; + home-manager.users.remy = import ./users/remy.nix; + } + ]; + }; }; }; + # raspberry-pi = nixpkgs.lib.nixosSystem { + # system = "aarch64-linux"; + # modules = [ + # ./hosts/raspberry-pi/configuration.nix + # ]; + # }; } diff --git a/machines/spectre-x360-2018/configuration.nix b/hosts/spectre-x360-2018/configuration.nix similarity index 92% rename from machines/spectre-x360-2018/configuration.nix rename to hosts/spectre-x360-2018/configuration.nix index 8028157..5d4da1b 100644 --- a/machines/spectre-x360-2018/configuration.nix +++ b/hosts/spectre-x360-2018/configuration.nix @@ -10,19 +10,25 @@ ./hardware-configuration.nix ]; + # Use the "experimental" flakes for cleaner config + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + # Use the systemd-boot EFI boot loader. + # In this setup it is chain-loaded by REFInd (managed by Arch linux) boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = false; + + # require the bcachefs modules to be loaded boot.supportedFilesystems = [ "bcachefs" ]; boot.kernelPackages = pkgs.linuxPackages_latest; - networking.hostName = "nixos"; # Define your hostname. + networking.hostName = "ArchNix"; # Define your hostname. # Pick only one of the below networking options. # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. # networking.networkmanager.enable = true; # Easiest to use and most distros use this by default. # Set your time zone. - time.timeZone = "Europe/Amsterdam"; + time.timeZone = "Europe/Berlin"; # Configure network proxy if necessary # networking.proxy.default = "http://user:password@proxy:port/"; diff --git a/machines/spectre-x360-2018/hardware-configuration.nix b/hosts/spectre-x360-2018/hardware-configuration.nix similarity index 100% rename from machines/spectre-x360-2018/hardware-configuration.nix rename to hosts/spectre-x360-2018/hardware-configuration.nix diff --git a/modules/home-manager/browser.nix b/modules/home-manager/browser.nix new file mode 100644 index 0000000..c1093d8 --- /dev/null +++ b/modules/home-manager/browser.nix @@ -0,0 +1,11 @@ +{pkgs-stable, ...}: { + home.packages = with pkgs-stable; [ + firefox + ]; + firefox = { + enable = true; + profile = { + "browser.startup.homepage" = "https://www.google.com"; + }; + }; +} diff --git a/modules/home-manager/code.nix b/modules/home-manager/code.nix new file mode 100644 index 0000000..0f249b4 --- /dev/null +++ b/modules/home-manager/code.nix @@ -0,0 +1,6 @@ +{pkgs-stable, ...}: { + home.packages = with pkgs-stable; [ + vscode + flutter + ]; +} diff --git a/modules/nixos/gdm.nix b/modules/nixos/gdm.nix new file mode 100644 index 0000000..8a2a0d9 --- /dev/null +++ b/modules/nixos/gdm.nix @@ -0,0 +1,26 @@ + +{ + config, + lib, + pkgs, + ... +}: +{ + # this actually does not enable xorg, but it is required for GDM + services.xserver.enable = true; + services.xserver.displayManager.gdm.enable = true; + services.xserver.desktopManager.gnome.enable = true; + # here we set wayland to be used + services.xserver.displayManager.gdm.wayland = true; + + # options = { + # services.gdm = { + # enable = lib.mkEnableOption "Enable GDM"; + # # Add any additional GDM options here + # }; + # }; + + # config = { + # services.gdm = if config.services.gdm.enable then gdmConfig else {}; + # }; +} diff --git a/modules/nixos/networks.nix b/modules/nixos/networks.nix new file mode 100644 index 0000000..a3bb981 --- /dev/null +++ b/modules/nixos/networks.nix @@ -0,0 +1,26 @@ +{ config, pkgs, ... }: + +let + networks = [ + { + ssid = "MyNetwork1"; + psk = "password1"; + } + { + ssid = "MyNetwork2"; + psk = "password2"; + } + { + ssid = "MyNetwork3"; + psk = "password3"; + } + { + ssid = "MyNetwork4"; + psk = "password4"; + } + ]; +in + +{ + networking.networkmanager.networks = networks; +} \ No newline at end of file diff --git a/users/remy.nix b/users/remy.nix new file mode 100644 index 0000000..6b08a83 --- /dev/null +++ b/users/remy.nix @@ -0,0 +1,31 @@ +{pkgs, ...}: { + + imports = [ + ../modules/home-manager/browser.nix + ../modules/home-manager/code.nix + ]; + + stateVersion = "24.05"; + programs.git = { + userName = "Remy Moll"; + userEmail = "me@moll.re"; + }; + programs.fish = { + enable = true; + enableCompletion = true; + plugins = [ + { + name = "fzf-fish"; + src = pkgs.fetchFromGitHub { + owner = "PatrickF1"; + repo = "fzf.fish"; + rev = "v10.3"; + } + } + }; + + users.users.remy = { + shell = pkgs.fish; + }; + +} diff --git a/utils/binary-cache.nix b/utils/binary-cache.nix new file mode 100644 index 0000000..9fc2778 --- /dev/null +++ b/utils/binary-cache.nix @@ -0,0 +1,22 @@ +{ + lib, + ... +}: { + + # ... + nix.settings = { + # allow substituters to be used + + substituters = [ + # also add mirrors? + # "https://mirrors.ustc.edu.cn/nix-channels/store" + "https://cache.nixos.org" + ]; + + trusted-public-keys = [ + # the default public key of cache.nixos.org, it's built-in, no need to add it here + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + ]; + }; + +} diff --git a/utils/garbage-collection.nix b/utils/garbage-collection.nix new file mode 100644 index 0000000..18ce57b --- /dev/null +++ b/utils/garbage-collection.nix @@ -0,0 +1,23 @@ +{ lib, pkgs, ... }: + +{ + # ... + + # Limit the number of generations to keep + boot.loader.systemd-boot.configurationLimit = 10; + # boot.loader.grub.configurationLimit = 10; + + # Perform garbage collection weekly to maintain low disk usage + nix.gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 1w"; + }; + + # Optimize storage + # You can also manually optimize the store via: + # nix-store --optimise + # Refer to the following link for more details: + # https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-auto-optimise-store + nix.settings.auto-optimise-store = true; +}