many changes

This commit is contained in:
Dmitriy Kholkin 2020-08-05 04:52:30 +04:00
parent de91841c0e
commit c3f757ac1a
15 changed files with 74 additions and 107 deletions

6
flake.lock generated
View File

@ -72,11 +72,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1596472492, "lastModified": 1596554686,
"narHash": "sha256-tDghU8H3KU2LP6SY6HtugEBtEdQmPN2TfW8FgS/kCKs=", "narHash": "sha256-B+c/xcjp/7vxUm6zVV2SwPalRWYWzxoUOvjGrzlwm7g=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nix", "repo": "nix",
"rev": "24e07c428f21f28df2a41a7a9851d5867f34753a", "rev": "5b22a2c0d443ce1156f361af2dcb142d270daa6c",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -60,19 +60,19 @@
}; };
in genAttrs hosts mkHost; in genAttrs hosts mkHost;
# legacyPackages.x86_64-linux = legacyPackages.x86_64-linux =
# (builtins.head (builtins.attrValues self.nixosConfigurations)).pkgs; (builtins.head (builtins.attrValues self.nixosConfigurations)).pkgs;
# nix run github:serokell/deploy # nix run github:serokell/deploy
# Because sudo requires local presence of my Yubikey, we have to manually activate the system # Because sudo requires local presence of my Yubikey, we have to manually activate the system
# sudo nix-env -p /nix/var/nix/profiles/system --set /nix/var/nix/profiles/per-user/alukard/system; # sudo nix-env -p /nix/var/nix/profiles/system --set /nix/var/nix/profiles/per-user/alukard/system;
# sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch # sudo /nix/var/nix/profiles/system/bin/switch-to-configuration switch
# deploy = { deploy = {
# user = "alukard"; user = "alukard";
# nodes = builtins.mapAttrs (_: conf: { nodes = builtins.mapAttrs (_: conf: {
# hostname = conf.config.networking.hostName; hostname = conf.config.networking.hostName;
# profiles.system.path = conf.config.system.build.toplevel; profiles.system.path = conf.config.system.build.toplevel;
# }) self.nixosConfigurations; }) self.nixosConfigurations;
# }; };
}; };
} }

View File

@ -1,27 +1,32 @@
# Do not modify this file! It was generated by nixos-generate-config # Do not modify this file! It was generated by nixos-generate-config
# and may be overwritten by future invocations. Please make changes # and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead. # to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, inputs, ... }: { config, lib, pkgs, modulesPath, ... }:
{ {
imports = [ ]; imports = [ ];
boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "sd_mod" "sr_mod" ]; boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "sd_mod" "sr_mod" ];
boot.initrd.kernelModules = [ ]; boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-amd" ]; boot.kernelModules = [ "kvm-amd" ];
boot.extraModulePackages = [ ]; boot.extraModulePackages = [ ];
fileSystems."/" = fileSystems."/" =
{ device = "/dev/disk/by-uuid/e9d79e40-9a7c-490f-9fc3-8ba36e1ee856"; { device = "/dev/disk/by-uuid/9affc545-6755-4b5b-b820-36ebb1119330";
fsType = "f2fs"; fsType = "f2fs";
}; };
fileSystems."/boot" = fileSystems."/boot" =
{ device = "/dev/sda1"; { device = "/dev/disk/by-uuid/4D6C-D3AB";
fsType = "vfat"; fsType = "vfat";
}; };
swapDevices = [ ]; swapDevices = [
{
device = "/dev/disk/by-partuuid/5ff8b0ed-a111-4399-916a-8e49ccb3dd4d";
randomEncryption.enable = true;
}
];
virtualisation.virtualbox.guest.enable = true; virtualisation.virtualbox.guest.enable = true;
} }

View File

