Skip to content

Instantly share code, notes, and snippets.

@tobiasBora
Last active January 9, 2024 18:31
Show Gist options
  • Save tobiasBora/1f19628dc6b12bcd4438164b24226c6c to your computer and use it in GitHub Desktop.
Save tobiasBora/1f19628dc6b12bcd4438164b24226c6c to your computer and use it in GitHub Desktop.
Demo basic flake
A basic flake sharing the same nixpkgs everywhere (nix shell, nix profile etc).
You can try to build me and run me in a VM with:
```
$ nixos-rebuild build-vm --flake git+https://gist.github.com/1f19628dc6b12bcd4438164b24226c6c.git#daw --refresh
$ ./result/bin/run-nixos-vm
```
The user is `daw` and the password is `foo`.
(Of course, do not install me system-wide directly, as you need to update the hardware configuration accordingly!)
# inputs is made possible thanks to the specialArgs line in flake.nix forwarding inputs:
{ pkgs, config, lib, inputs, ... }:
{
imports = [
./hardware-configuration.nix
];
## Enable flakes
nix = {
# This will add each flake input as a registry
# To make nix3 commands consistent with your flake
# Inspired by https://github.com/Misterio77/nix-starter-configs/blob/972935c1b35d8b92476e26b0e63a044d191d49c3/standard/nixos/configuration.nix
registry = lib.mapAttrs (_: value: { flake = value; }) inputs;
# This will additionally add your inputs to the system's legacy channels
# Making legacy nix commands consistent as well, awesome!
nixPath = lib.mapAttrsToList (key: value: "${key}=${value.to.path}") config.nix.registry;
settings = {
# Enable flakes and new 'nix' command
experimental-features = "nix-command flakes";
};
};
################################### Add here your configuration like:
system.stateVersion = "24.04";
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
users.users.daw = {
isNormalUser = true;
initialPassword = "foo";
};
# Not really needed, but recommended if you want to run non-nixos binaries.
# You can customize programs.nix-ld.libraries = []; to add more libraries not present in systemPackages.
programs.nix-ld.enable = true;
# List of packages:
environment.systemPackages = with pkgs; [
hello
];
}
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1704538339,
"narHash": "sha256-1734d3mQuux9ySvwf6axRWZRBhtcZA9Q8eftD6EZg6U=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "46ae0210ce163b3cba6c7da08840c1d63de9c701",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}
{
description = "The configuration of my system";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }@inputs: {
nixosConfigurations.daw = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = { inherit inputs; };
modules = [
./configuration.nix
];
};
};
}
{ config, lib, pkgs, modulesPath, ... }:
{
imports =
[ (modulesPath + "/installer/scan/not-detected.nix")
];
fileSystems."/" =
{ device = "/dev/disk/by-uuid/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
fsType = "ext4";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/0000-0000";
fsType = "vfat";
};
swapDevices = [ ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment