diff --git a/.github/workflows/nix-build-using-debian.yaml b/.github/workflows/nix-build-using-debian.yaml index c81bfb2..d96fc2a 100644 --- a/.github/workflows/nix-build-using-debian.yaml +++ b/.github/workflows/nix-build-using-debian.yaml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v4.1.1 - uses: cachix/install-nix-action@v26 with: - nix_path: nixpkgs=channel:nixos-20.09 + nix_path: nixos=channel:nixos-23.05 extra_nix_config: | extra-platforms = aarch64-linux - name: Check nix.conf @@ -78,7 +78,7 @@ jobs: EOF - name: Build SD Image run: | - nix-build '' \ + nix-build '' \ -A config.system.build.sdImage \ -I nixos-config=./configuration.custom.sdImage.nix \ --argstr system aarch64-linux \ diff --git a/.github/workflows/nix-build-using-docker.yaml b/.github/workflows/nix-build-using-docker.yaml index f7c91da..a969420 100644 --- a/.github/workflows/nix-build-using-docker.yaml +++ b/.github/workflows/nix-build-using-docker.yaml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v4.1.1 - uses: cachix/install-nix-action@v26 with: - nix_path: nixpkgs=channel:nixos-20.09 + nix_path: nixos=channel:nixos-23.05 extra_nix_config: | extra-platforms = aarch64-linux - name: Check nix.conf @@ -27,13 +27,17 @@ jobs: - name: Test binfmt availability run: | cat /proc/sys/fs/binfmt_misc/qemu-aarch64 + # non flake way to build +# - name: Build SD Image +# run: | +# nix-build '' \ +# -A config.system.build.sdImage \ +# -I nixos-config=./configuration.default.sdImage.nix \ +# --argstr system aarch64-linux \ +# --option sandbox false - name: Build SD Image run: | - nix-build '' \ - -A config.system.build.sdImage \ - -I nixos-config=./configuration.default.sdImage.nix \ - --argstr system aarch64-linux \ - --option sandbox false + nix build .#nixosConfigurations.raspberry-pi_3_default.config.system.build.sdImage - uses: actions/upload-artifact@v4 with: name: sd-image.img @@ -49,7 +53,7 @@ jobs: - uses: actions/checkout@v4.1.1 - uses: cachix/install-nix-action@v26 with: - nix_path: nixpkgs=channel:nixos-20.09 + nix_path: nixos=channel:nixos-23.05 extra_nix_config: | extra-platforms = aarch64-linux - name: Check nix.conf @@ -62,16 +66,20 @@ jobs: cat /proc/sys/fs/binfmt_misc/qemu-aarch64 - name: Extract configuration from secrets run: | - cat << EOF >> configuration.custom.sdImage.nix + cat << EOF >> configuration.nix ${{ secrets.CONFIGURATION_NIX }} EOF + # non nix flake way to build +# - name: Build SD Image +# run: | +# nix-build '' \ +# -A config.system.build.sdImage \ +# -I nixos-config=./configuration.custom.sdImage.nix \ +# --argstr system aarch64-linux \ +# --option sandbox false - name: Build SD Image run: | - nix-build '' \ - -A config.system.build.sdImage \ - -I nixos-config=./configuration.custom.sdImage.nix \ - --argstr system aarch64-linux \ - --option sandbox false + nix build .#nixosConfigurations.raspberry-pi_3_default.config.system.build.sdImage - uses: actions/upload-artifact@v4 with: name: sd-image.img diff --git a/.gitignore b/.gitignore index 8653b7d..b9c069e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,9 @@ etc-pihole .env docker-compose.override.yml result -sd-image.* \ No newline at end of file +output +.direnv +.DS_Store +sd-image.* + +.idea \ No newline at end of file diff --git a/README.md b/README.md index cc29aac..b1889bf 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Model: # Using prebuilt image available on Hydra -The latest image is on Hydra: +The latest image is on Hydra (example. You might need to change NixOS version in the following URL): [sd-image](https://hydra.nixos.org/job/nixos/release-20.09/nixos.sd_image.aarch64-linux/latest/download-by-type/file/sd-image) @@ -47,7 +47,9 @@ I already setup a workflow manual dispatch Github Action in this repo, so to bui 1. Fork the repo so you can build your own custom image 2. Create your build/deployment environment. -From your repo settings page, click the Environments menu. Click New environment. Give it a name other than `default`. Define environment secrets called `CONFIGURATION_NIX`. The content should be your sd Image Nix recipe (not your future NixOS configuration.nix). See the sample template file in: [configuration.default.sdImage.nix](configuration.default.sdImage.nix) or [configuration.sdImage.nix](configuration.sdImage.nix) +From your repo settings page, click the Environments menu. Click New environment. Give it a name other than `default`. Define environment secrets called `CONFIGURATION_NIX`. +The content should be your custom `configuration.nix` file. +This will be imported by the `configuration.sdImage.nix`. 3. Run your workflow @@ -99,7 +101,7 @@ The nix file must import the SD Image packages { imports = [ - + ]; # Do not compress the image as we want to use it straight away @@ -114,7 +116,7 @@ See example in: [configuration.sdImage.nix](configuration.sdImage.nix) Then build the image: ``` -nix-build '' -A config.system.build.sdImage -I nixos-config=./configuration.sdImage.nix \ +nix-build '' -A config.system.build.sdImage -I nixos-config=./configuration.sdImage.nix \ --argstr system aarch64-linux \ --option sandbox false ``` @@ -147,10 +149,29 @@ The build command: ``` # notice that we don't need to specify --argstr system aarch64-linux -nix-build '' -A config.system.build.sdImage -I nixos-config=./configuration.sdImage.nix \ +nix-build '' -A config.system.build.sdImage -I nixos-config=./configuration.sdImage.nix \ --option sandbox false ``` +# Building using Nix Flake + +You must be on a NixOS machine or Nix on Linux. The architecture won't matter. + +Following the previous guide on Building in x86_64 or ARM machine with Linux, the command is replaced +with Nix Flake command. + +```shell +nix build .#nixosConfigurations.raspberry-pi_3.config.system.build.sdImage +``` + +Note, that since you can execute nix build on a remote flake, if your `configuration.nix` is already +stored in your repo, then you can build locally against remote flake (no need to git clone). + +```shell +# example using this repo as the remote flake address +nix build github:lucernae/nixos-pi#nixosConfigurations.raspberry-pi_3.config.system.build.sdImage +``` + # Building using Docker Theoritically we can also build cross-platform using Docker container. diff --git a/configuration.default.nix b/configuration.default.nix new file mode 100644 index 0000000..f512722 --- /dev/null +++ b/configuration.default.nix @@ -0,0 +1,111 @@ +{ config, pkgs, lib, ... }: +{ + # NixOS wants to enable GRUB by default + boot.loader.grub.enable = false; + # Enables the generation of /boot/extlinux/extlinux.conf + boot.loader.generic-extlinux-compatible.enable = true; + + # !!! Set to specific linux kernel version + boot.kernelPackages = pkgs.linuxPackages; + + # Disable ZFS on kernel 6 + boot.supportedFilesystems = lib.mkForce [ + "vfat" + "xfs" + "cifs" + "ntfs" + ]; + + # !!! Needed for the virtual console to work on the RPi 3, as the default of 16M doesn't seem to be enough. + # If X.org behaves weirdly (I only saw the cursor) then try increasing this to 256M. + # On a Raspberry Pi 4 with 4 GB, you should either disable this parameter or increase to at least 64M if you want the USB ports to work. + boot.kernelParams = [ "cma=256M" ]; + + # File systems configuration for using the installer's partition layout + fileSystems = { + # Prior to 19.09, the boot partition was hosted on the smaller first partition + # Starting with 19.09, the /boot folder is on the main bigger partition. + # The following is to be used only with older images. + /* + "/boot" = { + device = "/dev/disk/by-label/NIXOS_BOOT"; + fsType = "vfat"; + }; + */ + "/" = { + device = "/dev/disk/by-label/NIXOS_SD"; + fsType = "ext4"; + }; + }; + + # !!! Adding a swap file is optional, but strongly recommended! + swapDevices = [{ device = "/swapfile"; size = 1024; }]; + + # Settings above are the bare minimum + # All settings below are customized depending on your needs + + # systemPackages + environment.systemPackages = with pkgs; [ + vim + curl + wget + nano + bind + kubectl + kubernetes-helm + iptables + openvpn + python3 + nodejs + docker-compose + ]; + + services.openssh = { + enable = true; + settings.PermitRootLogin = "yes"; + }; + + programs.zsh = { + enable = true; + ohMyZsh = { + enable = true; + theme = "bira"; + }; + }; + + + virtualisation.docker.enable = true; + + networking.firewall.enable = false; + + # WiFi + hardware = { + enableRedistributableFirmware = true; + firmware = [ pkgs.wireless-regdb ]; + }; + + # put your own configuration here, for example ssh keys: + users.defaultUserShell = pkgs.zsh; + users.mutableUsers = true; + users.groups = { + nixos = { + gid = 1000; + name = "nixos"; + }; + }; + users.users = { + nixos = { + uid = 1000; + home = "/home/nixos"; + name = "nixos"; + group = "nixos"; + shell = pkgs.zsh; + extraGroups = [ "wheel" "docker" ]; + }; + }; + users.users.root.openssh.authorizedKeys.keys = [ + # Your ssh key + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqlXJv/noNPmZMIfjJguRX3O+Z39xeoKhjoIBEyfeqgKGh9JOv7IDBWlNnd3rHVnVPzB9emiiEoAJpkJUnWNBidL6vPYn13r6Zrt/2WLT6TiUFU026ANdqMjIMEZrmlTsfzFT+OzpBqtByYOGGe19qD3x/29nbszPODVF2giwbZNIMo2x7Ww96U4agb2aSAwo/oQa4jQsnOpYRMyJQqCUhvX8LzvE9vFquLlrSyd8khUsEVV/CytmdKwUUSqmlo/Mn7ge/S12rqMwmLvWFMd08Rg9NHvRCeOjgKB4EI6bVwF8D6tNFnbsGVzTHl7Cosnn75U11CXfQ6+8MPq3cekYr lucernae@lombardia-N43SM" + ]; + system.stateVersion = "23.05"; +} diff --git a/configuration.default.sdImage.nix b/configuration.default.sdImage.nix index fe80ae7..19ea5ba 100644 --- a/configuration.default.sdImage.nix +++ b/configuration.default.sdImage.nix @@ -2,81 +2,16 @@ { imports = [ - + # For nixpkgs cache - + + + # main configuration + ./configuration.default.nix ]; sdImage.compressImage = true; - - - # NixOS wants to enable GRUB by default - boot.loader.grub.enable = false; - # Enables the generation of /boot/extlinux/extlinux.conf - boot.loader.generic-extlinux-compatible.enable = true; - - # !!! Set to specific linux kernel version - boot.kernelPackages = pkgs.linuxPackages_5_4; - - # !!! Needed for the virtual console to work on the RPi 3, as the default of 16M doesn't seem to be enough. - # If X.org behaves weirdly (I only saw the cursor) then try increasing this to 256M. - # On a Raspberry Pi 4 with 4 GB, you should either disable this parameter or increase to at least 64M if you want the USB ports to work. - boot.kernelParams = ["cma=256M"]; - - # Settings above are the bare minimum - # All settings below are customized depending on your needs - - # systemPackages - environment.systemPackages = with pkgs; [ - vim curl wget nano bind kubectl helm iptables openvpn - python3 nodejs-12_x docker-compose ]; - - services.openssh = { - enable = true; - permitRootLogin = "yes"; - }; - programs.zsh = { - enable = true; - ohMyZsh = { - enable = true; - theme = "bira"; - }; - }; - - - virtualisation.docker.enable = true; - - networking.firewall.enable = false; - - # WiFi - hardware = { - enableRedistributableFirmware = true; - firmware = [ pkgs.wireless-regdb ]; - }; - - # put your own configuration here, for example ssh keys: - users.defaultUserShell = pkgs.zsh; - users.mutableUsers = true; - users.groups = { - nixos = { - gid = 1000; - name = "nixos"; - }; - }; - users.users = { - nixos = { - uid = 1000; - home = "/home/nixos"; - name = "nixos"; - group = "nixos"; - shell = pkgs.zsh; - extraGroups = [ "wheel" "docker" ]; - }; - }; - users.extraUsers.root.openssh.authorizedKeys.keys = [ - # Your ssh key - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqlXJv/noNPmZMIfjJguRX3O+Z39xeoKhjoIBEyfeqgKGh9JOv7IDBWlNnd3rHVnVPzB9emiiEoAJpkJUnWNBidL6vPYn13r6Zrt/2WLT6TiUFU026ANdqMjIMEZrmlTsfzFT+OzpBqtByYOGGe19qD3x/29nbszPODVF2giwbZNIMo2x7Ww96U4agb2aSAwo/oQa4jQsnOpYRMyJQqCUhvX8LzvE9vFquLlrSyd8khUsEVV/CytmdKwUUSqmlo/Mn7ge/S12rqMwmLvWFMd08Rg9NHvRCeOjgKB4EI6bVwF8D6tNFnbsGVzTHl7Cosnn75U11CXfQ6+8MPq3cekYr lucernae@lombardia-N43SM" - ]; + system.copySystemConfiguration = true; } diff --git a/configuration.nix b/configuration.nix index 2cf0cbf..34124da 100755 --- a/configuration.nix +++ b/configuration.nix @@ -4,25 +4,33 @@ boot.loader.grub.enable = false; # Enables the generation of /boot/extlinux/extlinux.conf boot.loader.generic-extlinux-compatible.enable = true; - + # !!! Set to specific linux kernel version - boot.kernelPackages = pkgs.linuxPackages_5_4; + boot.kernelPackages = pkgs.linuxPackages; + + # Disable ZFS on kernel 6 + boot.supportedFilesystems = lib.mkForce [ + "vfat" + "xfs" + "cifs" + "ntfs" + ]; # !!! Needed for the virtual console to work on the RPi 3, as the default of 16M doesn't seem to be enough. # If X.org behaves weirdly (I only saw the cursor) then try increasing this to 256M. # On a Raspberry Pi 4 with 4 GB, you should either disable this parameter or increase to at least 64M if you want the USB ports to work. - boot.kernelParams = ["cma=256M"]; - + boot.kernelParams = [ "cma=256M" ]; + # File systems configuration for using the installer's partition layout fileSystems = { # Prior to 19.09, the boot partition was hosted on the smaller first partition # Starting with 19.09, the /boot folder is on the main bigger partition. # The following is to be used only with older images. /* - "/boot" = { + "/boot" = { device = "/dev/disk/by-label/NIXOS_BOOT"; fsType = "vfat"; - }; + }; */ "/" = { device = "/dev/disk/by-label/NIXOS_SD"; @@ -31,29 +39,40 @@ }; # !!! Adding a swap file is optional, but strongly recommended! - swapDevices = [ { device = "/swapfile"; size = 1024; } ]; + swapDevices = [{ device = "/swapfile"; size = 1024; }]; # systemPackages - environment.systemPackages = with pkgs; [ - vim curl wget nano bind kubectl helm iptables openvpn - python3 nodejs-12_x docker-compose ]; + environment.systemPackages = with pkgs; [ + vim + curl + wget + nano + bind + kubectl + kubernetes-helm + iptables + openvpn + python3 + nodejs + docker-compose + ]; services.openssh = { - enable = true; - permitRootLogin = "yes"; + enable = true; + settings.PermitRootLogin = "yes"; }; # Some sample service. # Use dnsmasq as internal LAN DNS resolver. services.dnsmasq = { - enable = false; - servers = [ "8.8.8.8" "8.8.4.4" "1.1.1.1" ]; - extraConfig = '' - address=/fenrir.test/192.168.100.6 - address=/recalune.test/192.168.100.7 - address=/eth.nixpi.test/192.168.100.3 - address=/wlan.nixpi.test/192.168.100.4 - ''; + enable = false; + settings.servers = [ "8.8.8.8" "8.8.4.4" "1.1.1.1" ]; + settings.extraConfig = '' + address=/fenrir.test/192.168.100.6 + address=/recalune.test/192.168.100.7 + address=/eth.nixpi.test/192.168.100.3 + address=/wlan.nixpi.test/192.168.100.4 + ''; }; # services.openvpn = { @@ -66,18 +85,18 @@ # }; programs.zsh = { + enable = true; + ohMyZsh = { enable = true; - ohMyZsh = { - enable = true; - theme = "bira"; - }; + theme = "bira"; + }; }; virtualisation.docker.enable = true; networking.firewall.enable = false; - + # WiFi hardware = { @@ -91,7 +110,7 @@ useDHCP = false; ipv4.addresses = [{ # I used static IP over WLAN because I want to use it as local DNS resolver - address = "192.168.100.4"; + address = "192.168.1.4"; prefixLength = 24; }]; }; @@ -108,14 +127,21 @@ wireless.enable = true; wireless.interfaces = [ "wlan0" ]; # If you want to connect also via WIFI to your router - wireless.networks."WIFI-SSID".psk = "wifipass"; + # wireless.networks."SATRIA".psk = "wifipassword"; # You can set default nameservers - nameservers = [ "192.168.100.3" "192.168.100.4" "192.168.100.1" ]; + # nameservers = [ "192.168.100.3" "192.168.100.4" "192.168.100.1" ]; # You can set default gateway - defaultGateway = { - address = "192.168.100.1"; - interface = "wlan0"; - }; + # defaultGateway = { + # address = "192.168.1.1"; + # interface = "eth0"; + # }; + }; + + # forwarding + boot.kernel.sysctl = { + "net.ipv4.conf.all.forwarding" = true; + "net.ipv6.conf.all.forwarding" = true; + "net.ipv4.tcp_ecn" = true; }; # put your own configuration here, for example ssh keys: @@ -137,8 +163,9 @@ extraGroups = [ "wheel" "docker" ]; }; }; - users.extraUsers.root.openssh.authorizedKeys.keys = [ + users.users.root.openssh.authorizedKeys.keys = [ # This is my public key - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqlXJv/noNPmZMIfjJguRX3O+Z39xeoKhjoIBEyfeqgKGh9JOv7IDBWlNnd3rHVnVPzB9emiiEoAJpkJUnWNBidL6vPYn13r6Zrt/2WLT6TiUFU026ANdqMjIMEZrmlTsfzFT+OzpBqtByYOGGe19qD3x/29nbszPODVF2giwbZNIMo2x7Ww96U4agb2aSAwo/oQa4jQsnOpYRMyJQqCUhvX8LzvE9vFquLlrSyd8khUsEVV/CytmdKwUUSqmlo/Mn7ge/S12rqMwmLvWFMd08Rg9NHvRCeOjgKB4EI6bVwF8D6tNFnbsGVzTHl7Cosnn75U11CXfQ6+8MPq3cekYr lucernae@lombardia-N43SM" + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqlXJv/noNPmZMIfjJguRX3O+Z39xeoKhjoIBEyfeqgKGh9JOv7IDBWlNnd3rHVnVPzB9emiiEoAJpkJUnWNBidL6vPYn13r6Zrt/2WLT6TiUFU026ANdqMjIMEZrmlTsfzFT+OzpBqtByYOGGe19qD3x/29nbszPODVF2giwbZNIMo2x7Ww96U4agb2aSAwo/oQa4jQsnOpYRMyJQqCUhvX8LzvE9vFquLlrSyd8khUsEVV/CytmdKwUUSqmlo/Mn7ge/S12rqMwmLvWFMd08Rg9NHvRCeOjgKB4EI6bVwF8D6tNFnbsGVzTHl7Cosnn75U11CXfQ6+8MPq3cekYr lucernae@lombardia-N43SM" ]; + system.stateVersion = "23.05"; } diff --git a/configuration.sdImage.nix b/configuration.sdImage.nix index 7fe8f99..f73d571 100755 --- a/configuration.sdImage.nix +++ b/configuration.sdImage.nix @@ -2,114 +2,16 @@ { imports = [ - + # For nixpkgs cache - + + + # main configuration + ./configuration.nix ]; sdImage.compressImage = false; - - - # NixOS wants to enable GRUB by default - boot.loader.grub.enable = false; - # Enables the generation of /boot/extlinux/extlinux.conf - boot.loader.generic-extlinux-compatible.enable = true; - - # !!! Set to specific linux kernel version - boot.kernelPackages = pkgs.linuxPackages_5_4; - - # !!! Needed for the virtual console to work on the RPi 3, as the default of 16M doesn't seem to be enough. - # If X.org behaves weirdly (I only saw the cursor) then try increasing this to 256M. - # On a Raspberry Pi 4 with 4 GB, you should either disable this parameter or increase to at least 64M if you want the USB ports to work. - boot.kernelParams = ["cma=256M"]; - - # Settings above are the bare minimum - # All settings below are customized depending on your needs - - # systemPackages - environment.systemPackages = with pkgs; [ - vim curl wget nano bind kubectl helm iptables openvpn - python3 nodejs-12_x docker-compose ]; - - services.openssh = { - enable = true; - permitRootLogin = "yes"; - }; - - programs.zsh = { - enable = true; - ohMyZsh = { - enable = true; - theme = "bira"; - }; - }; - - virtualisation.docker.enable = true; - - networking.firewall.enable = false; - - # WiFi - hardware = { - enableRedistributableFirmware = true; - firmware = [ pkgs.wireless-regdb ]; - }; - - # Networking - networking = { - # useDHCP = true; - interfaces.wlan0 = { - useDHCP = false; - ipv4.addresses = [{ - # I used static IP over WLAN because I want to use it as local DNS resolver - address = "192.168.100.4"; - prefixLength = 24; - }]; - }; - interfaces.eth0 = { - useDHCP = true; - # I used DHCP because sometimes I disconnect the LAN cable - #ipv4.addresses = [{ - # address = "192.168.100.3"; - # prefixLength = 24; - #}]; - }; - - # Enabling WIFI - wireless.enable = true; - wireless.interfaces = [ "wlan0" ]; - # If you want to connect also via WIFI to your router - wireless.networks."WIFI-SSID".psk = "wifipass"; - # You can set default nameservers - nameservers = [ "192.168.100.3" "192.168.100.4" "192.168.100.1" ]; - # You can set default gateway - defaultGateway = { - address = "192.168.100.1"; - interface = "wlan0"; - }; - }; - - # put your own configuration here, for example ssh keys: - users.defaultUserShell = pkgs.zsh; - users.mutableUsers = true; - users.groups = { - nixos = { - gid = 1000; - name = "nixos"; - }; - }; - users.users = { - nixos = { - uid = 1000; - home = "/home/nixos"; - name = "nixos"; - group = "nixos"; - shell = pkgs.zsh; - extraGroups = [ "wheel" "docker" ]; - }; - }; - users.extraUsers.root.openssh.authorizedKeys.keys = [ - "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDqlXJv/noNPmZMIfjJguRX3O+Z39xeoKhjoIBEyfeqgKGh9JOv7IDBWlNnd3rHVnVPzB9emiiEoAJpkJUnWNBidL6vPYn13r6Zrt/2WLT6TiUFU026ANdqMjIMEZrmlTsfzFT+OzpBqtByYOGGe19qD3x/29nbszPODVF2giwbZNIMo2x7Ww96U4agb2aSAwo/oQa4jQsnOpYRMyJQqCUhvX8LzvE9vFquLlrSyd8khUsEVV/CytmdKwUUSqmlo/Mn7ge/S12rqMwmLvWFMd08Rg9NHvRCeOjgKB4EI6bVwF8D6tNFnbsGVzTHl7Cosnn75U11CXfQ6+8MPq3cekYr lucernae@lombardia-N43SM" - ]; + system.copySystemConfiguration = true; } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..37ee4fc --- /dev/null +++ b/flake.lock @@ -0,0 +1,147 @@ +{ + "nodes": { + "devshell": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1711099426, + "narHash": "sha256-HzpgM/wc3aqpnHJJ2oDqPBkNsqWbW0WfWUO8lKu8nGk=", + "owner": "numtide", + "repo": "devshell", + "rev": "2d45b54ca4a183f2fdcf4b19c895b64fbf620ee8", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1704161960, + "narHash": "sha256-QGua89Pmq+FBAro8NriTuoO/wNaUtugt29/qqA8zeeM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63143ac2c9186be6d9da6035fa22620018c85932", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1711715736, + "narHash": "sha256-9slQ609YqT9bT/MNX9+5k5jltL9zgpn36DpFB7TkttM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "807c549feabce7eddbf259dbdcec9e0600a0660d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devshell": "devshell", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e59b7d0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,69 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + devshell.url = "github:numtide/devshell"; + }; + + outputs = { self, nixpkgs, flake-utils, devshell, ... }: + flake-utils.lib.eachDefaultSystem (system: { + apps.devshell = self.outputs.devShell.${system}.flakeApp; + formatter = nixpkgs.legacyPackages.${system}.nixpkgs-fmt; + packages = { + nixosConfigurations = + let + inherit (nixpkgs.lib) nixosSystem; + in + rec { + # to build: nix build github:lucernae/nix-config#nixosConfigurations.raspberry-pi_3.config.system.build.sdImage + raspberry-pi_3 = nixosSystem { + system = "aarch64-linux"; + modules = [ + "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64-installer.nix" + # replace this with your target configuration + ./configuration.nix + + # extra config for sdImage generator + { + sdImage.compressImage = false; + } + ]; + }; + raspberry-pi_3_default = nixosSystem { + system = "aarch64-linux"; + modules = [ + "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64-installer.nix" + # replace this with your target configuration + ./configuration.default.nix + + # extra config for sdImage generator + { + sdImage.compressImage = false; + } + ]; + }; + }; + }; + devShell = + let + pkgs = import nixpkgs { + inherit system; + overlays = [ devshell.overlays.default ]; + }; + in + pkgs.devshell.mkShell { + name = "nixos-pi"; + commands = [ + ]; + packages = with pkgs; [ + git + qemu + qemu_kvm + ]; + }; + }); +} diff --git a/shell.nix b/shell.nix index 4242476..6234bb4 100644 --- a/shell.nix +++ b/shell.nix @@ -1,18 +1,10 @@ -let _pkgs = import { }; -in { pkgs ? import (_pkgs.fetchFromGitHub { - owner = "NixOS"; - repo = "nixpkgs-channels"; - #branch@date: nixpkgs-unstable@2021-01-25 - rev = "502845c3e31ef3de0e424f3fcb09217df2ce6df6"; - sha256 = "0fcqpsy6y7dgn0y0wgpa56gsg0b0p8avlpjrd79fp4mp9bl18nda"; -}) { } }: - -with pkgs; - -mkShell { - buildInputs = [ - git - qemu - qemu_kvm - ]; -} \ No newline at end of file +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).shellNix