@ -1,18 +1,18 @@
#! /usr/bin/env nix-shell #! /usr/bin/env nix-shell
#! nix-shell -i bash -p git #! nix-shell -i bash -p perl
cd .. cd ..
CONFIG_FOLDER=$(pwd) CONFIG_FOLDER=$(pwd)
cd install cd install
ENCRYPT_ROOT=false ENCRYPT_ROOT=false
FORMAT_BOOT_PARTITION=false FORMAT_BOOT_PARTITION=true
DEVICE_NAME=Dell-Laptop DEVICE_NAME=NixOS-VM
MAX_JOBS=8 MAX_JOBS=4
DEVICE=/dev/nvme0n1 DEVICE=/dev/sda
BOOT_PARTITION=/dev/nvme0n1p1 BOOT_PARTITION=/dev/sda1
SWAP_PARTITION=/dev/nvme0n1p3 SWAP_PARTITION=/dev/sda3
ROOT_PARTITION=/dev/nvme0n1p2 ROOT_PARTITION=/dev/sda2
ROOT_NAME=cryptnixos ROOT_NAME=cryptnixos
gdisk $DEVICE gdisk $DEVICE
@ -38,12 +38,20 @@ mkdir /mnt/boot
mount $BOOT_PARTITION /mnt/boot mount $BOOT_PARTITION /mnt/boot
# Create swap # Create swap
mkswap -L swap $SWAP_PARTITION mkswap -L swap $SWAP_PARTITION
# Search swap PARTUUID
SW=$(cut -d'/' -f3 <<< "$SWAP_PARTITION")
SWAP_PARTUUID=$(eval "lsblk -o name,partuuid | grep $SW | awk '{print \$2}'")
# Generate config (hardware) # Generate config (hardware)
nixos-generate-config --root /mnt/ nixos-generate-config --root /mnt/
# Copy hardware conf into new installation
cp /mnt/etc/nixos/hardware-configuration.nix $CONFIG_FOLDER/hardware-configuration/$DEVICE_NAME.nix cp /mnt/etc/nixos/hardware-configuration.nix $CONFIG_FOLDER/hardware-configuration/$DEVICE_NAME.nix
# Change not-detected for flakes
sed -i 's#<nixpkgs/nixos/modules/installer/scan/not-detected.nix>#"${inputs.nixpkgs}/nixos/modules/installer/scan/not-detected.nix"#' $CONFIG_FOLDER/hardware-configuration/$DEVICE_NAME.nix sed -i 's#<nixpkgs/nixos/modules/installer/scan/not-detected.nix>#"${inputs.nixpkgs}/nixos/modules/installer/scan/not-detected.nix"#' $CONFIG_FOLDER/hardware-configuration/$DEVICE_NAME.nix
perl -0777 -pi -e "s#swapDevices.+#swapDevices = [\n {\n device = \"/dev/disk/by-partuuid/$SWAP_PARTUUID\";\n randomEncryption.enable = true;\n }\n ];#" $CONFIG_FOLDER/hardware-configuration/$DEVICE_NAME.nix
# Copy initial system config
cp ./min-config.nix /mnt/etc/nixos/configuration.nix cp ./min-config.nix /mnt/etc/nixos/configuration.nix
# Change hostname
sed -i "s#changeme#${DEVICE_NAME}#" /mnt/etc/nixos/configuration.nix
nixos-install -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/840c782d507d60aaa49aa9e3f6d0b0e780912742.tar.gz --max-jobs $MAX_JOBS --no-root-passwd nixos-install -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/840c782d507d60aaa49aa9e3f6d0b0e780912742.tar.gz --max-jobs $MAX_JOBS --no-root-passwd
mkdir -p /mnt/home/alukard/nixos-config mkdir -p /mnt/home/alukard/nixos-config

View File

@ -9,13 +9,14 @@
# Use the systemd-boot EFI boot loader. # Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = true; boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true; boot.loader.efi.canTouchEfiVariables = true;
boot.kernelPackages = pkgs.linuxPackages_latest;
networking = { networking = {
hostName = "nixos"; hostName = "changeme";
firewall.enable = false; firewall.enable = false;
networkmanager.enable = false; networkmanager.enable = false;
wireless = { wireless = {
enable = true; enable = false;
userControlled.enable = true; userControlled.enable = true;
networks.Alukard_5GHz = { networks.Alukard_5GHz = {
pskRaw = "feee27000fb0d7118d498d4d867416d04d1d9a1a7b5dbdbd888060bbde816fe4"; pskRaw = "feee27000fb0d7118d498d4d867416d04d1d9a1a7b5dbdbd888060bbde816fe4";
@ -24,26 +25,34 @@
}; };
}; };
programs.gnupg = {
agent.enable = true;
package = pkgs.gnupg;
};
nixpkgs.config = { nixpkgs.config = {
allowUnfree = true; allowUnfree = true;
}; };
nix = { nix = {
useSandbox = true; useSandbox = true;
autoOptimiseStore = true; autoOptimiseStore = true;
optimise.automatic = true; optimise.automatic = true;
extraOptions = ''
experimental-features = nix-command flakes
'';
package = pkgs.nixFlakes;
}; };
i18n = { i18n.defaultLocale = "en_GB.UTF-8";
consoleFont = "Lat2-Terminus16"; console = {
consoleKeyMap = "us"; font = "Lat2-Terminus16";
defaultLocale = "en_US.UTF-8"; keyMap = "us";
}; };
time.timeZone = "Europe/Volgograd"; time.timeZone = "Europe/Volgograd";
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [ git ];
wget vim git gnupg
];
users.mutableUsers = false; users.mutableUsers = false;
users.users.alukard = { users.users.alukard = {

View File

@ -1,11 +0,0 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
name = "nixflk";
nativeBuildInputs = with pkgs; [
git
];
shellHook = ''
'';
}

27
modules/devices.nix Executable file → Normal file
View File

@ -2,7 +2,7 @@
with lib; with lib;
with types; { with types; {
options = { options = {
device = mkOption { type = strMatching "[A-z]*-[A-z]*"; }; device = mkOption { type = strMatching "[A-z|0-9]*-(Laptop|Workstation|VM)"; };
devices = mkOption { type = attrs; }; devices = mkOption { type = attrs; };
deviceSpecific = mkOption { type = attrs; }; deviceSpecific = mkOption { type = attrs; };
}; };
@ -13,25 +13,21 @@ with types; {
in rec { in rec {
isLaptop = (!isNull (builtins.match ".*Laptop" device)); isLaptop = (!isNull (builtins.match ".*Laptop" device));
isVM = (!isNull (builtins.match ".*VM" device)); isVM = (!isNull (builtins.match ".*VM" device));
smallScreen = (device == "Dell-Laptop");
isHost = (device == "AMD-Workstation"); isHost = (device == "AMD-Workstation");
isShared = devInfo.isShared; isShared = devInfo.isShared;
isSSD = devInfo.drive.type == "ssd";
smallScreen = (device == "Dell-Laptop");
cpu = devInfo.cpu.vendor; cpu = devInfo.cpu.vendor;
video = devInfo.video; video = devInfo.video;
isSSD = devInfo.drive.type == "ssd";
enableVirtualisation = devInfo.enableVirtualisation; enableVirtualisation = devInfo.enableVirtualisation;
hostName = if !isNull devInfo.hostName then
devInfo.hostName
else
device;
}; };
devices = { devices = {
AMD-Workstation = { AMD-Workstation = {
cpu = { cpu = {
vendor = "amd"; vendor = "amd";
clock = 3800; clock = 3700;
cores = 6; threads = 12;
}; };
drive = { drive = {
type = "ssd"; type = "ssd";
@ -41,39 +37,36 @@ with types; {
ram = 16; ram = 16;
isShared = false; isShared = false;
enableVirtualisation = true; enableVirtualisation = true;
hostName = "ataraxia-pc";
}; };
Dell-Laptop = { Dell-Laptop = {
cpu = { cpu = {
vendor = "intel"; vendor = "intel";
clock = 1600; clock = 1600;
cores = 4; threads = 8;
}; };
drive = { drive = {
type = "ssd"; type = "ssd";
size = 250; size = 250;
}; };
video = "intel"; video = "intel";
ram = 8; ram = 16;
isShared = false; isShared = false;
enableVirtualisation = false; enableVirtualisation = false;
hostName = "dell-ataraxia";
}; };
NixOS-VM = { NixOS-VM = {
cpu = { cpu = {
vendor = "amd"; vendor = "amd";
clock = 3600; clock = 3700;
cores = 2; threads = 4;
}; };
drive = { drive = {
type = "ssd"; type = "ssd";
size = 12; size = 20;
}; };
video = "virtualbox"; video = "virtualbox";
ram = 4; ram = 4;
isShared = false; isShared = false;
enableVirtualisation = false; enableVirtualisation = false;
hostName = null;
}; };
}; };
}; };

13
modules/filesystems.nix Executable file → Normal file
View File

@ -90,17 +90,4 @@ with deviceSpecific; {
]; ];
}; };
}; };
swapDevices = [
{
device = if device == "AMD-Workstation" then
"/dev/disk/by-partuuid/3c4f9305-ad40-4ed3-b568-f1559f1c845a"
else if device == "Dell-Laptop" then
"/dev/disk/by-partuuid/e979f198-37c4-4a86-8138-e148c3d78447"
else if device == "NixOS-VM" then
"/dev/disk/by-partuuid/4caf1e45-2f1c-4cb2-a914-f2e90961503a"
else
"";
randomEncryption.enable = true;
}
];
} }

