feat: migrate to nix flake
This commit is contained in:
parent
d466f7e800
commit
80d4bb746e
45
README.md
45
README.md
|
@ -1,8 +1,43 @@
|
||||||
# FelschR's NixOS configuration
|
# felschr's NixOS configuration
|
||||||
|
|
||||||
## Installation on new machine
|
## Installation
|
||||||
To setup a new machine run the following command after completing partitioning and mounting:
|
|
||||||
|
Clone the configuraiton into `etc/nixos`.
|
||||||
|
|
||||||
|
On a new machine run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nixos-generate-config --root /mnt
|
||||||
```
|
```
|
||||||
./install.sh <NIX_CONFIG>
|
|
||||||
|
Then move the resulting `/etc/nixos/hardware-configuration.nix` to `./hardware/<config>.nix` and adjust it and the `flake.nix` accodringly.
|
||||||
|
Make sure everything was properly recognised. Btrfs mount options might be missing, for example.
|
||||||
|
|
||||||
|
To install run the following command where `<config>` matches `outputs.nixosConfigurations.<config>` in `flake.nix`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nixos-install --flake /etc/nixos#<config>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Updating
|
||||||
|
|
||||||
|
Update all or specific locked flake inputs:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix flake update
|
||||||
|
nix flake update --update-input <input>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Rebuilding the system
|
||||||
|
|
||||||
|
Rebuild the system:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo nixos-rebuild switch
|
||||||
|
```
|
||||||
|
|
||||||
|
Update flake.lock and rebuild the system:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix flake update && sudo nixos-rebuild switch
|
||||||
```
|
```
|
||||||
This runs `nixos-generate-config`, symlinks the passed configuration to `/etc/nixos/configuration.nix`, sets up required nix channels and then runs `nixos-install`.
|
|
||||||
|
|
62
flake.lock
Normal file
62
flake.lock
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"home-manager": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1600810013,
|
||||||
|
"narHash": "sha256-Zcvg0/ot+EfV1fOdUF0G/GY2zBq76ksv92cpa2E2xvk=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "home-manager",
|
||||||
|
"rev": "a6a3abb295777b1d3ac1ca7f2d47bd0daf7f9638",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"ref": "master",
|
||||||
|
"repo": "home-manager",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1600573085,
|
||||||
|
"narHash": "sha256-w5SGosyuTbFCBoUzgy2gyVcxYxRUvZ6SgHsRIPkZXgI=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "1179840f9a88b8a548f4b11d1a03aa25a790c379",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nur": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1600834397,
|
||||||
|
"narHash": "sha256-LGv1Red7btJ4fyiYjeVOhThJ5mulFgV7E9ZQJImg1To=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "NUR",
|
||||||
|
"rev": "b347177e8aeac5eb21b0fd58966c24dee754039d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"ref": "master",
|
||||||
|
"repo": "NUR",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"home-manager": "home-manager",
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"nur": "nur"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
60
flake.nix
Normal file
60
flake.nix
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
{
|
||||||
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
|
||||||
|
inputs.home-manager = {
|
||||||
|
url = "github:nix-community/home-manager/master";
|
||||||
|
flake = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
inputs.nur.url = "github:nix-community/NUR/master";
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, home-manager, nur }: let
|
||||||
|
systemModule = { hostName, hardwareConfig, config }: ({ pkgs, ... }: {
|
||||||
|
networking.hostName = hostName;
|
||||||
|
|
||||||
|
# Let 'nixos-version --json' know about the Git revision
|
||||||
|
# of this flake.
|
||||||
|
system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev;
|
||||||
|
|
||||||
|
nix.registry.nixpkgs.flake = nixpkgs;
|
||||||
|
|
||||||
|
nixpkgs.overlays = [
|
||||||
|
nur.overlay
|
||||||
|
];
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
hardwareConfig
|
||||||
|
"${home-manager}/nixos"
|
||||||
|
config
|
||||||
|
];
|
||||||
|
});
|
||||||
|
in {
|
||||||
|
|
||||||
|
nixosConfigurations.felix-nixos = nixpkgs.lib.nixosSystem {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
modules =
|
||||||
|
[
|
||||||
|
nixpkgs.nixosModules.notDetected
|
||||||
|
(systemModule {
|
||||||
|
hostName = "felix-nixos";
|
||||||
|
hardwareConfig = ./hardware/felix-nixos.nix;
|
||||||
|
config = ./home-pc.nix;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
nixosConfigurations.pilot1 = nixpkgs.lib.nixosSystem {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
modules =
|
||||||
|
[
|
||||||
|
nixpkgs.nixosModules.notDetected
|
||||||
|
(systemModule {
|
||||||
|
hostName = "pilot1";
|
||||||
|
hardwareConfig = ./hardware-configuration.nix; # TODO
|
||||||
|
config = ./work-pc.nix;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
43
hardware/felix-nixos.nix
Normal file
43
hardware/felix-nixos.nix
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" "sr_mod" ];
|
||||||
|
boot.initrd.kernelModules = [ ];
|
||||||
|
boot.kernelModules = [ "kvm-amd" ];
|
||||||
|
boot.extraModulePackages = [ ];
|
||||||
|
|
||||||
|
fileSystems."/" =
|
||||||
|
{ device = "/dev/disk/by-uuid/9ef41d63-a7ad-406d-8c2b-5ad3fb4c0ea6";
|
||||||
|
fsType = "btrfs";
|
||||||
|
options = [ "subvol=@" "compress-force=zstd" "noatime" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
boot.initrd.luks.devices."enc".device = "/dev/disk/by-uuid/6f4f3ce1-57fd-4ec3-bb9d-7847853d2dcf";
|
||||||
|
|
||||||
|
fileSystems."/home" =
|
||||||
|
{ device = "/dev/disk/by-uuid/9ef41d63-a7ad-406d-8c2b-5ad3fb4c0ea6";
|
||||||
|
fsType = "btrfs";
|
||||||
|
options = [ "subvol=@home" "compress-force=zstd" "noatime" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
fileSystems."/swap" =
|
||||||
|
{ device = "/dev/disk/by-uuid/9ef41d63-a7ad-406d-8c2b-5ad3fb4c0ea6";
|
||||||
|
fsType = "btrfs";
|
||||||
|
options = [ "subvol=@swap" ];
|
||||||
|
neededForBoot = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
fileSystems."/.snapshots" =
|
||||||
|
{ device = "/dev/disk/by-uuid/9ef41d63-a7ad-406d-8c2b-5ad3fb4c0ea6";
|
||||||
|
fsType = "btrfs";
|
||||||
|
options = [ "subvol=@snapshots" "compress-force=zstd" "noatime" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
fileSystems."/boot" =
|
||||||
|
{ device = "/dev/disk/by-uuid/5C20-4516";
|
||||||
|
fsType = "vfat";
|
||||||
|
};
|
||||||
|
|
||||||
|
swapDevices = [ ];
|
||||||
|
|
||||||
|
}
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./hardware-configuration.nix
|
|
||||||
<home-manager/nixos>
|
|
||||||
./hardware/base.nix
|
./hardware/base.nix
|
||||||
./hardware/gpu-nvidia.nix
|
./hardware/gpu-nvidia.nix
|
||||||
./hardware/ledger.nix
|
./hardware/ledger.nix
|
||||||
|
@ -21,8 +19,6 @@
|
||||||
"p7zip-16.02" # currently used by lutris
|
"p7zip-16.02" # currently used by lutris
|
||||||
];
|
];
|
||||||
|
|
||||||
networking.hostName = "felix-nixos";
|
|
||||||
|
|
||||||
hardware.enableAllFirmware = true;
|
hardware.enableAllFirmware = true;
|
||||||
hardware.cpu.amd.updateMicrocode = true;
|
hardware.cpu.amd.updateMicrocode = true;
|
||||||
services.fwupd.enable = true;
|
services.fwupd.enable = true;
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
dirs = [ "~/dev/work/" ];
|
dirs = [ "~/dev/work/" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
defaultProfile = "private";
|
|
||||||
|
|
||||||
ignores = [".direnv"];
|
ignores = [".direnv"];
|
||||||
signing = {
|
signing = {
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
with pkgs;
|
with pkgs;
|
||||||
let
|
let
|
||||||
# TODO this doesn't affect the desktop file
|
|
||||||
# e.g. when starting via GNOME the flag is not set
|
|
||||||
signal-desktop = runCommand "signal-desktop" {
|
signal-desktop = runCommand "signal-desktop" {
|
||||||
buildInputs = [ makeWrapper ];
|
buildInputs = [ makeWrapper ];
|
||||||
} ''
|
} ''
|
||||||
|
@ -17,8 +15,10 @@ in
|
||||||
{
|
{
|
||||||
home.packages = [ signal-desktop ];
|
home.packages = [ signal-desktop ];
|
||||||
|
|
||||||
|
# TODO switch to overwritten `signal-desktop` when
|
||||||
|
# desktop file is updated with correct exec path
|
||||||
xdg.configFile."autostart/signal-desktop.desktop".text =
|
xdg.configFile."autostart/signal-desktop.desktop".text =
|
||||||
builtins.replaceStrings
|
builtins.replaceStrings
|
||||||
["bin/signal-desktop"] ["bin/signal-desktop --start-in-tray"]
|
["bin/signal-desktop"] ["bin/signal-desktop --start-in-tray"]
|
||||||
(builtins.readFile "${signal-desktop}/share/applications/signal-desktop.desktop");
|
(builtins.readFile "${pkgs.signal-desktop}/share/applications/signal-desktop.desktop");
|
||||||
}
|
}
|
||||||
|
|
29
install.sh
29
install.sh
|
@ -1,29 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ $EUID != 0 ]; then
|
|
||||||
sudo "$0" "$@"
|
|
||||||
exit $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
CONFIG=$1
|
|
||||||
|
|
||||||
if [ -z "$CONFIG" ]
|
|
||||||
then
|
|
||||||
echo "path to config to use as configuration.nix needs to be passed as first argument"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "using configuration: '$CONFIG'"
|
|
||||||
fi
|
|
||||||
|
|
||||||
ln -s $CONFIG configuration.nix
|
|
||||||
|
|
||||||
nixos-generate-config --root /mnt
|
|
||||||
|
|
||||||
# add nixos-unstable and home-manager channels
|
|
||||||
nix-channel --add https://nixos.org/channels/nixos-unstable nixos
|
|
||||||
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
|
|
||||||
nix-channel --update
|
|
||||||
|
|
||||||
nixos-install
|
|
|
@ -5,7 +5,6 @@
|
||||||
./hardened.nix
|
./hardened.nix
|
||||||
./i18n.nix
|
./i18n.nix
|
||||||
./nix.nix
|
./nix.nix
|
||||||
./nur.nix
|
|
||||||
./vpn.nix
|
./vpn.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
# for flakes support
|
||||||
|
nix.package = pkgs.nixUnstable;
|
||||||
|
nix.extraOptions = ''
|
||||||
|
experimental-features = nix-command flakes
|
||||||
|
'';
|
||||||
|
|
||||||
nix.autoOptimiseStore = true;
|
nix.autoOptimiseStore = true;
|
||||||
nix.gc = {
|
nix.gc = {
|
||||||
automatic = true;
|
automatic = true;
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
{ config, pkgs, ... }:
|
|
||||||
|
|
||||||
{
|
|
||||||
nixpkgs.config.packageOverrides = pkgs: {
|
|
||||||
nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
|
|
||||||
inherit pkgs;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./hardware-configuration.nix
|
|
||||||
<home-manager/nixos>
|
|
||||||
./hardware/base.nix
|
./hardware/base.nix
|
||||||
./hardware/gpu-bumblebee.nix
|
./hardware/gpu-bumblebee.nix
|
||||||
./system
|
./system
|
||||||
|
@ -21,8 +19,6 @@
|
||||||
|
|
||||||
nixpkgs.config.allowUnfree = true;
|
nixpkgs.config.allowUnfree = true;
|
||||||
|
|
||||||
networking.hostName = "pilot1-nixos"; # Define your hostname.
|
|
||||||
|
|
||||||
hardware.enableAllFirmware = true;
|
hardware.enableAllFirmware = true;
|
||||||
hardware.cpu.intel.updateMicrocode = true;
|
hardware.cpu.intel.updateMicrocode = true;
|
||||||
hardware.logitech.enable = true;
|
hardware.logitech.enable = true;
|
||||||
|
|
Loading…
Reference in a new issue