├── LICENSE ├── README.md ├── default └── flake.nix ├── final ├── configuration.nix ├── disko.nix ├── flake.nix ├── hardware-configuration.nix └── home.nix └── flake.nix /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## You can find all files in /final 2 | 3 | ## downloading disko.nix 4 | ```bash 5 | curl https://raw.githubusercontent.com/vimjoyer/impermanent-setup/main/final/disko.nix -O /tmp/disko.nix 6 | ``` 7 | 8 | ## disko formatting command 9 | replace `'"/dev/vda"'` with your drive 10 | ```bash 11 | sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/disko.nix --arg device '"/dev/vda"' 12 | ``` 13 | 14 | ## initialize flake 15 | ```bash 16 | nix flake init --template github:vimjoyer/impermanent-setup 17 | ``` 18 | 19 | ## installing nixos 20 | ```bash 21 | nixos-install --root /mnt --flake /mnt/etc/nixos#default 22 | ``` 23 | -------------------------------------------------------------------------------- /default/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Nixos config flake"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; 6 | 7 | disko = { 8 | url = "github:nix-community/disko"; 9 | inputs.nixpkgs.follows = "nixpkgs"; 10 | }; 11 | 12 | # impermanence = { 13 | # url = "github:nix-community/impermanence"; 14 | # }; 15 | 16 | # home-manager = { 17 | # url = "github:nix-community/home-manager"; 18 | # inputs.nixpkgs.follows = "nixpkgs"; 19 | # }; 20 | }; 21 | 22 | outputs = {nixpkgs, ...} @ inputs: 23 | { 24 | nixosConfigurations.default = nixpkgs.lib.nixosSystem { 25 | specialArgs = {inherit inputs;}; 26 | modules = [ 27 | inputs.disko.nixosModules.default 28 | (import ./disko.nix { device = "/dev/vda"; }) 29 | 30 | ./configuration.nix 31 | 32 | # inputs.home-manager.nixosModules.default 33 | # inputs.impermanence.nixosModules.impermanence 34 | ]; 35 | }; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /final/configuration.nix: -------------------------------------------------------------------------------- 1 | { pkgs, lib, inputs, ... }: 2 | 3 | { 4 | imports = 5 | [ 6 | ./hardware-configuration.nix 7 | ]; 8 | 9 | boot.loader.systemd-boot.enable = true; 10 | boot.loader.efi.canTouchEfiVariables = true; 11 | 12 | services.openssh.enable = true; 13 | 14 | system.stateVersion = "23.05"; # Did you read the comment? 15 | 16 | users.users."vimjoyer" = { 17 | isNormalUser = true; 18 | initialPassword = "1"; 19 | extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user. 20 | }; 21 | 22 | boot.initrd.postDeviceCommands = lib.mkAfter '' 23 | mkdir /btrfs_tmp 24 | mount /dev/root_vg/root /btrfs_tmp 25 | if [[ -e /btrfs_tmp/root ]]; then 26 | mkdir -p /btrfs_tmp/old_roots 27 | timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S") 28 | mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp" 29 | fi 30 | 31 | delete_subvolume_recursively() { 32 | IFS=$'\n' 33 | for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do 34 | delete_subvolume_recursively "/btrfs_tmp/$i" 35 | done 36 | btrfs subvolume delete "$1" 37 | } 38 | 39 | for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do 40 | delete_subvolume_recursively "$i" 41 | done 42 | 43 | btrfs subvolume create /btrfs_tmp/root 44 | umount /btrfs_tmp 45 | ''; 46 | 47 | fileSystems."/persist".neededForBoot = true; 48 | environment.persistence."/persist/system" = { 49 | hideMounts = true; 50 | directories = [ 51 | "/etc/nixos" 52 | "/var/log" 53 | "/var/lib/bluetooth" 54 | "/var/lib/nixos" 55 | "/var/lib/systemd/coredump" 56 | "/etc/NetworkManager/system-connections" 57 | { directory = "/var/lib/colord"; user = "colord"; group = "colord"; mode = "u=rwx,g=rx,o="; } 58 | ]; 59 | files = [ 60 | "/etc/machine-id" 61 | { file = "/var/keys/secret_file"; parentDirectory = { mode = "u=rwx,g=,o="; }; } 62 | ]; 63 | }; 64 | 65 | programs.fuse.userAllowOther = true; 66 | home-manager = { 67 | extraSpecialArgs = {inherit inputs;}; 68 | users = { 69 | "vimjoyer" = import ./home.nix; 70 | }; 71 | }; 72 | 73 | } 74 | -------------------------------------------------------------------------------- /final/disko.nix: -------------------------------------------------------------------------------- 1 | { 2 | device ? throw "Set this to your disk device, e.g. /dev/sda", 3 | ... 4 | }: { 5 | disko.devices = { 6 | disk.main = { 7 | inherit device; 8 | type = "disk"; 9 | content = { 10 | type = "gpt"; 11 | partitions = { 12 | boot = { 13 | name = "boot"; 14 | size = "1M"; 15 | type = "EF02"; 16 | }; 17 | esp = { 18 | name = "ESP"; 19 | size = "500M"; 20 | type = "EF00"; 21 | content = { 22 | type = "filesystem"; 23 | format = "vfat"; 24 | mountpoint = "/boot"; 25 | }; 26 | }; 27 | swap = { 28 | size = "4G"; 29 | content = { 30 | type = "swap"; 31 | resumeDevice = true; 32 | }; 33 | }; 34 | root = { 35 | name = "root"; 36 | size = "100%"; 37 | content = { 38 | type = "lvm_pv"; 39 | vg = "root_vg"; 40 | }; 41 | }; 42 | }; 43 | }; 44 | }; 45 | lvm_vg = { 46 | root_vg = { 47 | type = "lvm_vg"; 48 | lvs = { 49 | root = { 50 | size = "100%FREE"; 51 | content = { 52 | type = "btrfs"; 53 | extraArgs = ["-f"]; 54 | 55 | subvolumes = { 56 | "/root" = { 57 | mountpoint = "/"; 58 | }; 59 | 60 | "/persist" = { 61 | mountOptions = ["subvol=persist" "noatime"]; 62 | mountpoint = "/persist"; 63 | }; 64 | 65 | "/nix" = { 66 | mountOptions = ["subvol=nix" "noatime"]; 67 | mountpoint = "/nix"; 68 | }; 69 | }; 70 | }; 71 | }; 72 | }; 73 | }; 74 | }; 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /final/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Nixos config flake"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; 6 | 7 | disko = { 8 | url = "github:nix-community/disko"; 9 | inputs.nixpkgs.follows = "nixpkgs"; 10 | }; 11 | 12 | # impermanence = { 13 | # url = "github:nix-community/impermanence"; 14 | # }; 15 | 16 | # home-manager = { 17 | # url = "github:nix-community/home-manager"; 18 | # inputs.nixpkgs.follows = "nixpkgs"; 19 | # }; 20 | }; 21 | 22 | outputs = {nixpkgs, ...} @ inputs: 23 | { 24 | nixosConfigurations.default = nixpkgs.lib.nixosSystem { 25 | specialArgs = {inherit inputs;}; 26 | modules = [ 27 | inputs.disko.nixosModules.default 28 | (import ./disko.nix { device = "/dev/vda"; }) 29 | 30 | ./configuration.nix 31 | 32 | # inputs.home-manager.nixosModules.default 33 | # inputs.impermanence.nixosModules.impermanence 34 | ]; 35 | }; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /final/hardware-configuration.nix: -------------------------------------------------------------------------------- 1 | # Do not modify this file! It was generated by ‘nixos-generate-config’ 2 | # and may be overwritten by future invocations. Please make changes 3 | # to /etc/nixos/configuration.nix instead. 4 | { config, lib, pkgs, modulesPath, ... }: 5 | 6 | { 7 | imports = 8 | [ (modulesPath + "/profiles/qemu-guest.nix") 9 | ]; 10 | 11 | boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "virtio_pci" "sr_mod" "virtio_blk" ]; 12 | boot.initrd.kernelModules = [ ]; 13 | boot.kernelModules = [ "kvm-amd" ]; 14 | boot.extraModulePackages = [ ]; 15 | 16 | # Enables DHCP on each ethernet and wireless interface. In case of scripted networking 17 | # (the default) this is the recommended approach. When using systemd-networkd it's 18 | # still possible to use this option, but it's recommended to use it in conjunction 19 | # with explicit per-interface declarations with `networking.interfaces..useDHCP`. 20 | networking.useDHCP = lib.mkDefault true; 21 | # networking.interfaces.enp1s0.useDHCP = lib.mkDefault true; 22 | 23 | nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; 24 | } 25 | -------------------------------------------------------------------------------- /final/home.nix: -------------------------------------------------------------------------------- 1 | { pkgs, inputs, ... }: 2 | 3 | { 4 | imports = [ 5 | inputs.impermanence.nixosModules.home-manager.impermanence 6 | ]; 7 | 8 | home.stateVersion = "23.11"; # Please read the comment before changing. 9 | 10 | home.persistence."/persist/home" = { 11 | directories = [ 12 | "Downloads" 13 | "Music" 14 | "Pictures" 15 | "Documents" 16 | "Videos" 17 | "VirtualBox VMs" 18 | ".gnupg" 19 | ".ssh" 20 | ".nixops" 21 | ".local/share/keyrings" 22 | ".local/share/direnv" 23 | { 24 | directory = ".local/share/Steam"; 25 | method = "symlink"; 26 | } 27 | ]; 28 | files = [ 29 | ".screenrc" 30 | ]; 31 | allowOther = true; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "A flake"; 3 | 4 | outputs = { self }: { 5 | 6 | templates = { 7 | 8 | flakeonly = { 9 | path = ./default; 10 | description = "Impermanent flake"; 11 | }; 12 | 13 | final = { 14 | path = ./final; 15 | description = "Impermanent setup"; 16 | }; 17 | 18 | }; 19 | 20 | defaultTemplate = self.templates.flakeonly; 21 | 22 | }; 23 | } 24 | --------------------------------------------------------------------------------