View File

@ -26,7 +26,7 @@
userControlled.enable = true; userControlled.enable = true;
}; };
firewall.enable = false; firewall.enable = false;
usePredictableInterfaceNames = false; usePredictableInterfaceNames = true;
hostName = config.device; hostName = config.device;
}; };
} }

View File

@ -54,6 +54,7 @@
experimental-features = nix-command flakes experimental-features = nix-command flakes
''; '';
# TODO: change?
# package = pkgs.nixFlakes; # package = pkgs.nixFlakes;
package = inputs.nix.packages.x86_64-linux.nix; package = inputs.nix.packages.x86_64-linux.nix;

View File

@ -38,8 +38,8 @@ with deviceSpecific; {
powerManagement.cpuFreqGovernor = powerManagement.cpuFreqGovernor =
lib.mkIf config.services.tlp.enable (lib.mkForce null); lib.mkIf config.services.tlp.enable (lib.mkForce null);
services.undervolt = { services.undervolt = lib.mkIf (device == "Dell-Laptop") {
enable = (device == "Dell-Laptop"); enable = true;
coreOffset = "-120"; coreOffset = "-120";
gpuOffset = "-54"; gpuOffset = "-54";
}; };

View File

@ -22,9 +22,6 @@ with deviceSpecific; {
nsswins = false; nsswins = false;
securityType = "user"; securityType = "user";
syncPasswordsByPam = false; syncPasswordsByPam = false;
# shares = {
# };
# extraConfig = ''
configText = '' configText = ''
[global] [global]
server string = samba home server server string = samba home server

5
modules/services.nix Executable file → Normal file
View File

@ -5,11 +5,6 @@ in {
services.acpid.enable = true; services.acpid.enable = true;
# services.btrfs.autoScrub = {
# enable = true;
# interval = "weekly";
# };
services.redshift = { services.redshift = {
enable = true; enable = true;
temperature.day = 5500; temperature.day = 5500;

View File

@ -28,14 +28,10 @@
}; };
security.sudo = { security.sudo = {
enable = true; enable = true;
extraConfig = ''
ALL ALL = (ALL) NOPASSWD: /run/current-system/sw/bin/btrfs fi usage *
'';
# extraConfig = '' # extraConfig = ''
# alukard ALL = (root) NOPASSWD: /run/current-system/sw/bin/nixos-rebuild switch # alukard ALL = (root) NOPASSWD: /run/current-system/sw/bin/nixos-rebuild switch
# ''; # '';
}; };
# nix.requireSignedBinaryCaches = false; # nix.requireSignedBinaryCaches = false;
home-manager.useUserPackages = true; home-manager.useUserPackages = true;
} }

View File

@ -1,13 +1,10 @@
{ pkgs ? import <nixpkgs> { } }: { pkgs ? import <nixpkgs> { } }:
let let
configs = "${toString ./.}#nixosConfigurations";
build = "config.system.build";
rebuild = pkgs.writeShellScriptBin "rebuild" '' rebuild = pkgs.writeShellScriptBin "rebuild" ''
if [[ -z $1 ]]; then if [[ -z $1 ]]; then
echo "Usage: $(basename $0) host {switch|boot|test}" echo "Usage: $(basename $0) {switch|boot|test}"
else else
sudo -E nix shell -vv ${configs}.$1.${build}.toplevel -c switch-to-configuration $2 sudo nixos-rebuild $1 --flake .
fi fi
''; '';
in in
@ -16,16 +13,6 @@ pkgs.mkShell {
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
git git
git-crypt git-crypt
nixFlakes
rebuild rebuild
gnupg
]; ];
shellHook = ''
PATH=${
pkgs.writeShellScriptBin "nix" ''
${pkgs.nixFlakes}/bin/nix --option experimental-features "nix-command flakes ca-references" "$@"
''
}/bin:$PATH
'';
} }